cf1dtool.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:35k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = cf1dtool(option,varargin)
  2. %CF1DTOOL Wavelet Coefficients Selection 1-D tool.
  3. %   VARARGOUT = CF1DTOOL(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 28-Jun-2001.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.12 $  $Date: 2002/06/17 12:19:28 $
  8. % Test inputs.
  9. %-------------
  10. if nargin==0 , option = 'create'; end
  11. [option,winAttrb] = utguidiv('ini',option,varargin{:});
  12. % Default values.
  13. %----------------
  14. max_lev_anal = 9;
  15. % Stem parameters.
  16. %-----------------
  17. absMode = 0;
  18. appView = 1;
  19. % Memory Blocs of stored values.
  20. %===============================
  21. % MB0.
  22. %-----
  23. n_membloc0 = 'MB0';
  24. ind_sig    = 1;
  25. ind_coefs  = 2;
  26. ind_longs  = 3;
  27. ind_first  = 4;
  28. ind_last   = 5;
  29. ind_sort   = 6;
  30. ind_By_Lev = 7;
  31. ind_sizes  = 8;  % Dummy
  32. nb0_stored = 8;
  33. % MB1.
  34. %-----
  35. n_param_anal = 'MB1';
  36. ind_sig_name =  1;
  37. ind_sig_size =  2;
  38. ind_wav_name =  3;
  39. ind_lev_anal =  4;
  40. nb1_stored   =  4;
  41. % MB2.
  42. %-----
  43. n_InfoInit   = 'MB2';
  44. ind_filename =  1;
  45. ind_pathname =  2;
  46. nb2_stored   =  2;
  47. % MB3.
  48. %-----
  49. n_synt_sig = 'MB3';
  50. ind_ssig   =  1;
  51. nb3_stored =  1;
  52. % MB4.
  53. %-----
  54. n_miscella     = 'MB4';
  55. ind_graph_area =  1;
  56. ind_axe_hdl    =  2;
  57. ind_lin_hdl    =  3;
  58. nb4_stored     =  3;
  59. if ~isequal(option,'create') , win_tool = varargin{1}; end
  60. switch option
  61.   case {'create','close'} ,
  62.   otherwise
  63.     toolATTR = wfigmngr('getValue',win_tool,'ToolATTR');
  64.     hdl_UIC  = toolATTR.hdl_UIC;
  65.     hdl_MEN  = toolATTR.hdl_MEN;
  66.     pus_ana  = hdl_UIC.pus_ana;
  67.     chk_sho  = hdl_UIC.chk_sho;
  68. end
  69. switch option
  70.   case 'create'
  71.     % Get Globals.
  72.     %--------------
  73.     [Def_Btn_Height,Def_Btn_Width,Pop_Min_Width,  ...
  74.      Def_Txt_Height,X_Spacing,Y_Spacing,Def_FraBkColor ] = ...
  75.         mextglob('get',...
  76.             'Def_Btn_Height','Def_Btn_Width','Pop_Min_Width',  ...
  77.             'Def_Txt_Height','X_Spacing','Y_Spacing','Def_FraBkColor' ...
  78.             );
  79.     % Window initialization.
  80.     %----------------------
  81.     win_title = 'Wavelet Coefficients Selection 1-D';
  82.     [win_tool,pos_win,win_units,str_numwin,...
  83.         frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  84.            wfigmngr('create',win_title,winAttrb,'ExtFig_Tool_3',mfilename,1,1,0);
  85.     if nargout> 0 , varargout{1} = win_tool; end
  86. % Add Help for Tool.
  87. %------------------
  88. wfighelp('addHelpTool',win_tool,'One-Dimensional &Selection','CF1D_GUI');
  89.     % Menu construction.
  90.     %-------------------
  91.     m_files = wfigmngr('getmenus',win_tool,'file');
  92.     m_load = uimenu(m_files,...
  93.                     'Label','&Load Signal', ...
  94.                     'Position',1,           ...
  95.                     'Callback',             ...
  96.                     [mfilename '(''load'',' str_numwin ');'] ...
  97.                     );
  98.     m_save = uimenu(m_files,...
  99.                     'Label','&Save Synthesized Signal', ...
  100.                     'Position',2,     ...
  101.                     'Enable','Off',   ...
  102.                     'Callback',       ...
  103.                     [mfilename '(''save'',' str_numwin ');'] ...
  104.                     );
  105.     m_demo = uimenu(m_files,...
  106.                     'Label','&Example Analysis ','Position',3);
  107.     m_demo_1 = uimenu(m_demo,'Label','Basic Signals');
  108.     m_demo_2 = uimenu(m_demo,'Label','Noisy Signals');
  109.     m_demo_3 = uimenu(m_demo,'Label','Noisy Signals - Movie');
  110.     % Submenu of test signals.
  111.     %-------------------------
  112.     names(1,:)  = 'Sum of sines               ';
  113.     names(2,:)  = 'Frequency breakdown        ';
  114.     names(3,:)  = 'Uniform white noise        ';
  115.     names(4,:)  = 'AR(3) noise                ';
  116.     names(5,:)  = 'Noisy polynomial           ';
  117.     names(6,:)  = 'Noisy polynomial           ';
  118.     names(7,:)  = 'Step signal                ';
  119.     names(8,:)  = 'Two nearby discontinuities ';
  120.     names(9,:)  = 'Two nearby discontinuities ';
  121.     names(10,:) = 'Second derivative breakdown';
  122.     names(11,:) = 'Second derivative breakdown';
  123.     names(12,:) = 'Ramp + white noise         ';
  124.     names(13,:) = 'Ramp + colored noise       ';
  125.     names(14,:) = 'Sine + white noise         ';
  126.     names(15,:) = 'Triangle + sine            ';
  127.     names(16,:) = 'Triangle + sine + noise    ';
  128.     names(17,:) = 'Electrical consumption     ';
  129.     names(18,:) = 'Cantor curve               ';
  130.     names(19,:) = 'Koch curve                 ';
  131.     files = [ 'sumsin  ' ; 'freqbrk ' ; 'whitnois' ; 'warma   ' ; ...
  132.               'noispol ' ; 'noispol ' ; 'wstep   ' ; 'nearbrk ' ; ...
  133.               'nearbrk ' ; 'scddvbrk' ; 'scddvbrk' ; 'wnoislop' ; ...
  134.               'cnoislop' ; 'noissin ' ; 'trsin   ' ; 'wntrsin ' ; ...
  135.               'leleccum' ; 'wcantor ' ; 'vonkoch '                    ];
  136.     waves = ['db3' ; 'db5' ; 'db3' ; 'db3' ; 'db2' ; 'db3' ; 'db2' ; ...
  137.              'db2' ; 'db7' ; 'db1' ; 'db4' ; 'db3' ; 'db3' ; 'db5' ; ...
  138.              'db5' ; 'db5' ; 'db3' ; 'db1' ; 'db1'                      ];
  139.     levels = ['5';'5';'5';'5';'4';'4';'5';'5';'5';'2';'2';'6';'6';'5';...
  140.                     '6';'7';'5';'5';'5'];
  141.     beg_call_str = [mfilename '(''demo'',' str_numwin ','''];
  142.     for i=1:size(files,1)
  143.             libel = ['with ' waves(i,:) ' at level ' levels(i,:) ...
  144.                             '  --->  ' names(i,:)];
  145.             action = [beg_call_str files(i,:) ''',''' ...
  146.                             waves(i,:) ''',' levels(i,:) ');'];
  147.             uimenu(m_demo_1,'Label',libel,'Callback',action);
  148.     end
  149.     names = strvcat(...
  150.               'Noisy blocks','Noisy bumps','Noisy heavysin',     ...
  151.               'Noisy Doppler','Noisy quadchirp','Noisy mishmash' ...
  152.               );
  153.     files      = [ 'noisbloc' ; 'noisbump' ; 'heavysin' ; ...
  154.                    'noisdopp' ; 'noischir' ; 'noismima'      ];
  155.     waves  = ['sym8';'sym4';'sym8';'sym4';'db1 ';'db3 '];
  156.     levels = ['5';'5';'5';'5';'5';'5'];
  157.     beg_call_str = [mfilename '(''demo'',' str_numwin ','''];
  158.     for i=1:size(files,1)
  159.         libel = ['with ' waves(i,:) ' at level ' levels(i,:) ...
  160.                         '  --->  ' names(i,:)];
  161.         action = [beg_call_str files(i,:) ''',''' ...
  162.                         waves(i,:) ''',' levels(i,:) ');'];
  163.         uimenu(m_demo_2,'Label',libel,'Callback',action);
  164.     end
  165.     for i=1:size(files,1)
  166.         libel = ['with ' waves(i,:) ' at level ' levels(i,:) ...
  167.                         '  --->  ' names(i,:)];
  168.         action = [beg_call_str files(i,:) ''',''' ...
  169.                                waves(i,:) ''',' levels(i,:) ',' ...
  170.                                '{''Stepwise''}' ');'];
  171.         uimenu(m_demo_3,'Label',libel,'Callback',action);
  172.     end
  173.     % Begin waiting.
  174.     %---------------
  175.     wwaiting('msg',win_tool,'Wait ... initialization');
  176.     % General parameters initialization.
  177.     %-----------------------------------
  178.     dx = X_Spacing;   dx2 = 2*dx;
  179.     dy = Y_Spacing;   dy2 = 2*dy;
  180.     d_txt = (Def_Btn_Height-Def_Txt_Height);
  181.  
  182.     % Command part of the window.
  183.     %============================
  184.     % Data, Wavelet and Level parameters.
  185.     %------------------------------------
  186.     xlocINI = pos_frame0([1 3]);
  187.     ytopINI = pos_win(4)-dy;
  188.     toolPos = utanapar('create',win_tool, ...
  189.                   'xloc',xlocINI,'top',ytopINI,...
  190.                   'enable','off', ...
  191.                   'wtype','dwt'   ...
  192.                   );
  193.  
  194.     w_uic   = 1.5*Def_Btn_Width;
  195.     h_uic   = 1.5*Def_Btn_Height;
  196.     bdx     = (pos_frame0(3)-w_uic)/2;
  197.     x_left  = pos_frame0(1)+bdx;
  198.     y_low   = toolPos(2)-1.5*Def_Btn_Height-2*dy;
  199.     pos_ana = [x_left, y_low, w_uic, h_uic];
  200.     commonProp = {...
  201.         'Parent',win_tool, ...
  202.         'Unit',win_units,  ...
  203.         'Enable','off'     ...
  204.         };
  205.     str_ana = xlate('Analyze');
  206.     cba_ana = [mfilename '(''anal'',' str_numwin ');'];
  207.     pus_ana = uicontrol(commonProp{:},...
  208.                          'Style','Pushbutton', ...
  209.                          'Position',pos_ana,   ...
  210.                          'String',str_ana,     ...
  211.                          'Callback',cba_ana,   ...
  212.                          'Interruptible','On'  ...
  213.                          );
  214.     % Create coefficients tool.
  215.     %--------------------------
  216.     ytopCFS = pos_ana(2)-4*dy;
  217.     toolPos = utnbcfs('create',win_tool,...
  218.                       'toolOPT','cf1d',  ...
  219.                       'xloc',xlocINI,'top',ytopCFS);
  220.     % Create show checkbox.
  221.     %----------------------
  222.     w_uic = (3*pos_frame0(3))/4;
  223.     x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  224.     h_uic = Def_Btn_Height;
  225.     y_uic = toolPos(2)-Def_Btn_Height/2-h_uic;
  226.     pos_chk_sho = [x_uic, y_uic, w_uic, h_uic];
  227.     str_chk_sho = 'Show Original Signal';
  228.     chk_sho = uicontrol(commonProp{:},...
  229.                         'Style','checkbox',     ...
  230.                         'Visible','on',         ...
  231.                         'Position',pos_chk_sho, ...
  232.                         'String',str_chk_sho    ...
  233.                         );
  234.     %  Normalisation.
  235.     %----------------
  236.     Pos_Graphic_Area = wfigmngr('normalize',win_tool,Pos_Graphic_Area);
  237.  
  238.     % Axes contruction.
  239.     %------------------
  240.     ax     = zeros(4,1);
  241.     pos_ax = zeros(4,4);
  242.     bdx = 0.05;
  243.      ecy_top = 0.04;
  244.     ecy_bot = 0.04;
  245.     ecy_mid = 0.06;
  246.     w_ax = (Pos_Graphic_Area(3)-3*bdx)/2;
  247.     h_ax = (Pos_Graphic_Area(4)-ecy_top-ecy_mid-ecy_bot)/3;
  248.     x_ax = bdx;
  249.     y_ax = Pos_Graphic_Area(2)+Pos_Graphic_Area(4)-ecy_top-h_ax;
  250.     pos_ax(1,:) = [x_ax y_ax w_ax h_ax];
  251.     x_ax = x_ax+w_ax+bdx;
  252.     pos_ax(4,:) = [x_ax y_ax w_ax h_ax];
  253.     x_ax = bdx;
  254.     y_ax = Pos_Graphic_Area(2)+ecy_bot;
  255.     pos_ax(2,:) = [x_ax y_ax w_ax 2*h_ax];
  256.     x_ax = x_ax+w_ax+bdx;
  257.     pos_ax(3,:) = [x_ax y_ax w_ax 2*h_ax];
  258.     for k = 1:4
  259.         ax(k) = axes(...
  260.                      'Parent',win_tool,      ...
  261.                      'Unit','normalized',    ...
  262.                      'Position',pos_ax(k,:), ...
  263.                      'Xtick',[],'Ytick',[],  ...
  264.                      'Box','on',             ...
  265.                      'Visible','off'         ...
  266.                      );
  267.     end
  268.     % Callbacks update.
  269.     %------------------
  270.     hdl_den = utnbcfs('handles',win_tool);
  271.     utanapar('set_cba_num',win_tool,[m_files;hdl_den(:)]);
  272.     pop_lev = utanapar('handles',win_tool,'lev');
  273.     tmp     = num2mstr([pop_lev chk_sho]);
  274.     end_cba = [str_numwin ',' tmp ');'];
  275.     cba_pop_lev = [mfilename '(''update_level'',' end_cba];
  276.     cba_chk_sho = [mfilename '(''show_ori_sig'',' str_numwin ');'];
  277.     set(pop_lev,'Callback',cba_pop_lev);
  278.     set(chk_sho,'Callback',cba_chk_sho);
  279.     % Memory for stored values.
  280.     %--------------------------
  281.     hdl_UIC  = struct('pus_ana',pus_ana,'chk_sho',chk_sho);
  282.     hdl_MEN  = struct('m_load',m_load,'m_save',m_save,'m_demo',m_demo);
  283.     toolATTR = struct('hdl_UIC',hdl_UIC,'hdl_MEN',hdl_MEN);
  284.     wfigmngr('storeValue',win_tool,'ToolATTR',toolATTR);
  285.     hdl_STEM = struct(...
  286.                       'Hstems_O',[], ...
  287.                       'H_vert_O',[], ...
  288.                       'H_stem_O',[], ...
  289.                       'H_vert_O_Copy',[], ...
  290.                       'H_stem_O_Copy',[], ...
  291.                       'Hstems_M',[], ...
  292.                       'H_vert_M',[], ...
  293.                       'H_stem_M',[], ...
  294.                       'H_vert_M_Copy',[], ...
  295.                       'H_stem_M_Copy',[]  ...
  296.                       );
  297.     wfigmngr('storeValue',win_tool,'Stems_struct',hdl_STEM);
  298.     wmemtool('ini',win_tool,n_InfoInit,nb0_stored);
  299.     wmemtool('ini',win_tool,n_param_anal,nb1_stored);
  300.     wmemtool('ini',win_tool,n_membloc0,nb2_stored);
  301.     wmemtool('ini',win_tool,n_synt_sig,nb3_stored);
  302.     wmemtool('ini',win_tool,n_miscella,nb4_stored);
  303.     wmemtool('wmb',win_tool,n_miscella,...
  304.                    ind_graph_area,Pos_Graphic_Area,ind_axe_hdl,ax);
  305.     % End waiting.
  306.     %---------------
  307.     wwaiting('off',win_tool);
  308.   case 'load'
  309.     % Loading file.
  310.     %-------------
  311.     if length(varargin)<2
  312.        [sigInfos,sig_Anal,ok] = ...
  313.             utguidiv('load_sig',win_tool,'Signal_Mask','Load Signal');
  314.         demoFlag = 0;
  315.     else
  316.         sig_Name = deblank(varargin{2});
  317.         wav_Name = deblank(varargin{3});
  318.         lev_Anal = varargin{4};
  319.         filename = [sig_Name '.mat'];
  320.         pathname = utguidiv('WTB_DemoPath',filename);
  321.         [sigInfos,sig_Anal,ok] = ...
  322.             utguidiv('load_dem1D',win_tool,pathname,filename);
  323.         demoFlag = 1;
  324.     end
  325.     if ~ok, return; end
  326.     % Begin waiting.
  327.     %---------------
  328.     wwaiting('msg',win_tool,'Wait ... loading');
  329.     % Get Values.
  330.     %------------
  331.     axe_hdl = wmemtool('rmb',win_tool,n_miscella,ind_axe_hdl);
  332.     % Cleaning.
  333.     %----------
  334.     dynvtool('stop',win_tool);
  335.     utnbcfs('clean',win_tool)
  336.     set(hdl_MEN.m_save,'Enable','Off');
  337.     set(axe_hdl(2:end),'Visible','Off');
  338.     children = allchild(axe_hdl);
  339.     delete(children{:});
  340.     set(axe_hdl,'Xtick',[],'Ytick',[],'Box','on');
  341.     % Setting GUI values.
  342.     %--------------------
  343.     sig_Name = sigInfos.name;
  344.     sig_Size = sigInfos.size;
  345.     sig_Size = max(sig_Size);
  346.     levm     = wmaxlev(sig_Size,'haar');
  347.     levmax   = min(levm,max_lev_anal);
  348.     lev      = min(levmax,5);
  349.     str_lev_data = int2str([1:levmax]');
  350.     if ~demoFlag
  351.         cbanapar('set',win_tool, ...
  352.                  'n_s',{sig_Name,sig_Size}, ...
  353.                  'lev',{'String',str_lev_data,'Value',lev});
  354.     else
  355.         cbanapar('set',win_tool, ...
  356.                  'n_s',{sig_Name,sig_Size}, ...
  357.                  'wav',wav_Name, ...
  358.                  'lev',{'String',str_lev_data,'Value',lev_Anal});
  359.         lev = lev_Anal;
  360.     end
  361.     set(chk_sho,'Value',0)
  362.     cf1dtool('position',win_tool,lev,chk_sho);
  363.     % Drawing.
  364.     %---------
  365.     axeAct = axe_hdl(1);
  366.     lsig   = length(sig_Anal);
  367.     wtitle('Original Signal','Parent',axeAct);
  368.     col_s = wtbutils('colors','sig');
  369.     lin_hdl(1) = line(...
  370.       'Parent',axeAct,  ...
  371.       'Xdata',[1:lsig], ...
  372.       'Ydata',sig_Anal, ...
  373.       'Color',col_s,'Visible','on'...
  374.       );
  375.     ymin = min(sig_Anal);
  376.     ymax = max(sig_Anal);
  377.     dy   = (ymax-ymin)/20;
  378.     set(axeAct,...
  379.         'Xlim',[1 lsig],'Ylim',[ymin-dy ymax+dy], ...
  380.         'XtickMode','auto','YtickMode','auto','Visible','on' ...
  381.         );
  382.     axeAct = axe_hdl(4);
  383.     wtitle('Synthesized Signal','Parent',axeAct);
  384.     lin_hdl(2) = line(...
  385.       'Parent',axeAct,  ...
  386.       'Xdata',[1:lsig], ...
  387.       'Ydata',sig_Anal, ...
  388.       'Color',col_s,'Visible','off'...
  389.       );
  390.     col_ss = wtbutils('colors','ssig');
  391.     lin_hdl(3) = line(...
  392.       'Parent',axeAct,  ...
  393.       'Xdata',[1:lsig], ...
  394.       'Ydata',sig_Anal, ...
  395.       'Color',col_ss,'Visible','off'...
  396.       );
  397.     set(axeAct,...
  398.         'Xlim',[1 lsig],'Ylim',[ymin-dy ymax+dy], ...
  399.         'XtickMode','auto','YtickMode','auto'     ...
  400.         );
  401.     % Setting Analysis parameters.
  402.     %-----------------------------
  403.     wmemtool('wmb',win_tool,n_membloc0,ind_sig,sig_Anal);
  404.     wmemtool('wmb',win_tool,n_param_anal, ...
  405.                    ind_sig_name,sigInfos.name,...
  406.                    ind_sig_size,sigInfos.size ...
  407.                    );
  408.     wmemtool('wmb',win_tool,n_InfoInit, ...
  409.                    ind_filename,sigInfos.filename, ...
  410.                    ind_pathname,sigInfos.pathname  ...
  411.                    );
  412.     % Store Values.
  413.     %--------------
  414.     wmemtool('wmb',win_tool,n_miscella,ind_lin_hdl,lin_hdl);
  415.     % Setting enabled values.
  416.     %------------------------
  417.     utnbcfs('set',win_tool,'handleORI',lin_hdl(1),'handleTHR',lin_hdl(3))
  418.     cbanapar('enable',win_tool,'on');
  419.     set(pus_ana,'Enable','On' );
  420.  
  421.     % End waiting.
  422.     %-------------
  423.     wwaiting('off',win_tool);
  424.   case 'demo'
  425.     cf1dtool('load',varargin{:})
  426.     if length(varargin)>4 
  427.         parDEMO = varargin{5};
  428.     else
  429.         parDEMO = {'Global'};
  430.     end
  431.     % Begin waiting.
  432.     %---------------
  433.     wwaiting('msg',win_tool,'Wait ... computing');
  434.     % Computing.
  435.     %-----------
  436.     cf1dtool('anal',win_tool);
  437.     pause(1)
  438.     utnbcfs('demo',win_tool,parDEMO);
  439.     % End waiting.
  440.     %-------------
  441.     wwaiting('off',win_tool);
  442.   case 'save'
  443.     % Testing file.
  444.     %--------------
  445.     [filename,pathname,ok] = utguidiv('test_save',win_tool, ...
  446.                                  '*.mat','Save Synthesized Signal');
  447.     if ~ok, return; end
  448.     % Begin waiting.
  449.     %--------------
  450.     wwaiting('msg',win_tool,'Wait ... saving');
  451.     % Getting Synthesized Signal.
  452.     %---------------------------
  453.     wname   = wmemtool('rmb',win_tool,n_param_anal,ind_wav_name);
  454.     lin_hdl = wmemtool('rmb',win_tool,n_miscella,ind_lin_hdl);
  455.     lin_hdl = lin_hdl(3);
  456.     sig     = get(lin_hdl,'Ydata');
  457.     % Saving file.
  458.     %--------------
  459.     [name,ext] = strtok(filename,'.');
  460.     if isempty(ext) | isequal(ext,'.')
  461.         ext = '.mat'; filename = [name ext];
  462.     end
  463.     eval([name ' = sig ;']);
  464.     saveStr = {name,'wname'};
  465.     wwaiting('off',win_tool);
  466.     try
  467.       save([pathname filename],saveStr{:});
  468.     catch
  469.       errargt(mfilename,'Save FAILED !','msg');
  470.     end
  471.   case 'anal'
  472.     % Waiting message.
  473.     %-----------------
  474.     wwaiting('msg',win_tool,'Wait ... computing');
  475.  
  476.     % Reading Analysis Parameters.
  477.     %-----------------------------
  478.     sig_Anal = wmemtool('rmb',win_tool,n_membloc0,ind_sig);
  479.     [wav_Name,lev_Anal] = cbanapar('get',win_tool,'wav','lev');
  480.     % Setting Analysis parameters
  481.     %-----------------------------
  482.     wmemtool('wmb',win_tool,n_param_anal, ...
  483.                    ind_wav_name,wav_Name, ...
  484.                    ind_lev_anal,lev_Anal ...
  485.                    );
  486.     % Get Values.
  487.     %------------
  488.     [axe_hdl,lin_hdl] = wmemtool('rmb',win_tool,n_miscella,...
  489.                                   ind_axe_hdl,ind_lin_hdl);
  490.     % Analyzing.
  491.     %-----------
  492.     [coefs,longs] = wavedec(sig_Anal,lev_Anal,wav_Name);
  493.     [tmp,idxsort] = sort(abs(coefs));
  494.     last  = cumsum(longs(1:end-1));
  495.     first = ones(size(last));
  496.     first(2:end) = last(1:end-1)+1;
  497.     len = length(last);
  498.     idxByLev = cell(1,len);
  499.     for k=1:len
  500.         idxByLev{k} = find((first(k)<=idxsort) & (idxsort<=last(k)));
  501.     end
  502.     % Writing coefficients.
  503.     %----------------------
  504.     wmemtool('wmb',win_tool,n_membloc0,...
  505.              ind_coefs,coefs,ind_longs,longs, ...
  506.              ind_first,first,ind_last,last, ...
  507.              ind_sort,idxsort,ind_By_Lev,idxByLev,...
  508.              ind_sizes,[]);
  509.  
  510.     % Clean axes and reset dynvtool.
  511.     %-------------------------------
  512.     hdls_all = get(axe_hdl(2:3),'Children');
  513.     delete(hdls_all{:});
  514.     set(axe_hdl(2:3),'YTickLabel',[],'YTick',[]);
  515.     dynvtool('ini_his',win_tool,'reset')
  516.     % Plot original decomposition.
  517.     %-----------------------------
  518.     xlim = [1,length(sig_Anal)];
  519.     set(axe_hdl(1:4),'Xlim',xlim);
  520.     ax_prop = {'Xlim',xlim,'box','on','XtickMode','auto','Visible','On'};
  521.     axeAct = axe_hdl(2);
  522.     axes(axeAct);
  523.     Hstems_O = dw1dstem(axeAct,coefs,longs,absMode,appView,'WTBX');
  524.     set(axeAct,ax_prop{:});
  525.     wtitle('Original Coefficients','Parent',axeAct);
  526.     % Plot modified decomposition.
  527.     %-----------------------------
  528.     axeAct = axe_hdl(3);
  529.     axes(axeAct);
  530.     Hstems_M = dw1dstem(axeAct,coefs,longs,absMode,appView,'WTBX');
  531.     set(axeAct,ax_prop{:});
  532.     wtitle('Selected Coefficients','Parent',axeAct);
  533.     % Plot signal and synthezised signal.
  534.     %------------------------------------
  535.     axeAct = axe_hdl(4);
  536.     set(axeAct,'Visible','on');
  537.     set(lin_hdl(3),'Ydata',sig_Anal,'Visible','on');
  538.     % Reset tool coefficients.
  539.     %-------------------------
  540.     utnbcfs('update_NbCfs',win_tool,'anal');
  541.     utnbcfs('update_methode',win_tool,'anal');
  542.     utnbcfs('enable',win_tool,'anal');
  543.     set(hdl_MEN.m_save,'Enable','On');
  544.     % Construction of the invisible Stems.
  545.     %-------------------------------------
  546.     cf1dtool('set_Stems_HDL',win_tool,'anal',Hstems_O,Hstems_M);
  547.     % Connect dynvtool.
  548.     %------------------
  549.     params = [axe_hdl(2:3)' , -lev_Anal];
  550.     dynvtool('init',win_tool,[],axe_hdl,[],[1 0], ...
  551.             '','','cf1dcoor',params,'cf1dselc',params);
  552.     % End waiting.
  553.     %-------------
  554.     wwaiting('off',win_tool);
  555.         
  556.   case 'apply'
  557.     % Waiting message.
  558.     %-----------------
  559.     wwaiting('msg',win_tool,'Wait ... computing');
  560.  
  561.     % Analysis Parameters.
  562.     %--------------------
  563.     [first,idxsort,idxByLev] = ...
  564.         wmemtool('rmb',win_tool,n_membloc0,ind_first,ind_sort,ind_By_Lev);
  565.     [nameMeth,nbkept] = utnbcfs('get',win_tool,'nameMeth','nbkept');
  566.     len = length(idxByLev);
  567.     switch nameMeth
  568.       case {'Global','ByLevel'}
  569.         ind = [];
  570.         for k=1:len
  571.             ind = [ind , idxByLev{k}(end-nbkept(k)+1:end)];
  572.         end
  573.         idx_Cfs = idxsort(ind);
  574.         % Computing & Drawing.
  575.         %---------------------
  576.         Hstems_M = cf1dtool('plot_NewDec',win_tool,idx_Cfs,nameMeth);
  577.         % Construction of the invisible Stems.
  578.         %-------------------------------------
  579.         cf1dtool('set_Stems_HDL',win_tool,'apply',Hstems_M);
  580.       case {'Manual'}
  581.         [H_stem_O,H_stem_O_Copy] = ...
  582.             cf1dtool('get_Stems_HDL',win_tool,'Manual');
  583.         ind = [];
  584.         for k=1:len
  585.             y = len+1-k;
  586.             x_stem = get(H_stem_O(y),'Xdata');
  587.             x_stem_Copy = get(H_stem_O_Copy(y),'Xdata');
  588.             Idx = find(ismember(x_stem,x_stem_Copy));
  589.             ind = [ind , Idx+first(k)-1];
  590.         end
  591.         idx_Cfs = ind;
  592.         % Computing & Drawing.
  593.         %---------------------
  594.         cf1dtool('plot_NewDec',win_tool,idx_Cfs,nameMeth);
  595.     end 
  596.     % End waiting.
  597.     %-------------
  598.     wwaiting('off',win_tool);
  599.   case 'Apply_Movie'
  600.     movieSET = varargin{2};
  601.     if isempty(movieSET)
  602.         Hstems_M = cf1dtool('plot_NewDec',win_tool,[],'Stepwise');
  603.         return
  604.     end
  605.     nbInSet = length(movieSET);  
  606.     appFlag = varargin{3};
  607.     popStop = varargin{4};
  608.     % Waiting message.
  609.     %-----------------
  610.     if nbInSet>1
  611.         txt_msg = wwaiting('msg',win_tool,'Wait ... computing');
  612.     end
  613.     % Get Analysis Parameters.
  614.     %-------------------------
  615.     [first,last,idxsort,idxByLev] = ...
  616.         wmemtool('rmb',win_tool,n_membloc0, ...
  617.                        ind_first,ind_last,ind_sort,ind_By_Lev);
  618.     % Computing.
  619.     %-----------
  620.     len = length(last);
  621.     nbKept = zeros(1,len+1);
  622.     switch appFlag
  623.       case 1
  624.         idx_App = idxsort(idxByLev{1});
  625.         App_Len = length(idx_App);
  626.         idxsort(idxByLev{1}) = [];
  627.       case 2
  628.         idx_App = [];
  629.         App_Len = 0;
  630.        
  631.       case 3
  632.         idx_App = [];
  633.         App_Len = 0;       
  634.         idxsort(idxByLev{1}) = [];
  635.     end
  636.     for jj = 1:nbInSet
  637.         nbcfs = movieSET(jj);
  638.         nbcfs  = nbcfs-App_Len;
  639.         idx_Cfs = [idx_App , idxsort(end-nbcfs+1:end)];
  640.         if nbInSet>1 , 
  641.             for k=1:len
  642.               dummy  = find((first(k)<=idx_Cfs) & (idx_Cfs<=last(k)));
  643.               nbKept(k) = length(dummy);
  644.             end
  645.             nbKept(end) = sum(nbKept(1:end-1));
  646.             msg2 = [int2str(nbKept(end)) '  = [' int2str(nbKept(1:end-1)) ']'];
  647.             msg  = strvcat(' ', sprintf('Number of kept coefficients:  %s', msg2)); 
  648.             set(txt_msg,'String',msg);
  649.         end
  650.         % Computing & Drawing.
  651.         %---------------------
  652.         Hstems_M = cf1dtool('plot_NewDec',win_tool,idx_Cfs,'Stepwise');
  653.         if nbInSet>1 , 
  654.             % Test for stopping.
  655.             %-------------------
  656.             user = get(popStop,'Userdata');
  657.             if isequal(user,1)
  658.                set(popStop,'Userdata',[]);
  659.                break
  660.             end
  661.             pause(0.1);
  662.         end
  663.     end
  664.     % Construction of the invisible Stems.
  665.     %-------------------------------------
  666.     cf1dtool('set_Stems_HDL',win_tool,'apply',Hstems_M);
  667.     % End waiting.
  668.     %-------------
  669.     if nbInSet>1 , wwaiting('off',win_tool); end
  670.   case {'select','unselect'}
  671.      OK_Select = isequal(option,'select');
  672.      % Find Select Box.
  673.      %-----------------
  674.      [X,Y] = mngmbtn('getbox',win_tool);
  675.      xmin = ceil(min(X));
  676.      xmax = floor(max(X));
  677.      ymin = min(Y);
  678.      ymax = max(Y);
  679.      % Get stored Stems.
  680.      %------------------
  681.      [H_vert_O,H_stem_O,H_vert_O_Copy,H_stem_O_Copy,...
  682.       H_vert_M,H_stem_M,H_vert_M_Copy,H_stem_M_Copy] = ...
  683.           cf1dtool('get_Stems_HDL',win_tool,'allComponents');
  684.      nb_Stems = length(H_stem_O);
  685.      % Find points.
  686.      %-------------         
  687.      nbKept = utnbcfs('get',win_tool,'nbKept');
  688.      ylow = max(1,floor(ymin));
  689.      ytop = min(ceil(ymax),nb_Stems);
  690.      for y = ylow:ytop
  691.         xy_stem      = get(H_stem_O(y),{'Xdata','Ydata'});
  692.         xy_stem_Copy = get(H_stem_O_Copy(y),{'Xdata','Ydata'});
  693.         Idx = find(xmin<=xy_stem{1} & xy_stem{1}<=xmax & ...
  694.                    ymin<=xy_stem{2} & xy_stem{2}<=ymax);
  695.         if OK_Select
  696.             Idx = Idx(~ismember(xy_stem{1}(Idx),xy_stem_Copy{1}));
  697.         else
  698.             Idx = find(ismember(xy_stem_Copy{1},xy_stem{1}(Idx)));
  699.         end
  700.         if ~isempty(Idx)
  701.             xy_vert_Copy = get(H_vert_O_Copy(y),{'Xdata','Ydata'});
  702.             if OK_Select
  703.                 xy_stem_Copy{1} = [xy_stem_Copy{1} , xy_stem{1}(Idx)];
  704.                 xy_stem_Copy{2} = [xy_stem_Copy{2} , xy_stem{2}(Idx)];
  705.                 tmp = [xy_stem{1}(Idx); xy_stem{1}(Idx) ; xy_stem{1}(Idx)];
  706.                 xy_vert_Copy{1} = [xy_vert_Copy{1} , tmp(:)'];
  707.                 nbIdx = length(Idx);
  708.                 tmp = [y*ones(1,nbIdx); xy_stem{2}(Idx) ; NaN*ones(1,nbIdx)];
  709.                 xy_vert_Copy{2} = [xy_vert_Copy{2} , tmp(:)'];
  710.             else
  711.                 xy_stem_Copy{1}(Idx) = [];
  712.                 xy_stem_Copy{2}(Idx) = [];
  713.                 Idx = 3*Idx-4;
  714.                 Idx = [Idx,Idx+1,Idx+2];
  715.                 xy_vert_Copy{1}(Idx) = [];
  716.                 xy_vert_Copy{2}(Idx) = [];
  717.             end
  718.             set([H_stem_O_Copy(y),H_stem_M_Copy(y)],...
  719.                 'Xdata',xy_stem_Copy{1},...
  720.                 'Ydata',xy_stem_Copy{2} ...
  721.                 );
  722.             set([H_vert_O_Copy(y),H_vert_M_Copy(y)],...
  723.                 'Xdata',xy_vert_Copy{1},...
  724.                 'Ydata',xy_vert_Copy{2} ...
  725.                 );        
  726.             nbInd = length(xy_stem_Copy{1})-1;
  727.             nbKept(nb_Stems+1-y) = nbInd;
  728.         end               
  729.      end
  730.      nbKept(end) = sum(nbKept(1:end-1));
  731.      utnbcfs('set',win_tool,'nbKept',nbKept);
  732.   case 'plot_NewDec'
  733.     % Indices of preserved coefficients & Methode.
  734.     %---------------------------------------------
  735.     idx_Cfs  = varargin{2};
  736.     nameMeth = varargin{3};
  737.     
  738.     % Get Handles.
  739.     %-------------
  740.     [axe_hdl,lin_hdl] = wmemtool('rmb',win_tool,n_miscella,...
  741.                                   ind_axe_hdl,ind_lin_hdl);
  742.     % Get Analysis Parameters.
  743.     %-------------------------
  744.     wav_Name = wmemtool('rmb',win_tool,n_param_anal,ind_wav_name);
  745.     [coefs,longs] = wmemtool('rmb',win_tool,n_membloc0,ind_coefs,ind_longs);
  746.     % Compute synthezized signal.
  747.     %---------------------------
  748.     Cnew = zeros(size(coefs));
  749.     Cnew(idx_Cfs) = coefs(idx_Cfs);
  750.     SS  = waverec(Cnew,longs,wav_Name);
  751.     thr = min(abs(Cnew));
  752.     % Plot modified decomposition.
  753.     %-----------------------------
  754.     xlim    = get(axe_hdl(1),'Xlim');
  755.     ax_prop = {'Xlim',xlim,'box','on'};
  756.     axeAct = axe_hdl(3);
  757.     if ~isequal(nameMeth,'Manual')
  758.         axes(axeAct);
  759.         varargout{1} = dw1dstem(axeAct,Cnew,longs,absMode,appView,'WTBX');
  760.         set(axeAct,ax_prop{:});
  761.     else
  762.         varargout{1} = [];
  763.     end
  764.     % Plot synthezised signal.
  765.     %-------------------------
  766.     axeAct = axe_hdl(4);
  767.     axes(axeAct);
  768.     set(lin_hdl(3),'Ydata',SS);
  769.     ymin = min(SS);
  770.     ymax = max(SS);
  771.     dy   = (ymax-ymin)/20;
  772.     cf1dtool('show_ori_sig',win_tool)
  773.     % wtitle('Synthesized Signal','Parent',axeAct);
  774.     set(axeAct,...
  775.         'Xlim',xlim,  ...
  776.         'XtickMode','auto','YtickMode','auto', ...
  777.         'Box','on'  ...
  778.         );
  779.     set(hdl_MEN.m_save,'Enable','On');   
  780.   case 'get_Stems_HDL'
  781.     % Output parameter.
  782.     %------------------
  783.     mode = varargin{2};
  784.     % Get stored Stems.
  785.     %------------------
  786.     hdl_STEM  = wfigmngr('getValue',win_tool,'Stems_struct');
  787.     varargout = struct2cell(hdl_STEM);
  788.     if isequal(mode,'All') , return; end
  789.     
  790.     [...
  791.      Hstems_O,H_vert_O,H_stem_O,H_vert_O_Copy,H_stem_O_Copy, ...
  792.      Hstems_M,H_vert_M,H_stem_M,H_vert_M_Copy,H_stem_M_Copy  ...
  793.      ] = deal(varargout{:});
  794.      switch mode
  795.        case 'allComponents'
  796.          varargout = {... 
  797.            H_vert_O,H_stem_O,H_vert_O_Copy,H_stem_O_Copy, ...
  798.            H_vert_M,H_stem_M,H_vert_M_Copy,H_stem_M_Copy};
  799.        case 'Manual'
  800.          varargout = {H_stem_O,H_stem_O_Copy};
  801.      end
  802.   case 'set_Stems_HDL'
  803.     mode = varargin{2};
  804.     axe_hdl  = wmemtool('rmb',win_tool,n_miscella,ind_axe_hdl);
  805.     lev_Anal = wmemtool('rmb',win_tool,n_param_anal,ind_lev_anal);
  806.     nb_STEMS = lev_Anal+1;
  807.     hdl_STEM = wfigmngr('getValue',win_tool,'Stems_struct'); 
  808.     switch mode
  809.       case 'anal'
  810.         Hstems_O = varargin{3};
  811.         Hstems_M = varargin{4};
  812.         % Construction of the invisible duplicated coefficients axes.
  813.         %------------------------------------------------------------
  814.         [H_vert_O,H_stem_O,Hstems_O] = extractSTEMS(Hstems_O);
  815.         [H_vert_M,H_stem_M,Hstems_M] = extractSTEMS(Hstems_M);
  816.         % Store values.
  817.         %--------------
  818.         hdl_STEM.Hstems_O = Hstems_O;
  819.         hdl_STEM.H_vert_O = H_vert_O;
  820.         hdl_STEM.H_stem_O = H_stem_O;
  821.         hdl_STEM.Hstems_M = Hstems_M;
  822.         hdl_STEM.H_vert_M = H_vert_M;
  823.         hdl_STEM.H_stem_M = H_stem_M;
  824.       case 'apply'
  825.         Hstems_M = varargin{3};
  826.         % Modification of Stems.
  827.         %-----------------------
  828.         [H_vert_M,H_stem_M,Hstems_M] = extractSTEMS(Hstems_M);
  829.         hdl_STEM.Hstems_M = Hstems_M;
  830.         hdl_STEM.H_vert_M = H_vert_M;
  831.         hdl_STEM.H_stem_M = H_stem_M;
  832.       case 'reset'
  833.         nameMeth = varargin{3};
  834.         hdl_DEL = [hdl_STEM.H_vert_O_Copy,hdl_STEM.H_stem_O_Copy,...
  835.                    hdl_STEM.H_vert_M_Copy,hdl_STEM.H_stem_M_Copy];
  836.         hdl_DEL = hdl_DEL(ishandle(hdl_DEL));
  837.         delete(hdl_DEL)
  838.         if ~isempty(hdl_STEM.Hstems_M)
  839.             HDL_VIS = hdl_STEM.Hstems_M(:,[2:4]);
  840.             HDL_VIS = HDL_VIS(ishandle(HDL_VIS(:)));
  841.         else
  842.             HDL_VIS = [];
  843.         end
  844.         switch nameMeth
  845.           case {'Global','ByLevel','Stepwise'}
  846.             H_vert_O_Copy = [];  H_stem_O_Copy = [];
  847.             H_vert_M_Copy = [];  H_stem_M_Copy = [];
  848.             if ~isequal(nameMeth,'Stepwise')
  849.                 vis_VIS = 'On';
  850.             else
  851.                 vis_VIS = 'Off';
  852.             end
  853.           case {'Manual'}
  854.             [H_vert_O_Copy,H_stem_O_Copy] = initSTEMS(axe_hdl(2),nb_STEMS);
  855.             [H_vert_M_Copy,H_stem_M_Copy] = initSTEMS(axe_hdl(3),nb_STEMS);
  856.             HDL_Copy = [H_vert_O_Copy(:);H_stem_O_Copy(:);...
  857.                         H_vert_M_Copy(:);H_stem_M_Copy(:)];
  858.             vis_VIS = 'Off';
  859.             set(HDL_Copy,'Visible','On');
  860.         end
  861.         set(HDL_VIS,'Visible',vis_VIS);
  862.         hdl_STEM.H_vert_O_Copy = H_vert_O_Copy;
  863.         hdl_STEM.H_stem_O_Copy = H_stem_O_Copy;
  864.         hdl_STEM.H_vert_M_Copy = H_vert_M_Copy;
  865.         hdl_STEM.H_stem_M_Copy = H_stem_M_Copy;
  866.     end
  867.     wfigmngr('storeValue',win_tool,'Stems_struct',hdl_STEM);
  868.   case 'show_ori_sig'
  869.     lin_hdl = wmemtool('rmb',win_tool,n_miscella,ind_lin_hdl);
  870.     vis = getonoff(get(chk_sho,'Value'));
  871.     set(lin_hdl(2),'Visible',vis);
  872.     strTitle = 'Synthezised Signal';
  873.     if isequal(vis(1:2),'on')
  874.         strTitle = [strTitle ' and Original Signal'];
  875.     end
  876.     wtitle(strTitle,'Parent',get(lin_hdl(2),'Parent'))
  877.   case 'position'
  878.     lev_view = varargin{2};
  879.     chk_sho  = varargin{3};
  880.     set(chk_sho,'Visible','off');
  881.     pos_old  = utnbcfs('get',win_tool,'position');
  882.     utnbcfs('set',win_tool,'position',{1,lev_view})
  883.     pos_new  = utnbcfs('get',win_tool,'position');
  884.     ytrans   = pos_new(2)-pos_old(2);
  885.     pos_chk  = get(chk_sho,'Position');
  886.     pos_chk(2) = pos_chk(2)+ytrans;
  887.     set(chk_sho,'Position',pos_chk,'Visible','on');
  888.   case 'update_level'
  889.     pop_lev = varargin{2}(1);
  890.     chk_sho = varargin{2}(2);
  891.     levmax  = get(pop_lev,'value');
  892.     % Get Values.
  893.     %------------
  894.     [axe_hdl,lin_hdl] = wmemtool('rmb',win_tool,n_miscella,...
  895.                                   ind_axe_hdl,ind_lin_hdl);
  896.     % Clean axes.
  897.     %------------
  898.     hdls_all = get([axe_hdl(2:3)],'Children');
  899.     delete(hdls_all{:});
  900.     set(axe_hdl(2:3),'Visible','Off','YTickLabel',[],'YTick',[]);
  901.     % Hide synthezised signal.
  902.     %-------------------------
  903.     set(chk_sho,'Value',0);
  904.     set(wfindobj(axe_hdl(4)),'Visible','Off');
  905.     set(hdl_MEN.m_save,'Enable','Off');
  906.     % Reset coefficients tool and dynvtool.
  907.     %--------------------------------------
  908.     utnbcfs('clean',win_tool)
  909.     cf1dtool('position',win_tool,levmax,chk_sho);
  910.     dynvtool('ini_his',win_tool,'reset')
  911.   case 'handles'
  912.   case 'close'
  913.  
  914.   otherwise
  915.     errargt(mfilename,'Unknown Option','msg');
  916.     error('*');
  917. end
  918. %=============================================================================%
  919. % INTERNAL FUNCTIONS
  920. %=============================================================================%
  921. %-----------------------------------------------------------------------------%
  922. function varargout = copyManyObj(axe,varargin)
  923. nbin = length(varargin);
  924. varargout = cell(1,nbin);
  925. for k = 1:nbin , varargout{k} = copyobj(varargin{k},axe); end
  926. %-----------------------------------------------------------------------------%
  927. function varargout = extractSTEMS(HDL_Stems)
  928. nbrow = 4;
  929. nbcol = length(HDL_Stems)/nbrow;
  930. HDL_Stems = reshape(HDL_Stems(:),nbrow,nbcol)';
  931. H_vert = HDL_Stems(:,2);
  932. H_stem = HDL_Stems(:,3);
  933. varargout = {H_vert,H_stem,HDL_Stems};
  934. %-----------------------------------------------------------------------------%
  935. function varargout = initSTEMS(axe,nbSTEMS)
  936. stemColor = 'y';
  937. stemColor = wtbutils('colors','stem');
  938. linProp   = {...
  939.              'Visible','Off',             ...
  940.              'Xdata',NaN,'Ydata',NaN,     ...
  941.              'MarkerEdgeColor',stemColor, ...
  942.              'MarkerFaceColor',stemColor  ...
  943.              };
  944. linPropVert = {linProp{:},'linestyle','-','Color',stemColor};
  945. linPropStem = {linProp{:},'linestyle','none','Marker','o','MarkerSize',3};
  946. linTmpVert = line(linPropVert{:},'Parent',axe);
  947. linTmpStem = line(linPropStem{:},'Parent',axe);
  948. dupli      = ones(nbSTEMS,1);
  949. HDL_vert = copyobj(linTmpVert,axe(dupli));
  950. HDL_stem = copyobj(linTmpStem,axe(dupli));
  951. delete([linTmpVert,linTmpStem]);
  952. varargout = {HDL_vert,HDL_stem};
  953. %-----------------------------------------------------------------------------%
  954. %=============================================================================%