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

波变换

开发平台:

Matlab

  1. function varargout = dw1dcomp(option,varargin)
  2. %DW1DCOMP Discrete wavelet 1-D compression.
  3. %   VARARGOUT = DW1DCOMP(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 03-Feb-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.22.4.2 $
  8. % Default Value(s).
  9. %------------------
  10. def_nbCodeOfColors = 128;
  11. % Memory Blocks of stored values.
  12. %================================
  13. % MB1.
  14. %-----
  15. n_param_anal   = 'DWAn1d_Par_Anal';
  16. ind_sig_name   = 1;
  17. ind_sig_size   = 2;
  18. ind_wav_name   = 3;
  19. ind_lev_anal   = 4;
  20. ind_axe_ref    = 5;
  21. ind_act_option = 6;
  22. ind_ssig_type  = 7;
  23. ind_thr_val    = 8;
  24. nb1_stored     = 8;
  25. % MB2.
  26. %-----
  27. n_coefs_longs = 'Coefs_and_Longs';
  28. ind_coefs     = 1;
  29. ind_longs     = 2;
  30. nb2_stored    = 2;
  31. % MB1 (local).
  32. %-------------
  33. n_misc_loc = ['MB1_' mfilename];
  34. ind_sav_menus  = 1;
  35. ind_status     = 2;
  36. ind_win_caller = 3;
  37. ind_axe_datas  = 4;
  38. ind_hdl_datas  = 5;
  39. ind_cfsMode    = 6;
  40. ind_lin_cfs    = 7;
  41. ind_pop_mod    = 8;
  42. nbLOC_1_stored = 8;
  43. % MB2 (local).
  44. %-------------
  45. n_thrDATA = 'thrDATA';
  46. ind_value = 1;
  47. nbLOC_2_stored = 1;
  48. % Tag property.
  49. %--------------
  50. tag_axetxt_perf = 'Txt_Perf';
  51. if ~isequal(option,'create') , win_compress = varargin{1}; end
  52. switch option
  53.     case 'create'
  54.         % Get Globals.
  55.         %-------------
  56.         [Def_Btn_Height,Y_Spacing,Def_FraBkColor] = ...
  57.             mextglob('get','Def_Btn_Height','Y_Spacing','Def_FraBkColor' );
  58.         % Calling figure.
  59.         %----------------
  60.         win_caller = varargin{1};
  61.         str_win_caller = sprintf('%.0f',win_caller);
  62.         % Window initialization.
  63.         %----------------------
  64.         win_name = 'Wavelet 1-D  --  Compression';
  65.         [win_compress,pos_win,win_units,str_win_compress,...
  66.                 frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  67.                     wfigmngr('create',win_name,'','ExtFig_CompDeno', ...
  68.                                 strvcat(mfilename,'cond'),1,1,0);
  69.         set(win_compress,'userdata',win_caller);
  70.         varargout{1} = win_compress;
  71. % Add Help for Tool.
  72. %------------------
  73. wfighelp('addHelpTool',win_compress,'Signal Compression','DW1D_COMP_GUI');
  74. % Add Help Item.
  75. %----------------
  76. wfighelp('addHelpItem',win_compress,'Compression Procedure','COMP_PROCEDURE');
  77. wfighelp('addHelpItem',win_compress,'Available Methods','COMP_DENO_METHODS');
  78.         % Menu construction for current figure.
  79.         %--------------------------------------
  80. m_save  = wfigmngr('getmenus',win_compress,'save');
  81.         sav_menus(1) = uimenu(m_save,...
  82.                                 'Label','Compressed &Signal ',...
  83.                                 'Position',1,                   ...
  84.                                 'Enable','Off',                 ...
  85.                                 'Callback',                     ...
  86.                                 [mfilename '(''save_synt'','    ...
  87.                                         str_win_compress ');']  ...
  88.                                 );
  89.         sav_menus(2) = uimenu(m_save,...
  90.                                 'Label','&Coefficients ',       ...
  91.                                 'Position',2,                   ...
  92.                                 'Enable','Off',                 ...
  93.                                 'Callback',                     ...
  94.                                 [mfilename '(''save_cfs'','     ...
  95.                                         str_win_compress ');']  ...
  96.                                 );
  97.         sav_menus(3) = uimenu(m_save,...
  98.                                 'Label','&Decomposition ',      ...
  99.                                 'Position',3,                   ...
  100.                                 'Enable','Off',                 ...
  101.                                 'Callback',                     ...
  102.                                 [mfilename '(''save_dec'','     ...
  103.                                         str_win_compress ');']  ...
  104.                                 );
  105.         % Begin waiting.
  106.         %---------------
  107.         wwaiting('msg',win_compress,'Wait ... initialization');
  108.         % Getting Analysis parameters.
  109.         %-----------------------------
  110.         [Sig_Name,Wav_Name,Lev_Anal,Sig_Size] = ...
  111.                 wmemtool('rmb',win_caller,n_param_anal, ...
  112.                                ind_sig_name,ind_wav_name,...
  113.                                ind_lev_anal,ind_sig_size);
  114.         Wav_Fam  = wavemngr('fam_num',Wav_Name);
  115.         isBior   = wavemngr('isbior',Wav_Fam);
  116.         Sig_Anal = dw1dfile('sig',win_caller);
  117.         % General parameters initialization.
  118.         %-----------------------------------
  119.         dy = Y_Spacing;
  120.         if Lev_Anal>8 , ySpace = 2*dy; else , ySpace = 4*dy; end
  121.         str_pop_mod = strvcat('Global thresholding','By Level thresholding');
  122.         % Command & Graphic parts (common & global thresholding).
  123.         %========================================================
  124.         comFigProp = {'Parent',win_compress,'Unit',win_units};
  125.         % Data, Wavelet and Level parameters.
  126.         %------------------------------------
  127.         xlocINI = pos_frame0([1 3]);
  128.         ytopINI = pos_win(4)-dy;
  129.         toolPos = utanapar('create_copy',win_compress, ...
  130.                     {'xloc',xlocINI,'top',ytopINI},...
  131.                     {'n_s',{Sig_Name,Sig_Size},'wav',Wav_Name,'lev',Lev_Anal}...
  132.                     );
  133.         % Popup for mode.
  134.         %----------------
  135.         w_uic = (3*pos_frame0(3))/4;
  136.         h_uic = Def_Btn_Height;
  137.         y_uic = toolPos(2)-ySpace-h_uic;
  138.         x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  139.         pos_pop_mod = [x_uic, y_uic, w_uic, h_uic];            
  140.         pop_mod = uicontrol(comFigProp{:},...
  141.                             'Style','Popup',...
  142.                             'Position',pos_pop_mod,...
  143.                             'Userdata',1,...
  144.                             'String',str_pop_mod...
  145.                             );
  146.         cba_pop_mod = [mfilename '(''change_mode'',' ...
  147.                           str_win_compress ',' num2mstr(pop_mod) ');'];
  148.         set(pop_mod,'Callback',cba_pop_mod);
  149.         % Global Compression tool.
  150.         %-------------------------
  151.         ytopTHR = pos_pop_mod(2)-ySpace;
  152.         utthrgbl('create',win_compress,'toolOPT','dw1dcomp', ...
  153.                  'xloc',xlocINI,'top',ytopTHR, ...
  154.                  'isbior',isBior ...
  155.                  );
  156.         % Adding colormap GUI.
  157.         %---------------------
  158.         [viewType,hdl_cfs] = dw1dvdrv('get_imgcfs',win_caller);
  159.         if isequal(viewType,'image')
  160.             [pop_pal_caller,mapName,nbColors] = ...
  161.                 cbcolmap('get',win_caller,'pop_pal','mapName','nbColors');
  162.             utcolmap('create',win_compress, ...
  163.                      'xloc',xlocINI, ...
  164.                      'bkcolor',Def_FraBkColor, ...
  165.                      'briflag',0, ...
  166.                      'enable','on');
  167.             pop_pal_loc = cbcolmap('get',win_compress,'pop_pal');
  168.             set(pop_pal_loc,'Userdata',get(pop_pal_caller,'Userdata'));
  169.             cbcolmap('set',win_compress,'pal',{mapName,nbColors});
  170.         end
  171.         % General graphical parameters initialization.
  172.         %--------------------------------------------
  173.         bdx     = 0.08*pos_win(3);
  174.         bdy     = 0.06*pos_win(4);
  175.         ecy     = 0.03*pos_win(4);
  176.         y_graph = 2*Def_Btn_Height+dy;
  177.         h_graph = pos_frame0(4)-y_graph;
  178.         w_graph = pos_frame0(1);
  179.         fontsize = wmachdep('fontsize','normal',9,Lev_Anal);
  180.         % Axes construction parameters.
  181.         %------------------------------
  182.         w_left     = (w_graph-3*bdx)/2;
  183.         x_left     = bdx;
  184.         w_right    = w_left;
  185.         x_right    = x_left+w_left+5*bdx/4;
  186.         n_axeleft  = Lev_Anal;
  187.         n_axeright = 3;
  188.         ind_left   = n_axeleft;
  189.         ind_right  = n_axeright;
  190.         % Vertical separation.
  191.         %---------------------
  192.         w_fra = 0.01*pos_win(3);
  193.         x_fra = (w_graph-w_fra)/2;
  194.         uicontrol('Parent',win_compress,...
  195.                   'Style','frame',...
  196.                   'Unit',win_units,...
  197.                   'Position',[x_fra,y_graph,w_fra,h_graph],...
  198.                   'Backgroundcolor',Def_FraBkColor ...
  199.                   );
  200.         % Building axes on the right part.
  201.         %---------------------------------
  202.         ecy_right  = 2*ecy;
  203.         h_right    =(h_graph-2*bdy-(n_axeright-1)*ecy_right)/n_axeright;
  204.         y_right    = y_graph+2*bdy/3;
  205.         axe_datas  = zeros(1,n_axeright);
  206.         pos_right  = [x_right y_right w_right h_right];
  207.         for k = 1:n_axeright
  208.             axe_datas(k) = axes(...
  209.                                 'Parent',win_compress,  ...
  210.                                 'Units',win_units,...
  211.                                 'Position',pos_right,...
  212.                                 'Drawmode','fast',...
  213.                                 'Box','On' ...
  214.                                 );
  215.             pos_right(2) = pos_right(2)+pos_right(4)+ecy_right;
  216.         end
  217.         set(axe_datas(1),'visible','off');
  218.         % Displaying the signal.
  219.         %-----------------------
  220.         hdl_datas = [NaN ; NaN];
  221.         axeAct = axe_datas(3);
  222.         axes(axeAct)
  223.         curr_color   = wtbutils('colors','sig');
  224.         hdl_datas(1) = line(...
  225.                            'Xdata',1:length(Sig_Anal),...
  226.                            'Ydata',Sig_Anal,...
  227.                            'erasemode','none',...
  228.                            'Color',curr_color,...
  229.                            'Parent',axeAct);
  230.         wtitle('Original signal','Parent',axeAct);
  231.         xlim = [1              Sig_Size];
  232.         ylim = [min(Sig_Anal)  max(Sig_Anal)];
  233.         if xlim(1)==xlim(2) , xlim = xlim+[-0.01 0.01]; end
  234.         if ylim(1)==ylim(2) , ylim = ylim+[-0.01 0.01]; end
  235.         set(axeAct,'Xlim',xlim,'Ylim',ylim);
  236.         % Displaying original details coefficients.
  237.         %------------------------------------------
  238.         axeAct = axe_datas(2);
  239.         [details,set_ylim,ymin,ymax] = dw1dfile('cfs_beg',win_caller,...
  240.                             [1:Lev_Anal],1);
  241.         
  242.         if isequal(viewType,'image')
  243.             flagType = 1;
  244.             cfsMode  = [];
  245.             [nul,i_min] = min(abs(details(:)));
  246.             if ~isempty(hdl_cfs)
  247.                 col_cfs = flipud(get(hdl_cfs,'Cdata'));
  248.             else
  249.                 col_cfs = wcodemat(details,def_nbCodeOfColors,'row',1);
  250.             end
  251.             col_min = col_cfs(i_min);
  252.             col_cfs = flipud(col_cfs);
  253.             axes(axeAct);
  254.             hdl_cfs_ori = image(col_cfs,'Parent',axeAct,'Userdata',col_min);
  255.             clear col_cfs
  256.             levlab = int2str([Lev_Anal:-1:1]');
  257.         else
  258.             flagType = -1;
  259.             axes(axeAct);
  260.             hdl_stem = copyobj(hdl_cfs,axeAct);
  261.             set(hdl_stem,'Visible','on');
  262.             cfsMode  = get(hdl_stem(1),'Userdata');
  263.             levlab = int2str([1:Lev_Anal]');
  264.             hdl_cfs_ori = [];
  265.         end
  266.         set(axeAct,...
  267.               'Userdata',hdl_cfs_ori,...
  268.               'Xlim',[1 Sig_Size],...
  269.               'YTicklabelMode','manual',...
  270.               'YTick',[1:Lev_Anal],...
  271.               'YTickLabel',levlab,...
  272.               'Ylim',[0.5 Lev_Anal+0.5]...
  273.               );
  274.         wtitle('Original coefficients','Parent',axeAct);
  275.         wylabel('Level number','Parent',axeAct);
  276.         xylim = get(axeAct,{'Xlim','Ylim'});
  277.         set(axe_datas(1),'Xlim',xylim{1},'Ylim',xylim{2});
  278.         % Initializing global threshold.
  279.         %-------------------------------
  280.         [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  281.             dw1dcomp('compute_GBL_THR',win_compress,win_caller);
  282.         utthrgbl('set',win_compress,'thrBOUNDS',[0,valTHR,maxTHR]);
  283.        % Displaying perfos & legend.
  284.         %--------------------------
  285.         y_axe = y_graph+2*bdy/3+h_right+ecy_right;
  286.         h_axe = 2*h_right+ecy_right;
  287.         pos_axe_perfo = [x_left y_axe w_left h_axe];
  288.         y_axe = y_graph+h_right/2;
  289.         h_axe = h_right/2;
  290.         pos_axe_legend = [x_left y_axe w_left h_axe];
  291.         utthrgbl('displayPerf',win_compress, ...
  292.                   pos_axe_perfo,pos_axe_legend,thresVALUES,n0SCR,rl2SCR,valTHR);
  293.         [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  294.         utthrgbl('set',win_compress,'perfo',[perfl2,perf0]);
  295.         drawnow
  296.         % Command & Graphic parts (by Level thresholding).
  297.         %=================================================
  298.         utthrw1d('create',win_compress, ...
  299.                  'xloc',xlocINI,'top',ytopTHR,...
  300.                  'ydir',-1, ...
  301.                  'visible','off', ...
  302.                  'enable','on', ...
  303.                  'levmax',Lev_Anal, ...
  304.                  'levmaxMAX',Lev_Anal, ...
  305.                  'isbior',isBior,  ...
  306.                  'toolOPT','comp' ...
  307.                  );
  308.         % Building axes on the left part.
  309.         %--------------------------------
  310.         comAxeProp = {comFigProp{:}, ...
  311.                       'Visible','Off',...
  312.                       'Drawmode','normal',...
  313.                       'Box','On'...
  314.                      };
  315.         ecy_left  = ecy/2;
  316.         h_left    = (h_graph-2*bdy-(n_axeleft-1)*ecy_left)/n_axeleft;
  317.         y_left    = y_graph+bdy;
  318.         axe_left  = zeros(1,n_axeleft);
  319.         pos_left  = [x_left y_left w_left h_left];
  320.         for k = 1:n_axeleft
  321.             if k~=1
  322.                 axe_left(k) = axes(comAxeProp{:},'Position',pos_left,...
  323.                                    'XTicklabelMode','manual','XTickLabel',[]);
  324.             else
  325.                 axe_left(k) = axes(comAxeProp{:},'Position',pos_left);
  326.             end
  327.             pos_left(2) = pos_left(2)+pos_left(4)+ecy_left;
  328.         end
  329.         wtitle('Original details coefficients','Parent',axe_left(Lev_Anal));
  330.         utthrw1d('set',win_compress,'axes',axe_left);
  331.         % Initializing by level threshold.
  332.         %---------------------------------
  333.         maxTHR = zeros(1,Lev_Anal);
  334.         for k = 1:Lev_Anal , maxTHR(k) = max(abs(details(k,:))); end
  335.         [valTHR,perfl2,perf0] = ...
  336.             dw1dcomp('compute_LVL_THR',win_compress,win_caller);
  337.         valTHR = min(valTHR,maxTHR);
  338.         % Displaying details.
  339.         %-------------------
  340.         col_det  = wtbutils('colors','det',Lev_Anal);
  341.         txt_left = ones(Lev_Anal,1);
  342.         for k = Lev_Anal:-1:1
  343.             axeAct  = axe_left(ind_left);
  344.             axes(axeAct);
  345.             lin_cfs(k) = line(...
  346.                            'Parent',axeAct,...
  347.                            'Visible','off', ...
  348.                            'Xdata',1:Sig_Size,...
  349.                            'Ydata',details(k,:),...
  350.                            'Color',col_det(k,:));
  351.             txt_left(k) = txtinaxe('create',['d' wnsubstr(k)],...
  352.                                     axe_left(k),'left',...
  353.                                     'off','bold',fontsize);
  354.             utthrw1d('plot_dec',win_compress,k, ...
  355.                      {maxTHR(k),valTHR(k),1,Sig_Size,k})
  356.             maxi = max([abs(ymax(k)),abs(ymin(k))]);
  357.             if abs(maxi)<eps , maxi = maxi+0.01; end;
  358.             ylim = 1.1*[-maxi maxi];
  359.             set(axe_left(ind_left),'Xlim',xlim,'Ylim',ylim);
  360.             ind_left = ind_left-1;
  361.         end
  362.         % Initialization of Compression structure.
  363.         %----------------------------------------
  364.         xmin = 1; xmax = Sig_Size;
  365.         utthrw1d('set',win_compress,...
  366.                        'thrstruct',{xmin,xmax,valTHR,lin_cfs},...
  367.                        'intdepthr',[]);
  368. % Add Context Sensitive Help (CSHelp).
  369. %-------------------------------------
  370. wfighelp('add_ContextMenu',win_compress,pop_mod,'DW1D_COMP_GUI');
  371. %-------------------------------------
  372.         % Memory blocks update.
  373.         %----------------------
  374.         utthrgbl('set',win_compress,'handleORI',hdl_datas(1));
  375.         utthrw1d('set',win_compress,'handleORI',hdl_datas(1));
  376.         wmemtool('ini',win_compress,n_misc_loc,nbLOC_1_stored);
  377.         wmemtool('wmb',win_compress,n_misc_loc,  ...
  378.                        ind_sav_menus,sav_menus,  ...
  379.                        ind_status,0,             ...
  380.                        ind_win_caller,win_caller,...
  381.                        ind_axe_datas,axe_datas,  ...
  382.                        ind_hdl_datas,hdl_datas,  ...
  383.                        ind_cfsMode,cfsMode,      ...
  384.                        ind_lin_cfs,lin_cfs,      ...
  385.                        ind_pop_mod,pop_mod       ...
  386.                        );
  387.         wmemtool('ini',win_compress,n_thrDATA,nbLOC_2_stored);
  388.         % Axes attachment.
  389.         %-----------------
  390.         if flagType~=-1
  391.             axe_cmd = [axe_datas(1:3) axe_left(1:n_axeleft)];
  392.             axe_act = [];
  393.             axe_cfs = [axe_datas(1:2)];
  394.         else
  395.             axe_cmd = [axe_datas(1:3) axe_left(1:n_axeleft)];
  396.             axe_act = [];
  397.             axe_cfs = [axe_datas(1:2)];
  398.         end
  399.         dynvtool('init',win_compress,[],axe_cmd,axe_act,[1 0], ...
  400.                         '','','dw1dcoor',[win_caller,axe_cfs,flagType*Lev_Anal]);
  401.         % Setting units to normalized.
  402.         %-----------------------------
  403.         wfigmngr('normalize',win_compress);
  404.         % End waiting.
  405.         %-------------
  406.         wwaiting('off',win_compress);
  407.     case 'compress'
  408.         % Waiting message.
  409.         %-----------------
  410.         wwaiting('msg',win_compress,'Wait ... computing');
  411.         % Clear & Get Handles.
  412.         %----------------------
  413.         dw1dcomp('clear_GRAPHICS',win_compress);
  414.         [win_caller,pop_mod]  = wmemtool('rmb',win_compress,n_misc_loc, ...
  415.                                                ind_win_caller,ind_pop_mod);
  416.         [axe_datas,hdl_datas] = wmemtool('rmb',win_compress,n_misc_loc, ...
  417.                                                ind_axe_datas,ind_hdl_datas);
  418.         % Getting memory blocks.
  419.         %-----------------------
  420.         [Wav_Name,Lev_Anal,Sig_Size] = ...
  421.                         wmemtool('rmb',win_caller,n_param_anal,       ...
  422.                                        ind_wav_name,ind_lev_anal,ind_sig_size);
  423.         [coefs,longs] = wmemtool('rmb',win_caller,n_coefs_longs,...
  424.                                        ind_coefs,ind_longs);
  425.         isBior = wavemngr('isbior',Wav_Name);
  426.         % Loading the original signal.
  427.         %-----------------------------
  428.         Sig_Anal = dw1dfile('sig',win_caller);
  429.         mode_val = get(pop_mod,'value');
  430.         if isBior
  431.             topTitle = 'Energy ratio ';
  432.         else
  433.             topTitle = 'Retained energy ';
  434.         end
  435.         switch mode_val
  436.           case 1    % Global thresholding
  437.             valTHR = utthrgbl('get',win_compress,'valthr');
  438.             thrParams = {'gbl',coefs,longs,Wav_Name,Lev_Anal,valTHR,'h',1};
  439.             if isBior
  440.                 [xc,cxc,lxc,perf0] = wdencmp(thrParams{:});
  441.                 normsig = norm(Sig_Anal);
  442.                 perfl2  = 100;
  443.                 if normsig>eps , perfl2 = perfl2*(norm(xc)/normsig)^2; end
  444.             else
  445.                 [xc,cxc,lxc]   = wdencmp(thrParams{:});
  446.                 [perfl2,perf0] = utthrgbl('getPerfo',win_compress);
  447.             end
  448.           case 2    % By level thresholding
  449.             cxc = utthrw1d('den_M2',win_compress,coefs,longs);
  450.             lxc = longs;
  451.             xc  = waverec(cxc,longs,Wav_Name);            
  452.             normsig = norm(Sig_Anal);
  453.             perfl2  = 100;
  454.             if normsig>eps , perfl2 = perfl2*(norm(xc)/normsig)^2; end
  455.             perf0 = 100*(length(find(cxc==0))/length(cxc));
  456.         end
  457.         % Displaying compressed signal.
  458.         %------------------------------
  459.         hdl_comp = hdl_datas(2);
  460.         if ishandle(hdl_comp)
  461.             set(hdl_comp,'Ydata',xc,'Visible','on');
  462.         else
  463.             curr_color = wtbutils('colors','ssig');
  464.             hdl_comp = line('Xdata',1:length(xc),...
  465.                             'Ydata',xc,...
  466.                             'color',curr_color,...
  467.                             'Parent',axe_datas(3));
  468.             hdl_datas(2) = hdl_comp;
  469.             wmemtool('wmb',win_compress,n_misc_loc,...
  470.                            ind_hdl_datas,hdl_datas);
  471.             utthrgbl('set',win_compress,'handleTHR',hdl_comp);
  472.             utthrw1d('set',win_compress,'handleTHR',hdl_comp);
  473.         end     
  474.         % Set a text as a super title.
  475.         %-----------------------------
  476.         wtitle('Original and compressed signals','Parent',axe_datas(3));
  477.         strPerfo = [topTitle num2str(perfl2,'%5.2f') ...
  478.                     ' % -- Zeros ' num2str(perf0,'%5.2f') ' %'];
  479.         wtxttitl(axe_datas(3),strPerfo,tag_axetxt_perf);
  480.         if mode_val==2
  481.             utthrw1d('set',win_compress,'perfos',{perfl2,perf0});
  482.         end 
  483.         % Displaying thresholded details coefficients.
  484.         %---------------------------------------------
  485.         cfsMode = wmemtool('rmb',win_compress,n_misc_loc,ind_cfsMode);
  486.         if isempty(cfsMode)
  487.             col_cfs   = wrepcoef(cxc,lxc);
  488.             nz_cfs    = find(col_cfs~=0);
  489.             [nbr,nbc] = size(col_cfs);
  490.             img_cfs   = get(axe_datas(2),'Userdata');
  491.             col_min   = get(img_cfs,'Userdata');
  492.             cfs_ori   = flipud(get(img_cfs,'Cdata'));
  493.             col_cfs   = col_min*ones(nbr,nbc);
  494.             col_cfs(nz_cfs) = cfs_ori(nz_cfs);
  495.             image(flipud(col_cfs),'Parent',axe_datas(1));
  496.             levlab = int2str([Lev_Anal:-1:1]');
  497.         else
  498.             dw1dstem(axe_datas(1),cxc,lxc,'mode',cfsMode,'colors','WTBX');
  499.             levlab = int2str([1:Lev_Anal]');
  500.         end
  501.         set(axe_datas(1),...
  502.             'clipping','on',            ...
  503.             'Xlim',get(axe_datas(2),'Xlim'),...
  504.             'YTicklabelMode','manual',  ...
  505.             'YTick',[1:Lev_Anal],       ...
  506.             'YTickLabel',levlab,        ...
  507.             'Ylim',[0.5 Lev_Anal+0.5]   ...
  508.             );
  509.         wtitle('Thresholded coefficients','Parent',axe_datas(1));
  510.         wylabel('Level number','Parent',axe_datas(1));
  511.         set(findobj(axe_datas(1)),'Visible','on');
  512.         % Memory blocks & HG update.
  513.         %---------------------------
  514.         switch mode_val
  515.           case 1
  516.             thrParams = utthrgbl('get',win_compress,'valthr');
  517.           case 2
  518.             thrStruct = utthrw1d('get',win_compress,'thrstruct');
  519.             thrParams = {thrStruct(1:Lev_Anal).thrParams};
  520.         end
  521.         wmemtool('wmb',win_compress,n_thrDATA,ind_value,{xc,cxc,lxc,thrParams});
  522.         dw1dcomp('enable_menus',win_compress,'on');
  523.         % End waiting.
  524.         %-------------
  525.         wwaiting('off',win_compress);
  526.     case 'change_mode'
  527.         pop_mod = varargin{2}(1);
  528.         mod_val = get(pop_mod,'value');
  529.         old_mod = get(pop_mod,'userdata');
  530.         if isequal(mod_val,old_mod) , return; end
  531.         set(pop_mod,'userdata',mod_val);
  532.         dw1dcomp('clear_GRAPHICS',win_compress);
  533.         switch mod_val
  534.           case 1 , visGBL = 'on';  visLVL = 'off';
  535.           case 2 , visGBL = 'off'; visLVL = 'on';
  536.         end
  537.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  538.         viewType = dw1dvdrv('get_imgcfs',win_caller);
  539.         if isequal(viewType,'image')
  540.             visMAP = 'on';
  541.             if mod_val==2
  542.                Lev_Anal = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  543.                if Lev_Anal>5 , visMAP = 'off'; else , visMAP = 'on'; end
  544.             end
  545.             cbcolmap('visible',win_compress,visMAP);
  546.         end            
  547.         utthrgbl('visible',win_compress,visGBL);
  548.         utthrw1d('visible',win_compress,visLVL);
  549.     case 'compute_GBL_THR'
  550.         win_caller = varargin{2};
  551.         [numMeth,meth,sliVal] = utthrgbl('get_GBL_par',win_compress);
  552.         [coefs,longs] = wmemtool('rmb',win_caller,n_coefs_longs,...
  553.                                        ind_coefs,ind_longs);
  554.         thrFLAGS = 'dw1dcompGBL';
  555.         switch numMeth
  556.           case 1
  557.             [valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR] = ...
  558.                 wthrmngr(thrFLAGS,meth,coefs,longs);
  559.             if nargout==1 , varargout = {valTHR};
  560.             else          , varargout = {valTHR,maxTHR,thresVALUES,rl2SCR,n0SCR};
  561.             end
  562.           case 2
  563.             sig = dw1dfile('sig',win_caller);
  564.             valTHR = wthrmngr(thrFLAGS,meth,sig);
  565.             maxTHR = max(coefs);
  566.             valTHR = min(valTHR,maxTHR);
  567.             varargout = {valTHR};
  568.         end
  569.     case 'update_GBL_meth'
  570.         dw1dcomp('clear_GRAPHICS',win_compress);
  571.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  572.         valTHR = dw1dcomp('compute_GBL_THR',win_compress,win_caller);
  573.         utthrgbl('update_GBL_meth',win_compress,valTHR);
  574.     case 'show_LVL_perfos'
  575.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  576.         [coefs,longs] = wmemtool('rmb',win_caller,n_coefs_longs,...
  577.                                        ind_coefs,ind_longs);
  578.         lev_anal = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  579.         [numMeth,meth,scal,sorh] = utthrw1d('get_LVL_par',win_compress);
  580.         valTHR = utthrw1d('get',win_compress,'valTHR');
  581.         [perfl2,perf0] = wscrupd(coefs,longs,lev_anal,valTHR,sorh);      
  582.         utthrw1d('set',win_compress,'perfos',{perfl2,perf0}); 
  583.     case 'compute_LVL_THR'
  584.         win_caller = varargin{2};
  585.         [numMeth,meth,alfa,sorh] = utthrw1d('get_LVL_par',win_compress);
  586.        [coefs,longs] = wmemtool('rmb',win_caller,n_coefs_longs,...
  587.                                        ind_coefs,ind_longs);
  588.         level = wmemtool('rmb',win_caller,n_param_anal,ind_lev_anal);
  589.         thrFLAGS = 'dw1dcompLVL';
  590.         switch numMeth
  591.           case {1,2,3,4} , valTHR = wthrmngr(thrFLAGS,meth,coefs,longs,alfa);
  592.           case 5          
  593.             sig = dw1dfile('sig',win_caller);
  594.             valTHR = wthrmngr(thrFLAGS,meth,sig,level);
  595.         end
  596.         [perfl2,perf0] = wscrupd(coefs,longs,level,valTHR,sorh);
  597.         varargout = {valTHR,perfl2,perf0};
  598.         utthrw1d('set',win_compress,'perfos',{perfl2,perf0}); 
  599.     case 'update_LVL_meth'
  600.         dw1dcomp('clear_GRAPHICS',win_compress);
  601.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  602.         [valTHR,perfl2,perf0] = ...
  603.             dw1dcomp('compute_LVL_THR',win_compress,win_caller);
  604.         utthrw1d('update_LVL_meth',win_compress,valTHR);
  605.     case 'clear_GRAPHICS'
  606.         status = wmemtool('rmb',win_compress,n_misc_loc,ind_status);
  607.         if status == 0 , return; end
  608.         % Diseable Toggles and Menus.
  609.         %----------------------------
  610.         dw1dcomp('enable_menus',win_compress,'off');
  611.         % Get Handles.
  612.         %-------------
  613.         [axe_datas,hdl_datas] = wmemtool('rmb',win_compress,n_misc_loc, ...
  614.                                                ind_axe_datas,ind_hdl_datas);
  615.         % Setting the compressed coefs axes invisible.
  616.         %---------------------------------------------
  617.         hdl_comp = hdl_datas(2);
  618.         if ishandle(hdl_comp)
  619.             vis = get(hdl_comp,'Visible');
  620.             if vis(1:2)=='on'
  621.                 txt_perf = findobj(axe_datas(3),'tag',tag_axetxt_perf);
  622.                 if ishandle(txt_perf) , set(txt_perf,'Visible','off'); end
  623.                 set(findobj(axe_datas(1)),'Visible','off');
  624.                 wtitle('Original signal','Parent',axe_datas(3));
  625.                 set(hdl_comp,'Visible','off');
  626.             end
  627.         end
  628.         
  629.     case 'enable_menus'
  630.         enaVal = varargin{2};
  631.         sav_menus = wmemtool('rmb',win_compress,n_misc_loc,ind_sav_menus);
  632.         set(sav_menus,'Enable',enaVal);
  633.         utthrgbl('enable_tog_res',win_compress,enaVal);
  634.         utthrw1d('enable_tog_res',win_compress,enaVal);
  635.         if strncmpi(enaVal,'on',2) , status = 1; else , status = 0; end
  636.         wmemtool('wmb',win_compress,n_misc_loc,ind_status,status);
  637.     case 'save_synt'
  638.         win_compress = varargin{1};
  639.         % Testing file.
  640.         %--------------
  641.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  642.                                      '*.mat','Save Compressed Signal');
  643.         if ~ok, return; end
  644.         % Begin waiting.
  645.         %--------------
  646.         wwaiting('msg',win_compress,'Wait ... saving');
  647.         % Getting Analysis values.
  648.         %-------------------------
  649.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  650.         wname = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  651.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  652.         xc = thrDATA{1};
  653.         thrParams = thrDATA{4};
  654.         if length(thrParams)==1      % Global Mode
  655.             valTHR = thrParams;
  656.             thrName = 'valTHR';
  657.         else
  658.             thrName = 'thrParams';  % By Level Mode
  659.         end
  660.         % Saving file.
  661.         %--------------
  662.         [name,ext] = strtok(filename,'.');
  663.         if isempty(ext) | isequal(ext,'.')
  664.             ext = '.mat'; filename = [name ext];
  665.         end
  666.         saveStr = name;
  667.         eval([saveStr '= xc ;']);
  668.         wwaiting('off',win_compress);
  669.         try
  670.           save([pathname filename],saveStr,thrName,'wname');
  671.         catch
  672.           errargt(mfilename,'Save FAILED !','msg');
  673.         end
  674.     case 'save_cfs'
  675.         win_compress = varargin{1};
  676.         % Testing file.
  677.         %--------------
  678.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  679.                                      '*.mat','Save Coefficients (1D)');
  680.         if ~ok, return; end
  681.         % Begin waiting.
  682.         %--------------
  683.         wwaiting('msg',win_compress,'Wait ... saving coefficients');
  684.         % Getting Analysis values.
  685.         %-------------------------
  686.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  687.         wname = wmemtool('rmb',win_caller,n_param_anal,ind_wav_name);
  688.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  689.         coefs = thrDATA{2};
  690.         longs = thrDATA{3};
  691.         thrParams = thrDATA{4};
  692.         if length(thrParams)==1      % Global Mode
  693.             valTHR = thrParams;
  694.             thrName = 'valTHR';
  695.         else
  696.             thrName = 'thrParams';  % By Level Mode
  697.         end
  698.         % Saving file.
  699.         %--------------
  700.         [name,ext] = strtok(filename,'.');
  701.         if isempty(ext) | isequal(ext,'.')
  702.             ext = '.mat'; filename = [name ext];
  703.         end
  704.         saveStr = {'coefs','longs',thrName,'wname'};
  705.         wwaiting('off',win_compress);
  706.         try
  707.           save([pathname filename],saveStr{:});
  708.         catch
  709.           errargt(mfilename,'Save FAILED !','msg');
  710.         end
  711.     case 'save_dec'
  712.         % Testing file.
  713.         %--------------
  714.         [filename,pathname,ok] = utguidiv('test_save',win_compress, ...
  715.                                      '*.wa1','Save Wavelet Analysis (1D)');
  716.         if ~ok, return; end
  717.         % Begin waiting.
  718.         %--------------
  719.         wwaiting('msg',win_compress,'Wait ... saving decomposition');
  720.         % Getting Analysis parameters.
  721.         %-----------------------------
  722.         win_caller = wmemtool('rmb',win_compress,n_misc_loc,ind_win_caller);
  723.         [wave_name,data_name] = wmemtool('rmb',win_caller,n_param_anal,  ...
  724.                                                ind_wav_name,ind_sig_name);
  725.         % Getting Analysis values.
  726.         %-------------------------
  727.         thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  728.         coefs = thrDATA{2};
  729.         longs = thrDATA{3};
  730.         thrParams = thrDATA{4};
  731.         if length(thrParams)==1      % Global Mode
  732.             valTHR = thrParams;
  733.             thrName = 'valTHR';
  734.         else
  735.             thrName = 'thrParams';  % By Level Mode
  736.         end
  737.         % Saving file.
  738.         %--------------
  739.         [name,ext] = strtok(filename,'.');
  740.         if isempty(ext) | isequal(ext,'.')
  741.             ext = '.wa1'; filename = [name ext];
  742.         end
  743.         saveStr = {'coefs','longs',thrName,'wave_name','data_name'};
  744.         wwaiting('off',win_compress);
  745.         try
  746.           save([pathname filename],saveStr{:});
  747.         catch
  748.           errargt(mfilename,'Save FAILED !','msg');
  749.         end
  750.     case 'close'
  751.          [status,win_caller] = wmemtool('rmb',win_compress,n_misc_loc,...
  752.                                              ind_status,ind_win_caller);
  753.         if status==1
  754.             % Test for Updating.
  755.             %--------------------
  756.             status = wwaitans(win_compress,...
  757.                               'Update the synthesized signal ?',2,'cancel');
  758.         end
  759.         switch status
  760.             case 1
  761.               wwaiting('msg',win_compress,'Wait ... computing');
  762.               thrDATA = wmemtool('rmb',win_compress,n_thrDATA,ind_value);
  763.               valTHR  = thrDATA{4};
  764.               wmemtool('wmb',win_caller,n_param_anal,...
  765.                        ind_ssig_type,'cs',ind_thr_val,valTHR);
  766.               hdl_datas = wmemtool('rmb',win_compress,n_misc_loc,ind_hdl_datas);
  767.               hdl_comp  = hdl_datas(2);
  768.               dw1dmngr('return_comp',win_caller,status,hdl_comp);
  769.               wwaiting('off',win_compress);
  770.             case 0 , dw1dmngr('return_comp',win_caller,status);
  771.         end
  772.         varargout{1} = status;
  773.     otherwise
  774.         errargt(mfilename,'Unknown Option','msg');
  775.         error('*');
  776. end