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

波变换

开发平台:

Matlab

  1. function [out1,out2] = dw1dsupm(option,win_dw1dtool,in3,in4,in5)
  2. %DW1DSUPM Discrete wavelet 1-D superimpose mode manager.
  3. %   [OUT1,OUT2] = DW1DSUPM(OPTION,WIN_DW1DTOOL,IN3,IN4,IN5)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 27-Jun-2001.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.16 $
  8. % MemBloc1 of stored values.
  9. %---------------------------
  10. n_param_anal   = 'DWAn1d_Par_Anal';
  11. ind_sig_name   = 1;
  12. ind_sig_size   = 2;
  13. ind_wav_name   = 3;
  14. ind_lev_anal   = 4;
  15. ind_axe_ref    = 5;
  16. ind_act_option = 6;
  17. ind_ssig_type  = 7;
  18. ind_thr_val    = 8;
  19. nb1_stored     = 8;
  20. % Tag property of objects.
  21. %-------------------------
  22. tag_axeappini = 'Axe_AppIni';
  23. tag_axedetini = 'Axe_DetIni';
  24. tag_axecfsini = 'Axe_CfsIni';
  25. tag_axecolmap = 'Axe_ColMap';
  26. tag_s_inapp   = 'Sig_in_App';
  27. tag_ss_inapp  = 'SSig_in_App';
  28. tag_s_indet   = 'Sig_in_Det';
  29. tag_ss_indet  = 'SSig_in_Det';
  30. tag_app       = 'App';
  31. tag_det       = 'Det';
  32. tag_img_cfs   = 'Img_Cfs';
  33. tag_img_sca   = 'Img_Sca';
  34. children    = get(win_dw1dtool,'Children');
  35. axe_handles = findobj(children,'flat','type','axes');
  36. uic_handles = findobj(children,'flat','type','uicontrol');
  37. txt_handles = findobj(uic_handles,'Style','text');
  38. switch option
  39.     case 'view'
  40.         % in3 = old_mode or ...
  41.         % in3 = -1 : same mode
  42.         % in3 =  0 : clean
  43.         %-------------------------
  44.         [Wave_Name,opt_act,Level_Anal] = ...
  45.                         wmemtool('rmb',win_dw1dtool,n_param_anal,...
  46.                                 ind_wav_name,ind_act_option,ind_lev_anal);
  47.         old_mode = in3;
  48.         [flg_axe,flg_sa,flg_app,flg_sd,flg_det,ccfs_m] = ...
  49.                         dw1dvmod('get_vm',win_dw1dtool,4);
  50.         lev2    = Level_Anal+2;
  51.         v_flg   = [flg_sa , flg_app , flg_sd , flg_det , flg_axe(3)];
  52.         if flg_axe(1)== 0 , v_flg(1:lev2) = zeros(1,lev2); end
  53.         if flg_axe(2)== 0 , v_flg(lev2+1:2*lev2) = zeros(1,lev2); end
  54.         if flg_axe(3)== 0 , v_flg(2*lev2+1) = 0; end
  55.         vis_str = getonoff(v_flg);
  56.         v_s_app = vis_str(1,:);
  57.         v_ss_app= vis_str(2,:);
  58.         v_app   = vis_str(3:lev2,:);
  59.         v_s_det = vis_str(lev2+1,:);
  60.         v_ss_det= vis_str(lev2+2,:);
  61.         v_det   = vis_str(lev2+3:2*lev2,:);
  62.         v_cfs   = vis_str(2*lev2+1,:);
  63.         axe_hdl     = dw1dscrm('axes',win_dw1dtool,flg_axe);
  64.         lin_handles = findobj(axe_hdl,'Type','line');
  65.         img_handles = findobj(axe_hdl,'Type','image');
  66.         s_in_app    = findobj(lin_handles,'Tag',tag_s_inapp);
  67.         s_in_det    = findobj(lin_handles,'Tag',tag_s_indet);
  68.         app         = findobj(lin_handles,'Tag',tag_app);
  69.         ss_in_app   = findobj(lin_handles,'Tag',tag_ss_inapp);
  70.         ss_in_det   = findobj(lin_handles,'Tag',tag_ss_indet);
  71.         det         = findobj(lin_handles,'Tag',tag_det);
  72.         img_cfs     = findobj(img_handles,'Tag',tag_img_cfs);
  73.         img_sca     = findobj(img_handles,'Tag',tag_img_sca);
  74.         if isempty(s_in_app)
  75.             x = dw1dfile('sig',win_dw1dtool);
  76.             xmin = 1;               xmax = length(x);
  77.             ymin = min(x)-eps;      ymax = max(x)+eps;
  78.             set(axe_hdl(1:3),'Xlim',[xmin xmax]);
  79.             col_s = wtbutils('colors','sig');
  80.             line(...
  81.                  'Parent',axe_hdl(1),            ...
  82.                  'Xdata',[xmin:xmax],'Ydata',x,  ...
  83.                  'Color',col_s,'Visible',v_s_app,'Tag',tag_s_inapp);
  84.             line(...
  85.                  'Parent',axe_hdl(2),            ...
  86.                  'Xdata',[xmin:xmax],'Ydata',x,  ...
  87.                  'Color',col_s,'Visible',v_s_det,'Tag',tag_s_indet);
  88.         else
  89.             set(s_in_app,'Visible',v_s_app);
  90.             set(s_in_det,'Visible',v_s_det);
  91.         end
  92.         if isempty(ss_in_app)
  93.             x = dw1dfile('ssig',win_dw1dtool);
  94.             col_ss = wtbutils('colors','ssig');
  95.             line(...
  96.                  'Parent',axe_hdl(1),              ...
  97.                  'Xdata',[1:length(x)],'Ydata',x,  ...
  98.                  'Color',col_ss,'Visible',v_ss_app,...
  99.                  'Tag',tag_ss_inapp);
  100.             line(...
  101.                  'Parent',axe_hdl(2),              ...
  102.                  'Xdata',[1:length(x)],'Ydata',x,  ...
  103.                  'Color',col_ss,'Visible',v_ss_det,...
  104.                  'Tag',tag_ss_indet);
  105.         else
  106.             set(ss_in_app,'Visible',v_ss_app);
  107.             set(ss_in_det,'Visible',v_ss_det);
  108.         end
  109.         if isempty(app)
  110.             x       = dw1dfile('app',win_dw1dtool,1:Level_Anal);
  111.             app     = zeros(1,Level_Anal);
  112.             col_app = wtbutils('colors','app',Level_Anal);
  113.             axAct   = axe_hdl(1);
  114.             axes(axAct);
  115.             for k = 1:Level_Anal
  116.                 app(k) = line('Parent',axAct,       ...
  117.                               'Xdata',[1:size(x,2)],...
  118.                               'Ydata',x(k,:),       ...
  119.                               'Color',col_app(k,:), ...
  120.                               'Visible',v_app(k,:), ...
  121.                               'Tag',tag_app,        ...
  122.                               'Userdata',k          ...
  123.                               );
  124.             end
  125.         else
  126.             for k =1:Level_Anal
  127.                 lin = app(k);
  128.                 ind = get(lin,'Userdata');
  129.                 set(lin,'Visible',v_app(ind,:)); 
  130.             end
  131.         end
  132.         if strcmp(opt_act,'synt')
  133.             ini_str = 'Orig. Synt. Sig.';
  134.         else
  135.             ini_str = 'Signal';
  136.         end
  137.         ss_type = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_ssig_type);
  138.         switch ss_type
  139.             case 'ss', str_ss = 'Synthesized Signal';
  140.             case 'ds', str_ss = 'De-noised Signal';
  141.             case 'cs', str_ss = 'Compressed Signal';
  142.         end
  143.         if v_flg(1)==1
  144.             if v_flg(2)==1
  145.                 str_tit = [ini_str ', ' str_ss];        
  146.             else    
  147.                 str_tit = ini_str;      
  148.             end
  149.         else
  150.             if v_flg(2)==1
  151.                 str_tit = str_ss;       
  152.             else    
  153.                 str_tit = '';   
  154.             end
  155.         end
  156.         ind = find(flg_app==1);
  157.         if ~isempty(ind)
  158.             if isempty(str_tit) , s = '' ; else , s = ' and '; end
  159.             str_tit = [str_tit s 'Approximation(s) at level(s) :'];
  160.             for k = ind
  161.                 str_tit = [str_tit ' ' sprintf('%.0f',k)];
  162.             end
  163.         end
  164.         wtitle(str_tit,'Parent',axe_hdl(1));
  165.         if isempty(det)
  166.             ll = findobj([s_in_det,ss_in_det],'Visible','on');
  167.             if isempty(ll)
  168.                 [x,set_ylim,ymin,ymax] = ...
  169.                         dw1dfile('det',win_dw1dtool,1:Level_Anal,1);
  170.                 ymin = min(ymin);
  171.                 ymax = max(ymax);
  172.                 set_ylim = prod(set_ylim);
  173.             else
  174.                 set_ylim = 0;
  175.                 x = dw1dfile('det',win_dw1dtool,1:Level_Anal);
  176.             end
  177.             det     = zeros(1,Level_Anal);
  178.             col_det = wtbutils('colors','det',Level_Anal);
  179.             axAct   = axe_hdl(2);
  180.             for k = 1:Level_Anal
  181.                 det(k) = line(...
  182.                               'Parent',axAct, ...
  183.                               'Xdata',[1:size(x,2)],...
  184.                               'Ydata',x(k,:),       ...
  185.                               'Color',col_det(k,:), ...
  186.                               'Visible',v_det(k,:), ...
  187.                               'Tag',tag_det,        ...
  188.                               'Userdata',k          ...
  189.                               );
  190.             end
  191.             if set_ylim , set(axAct,'Ylim',[ymin ymax]); end
  192.         else
  193.             for k =1:Level_Anal
  194.                 lin = det(k);
  195.                 ind = get(lin,'Userdata');
  196.                 set(lin,'Visible',v_det(ind,:)); 
  197.             end
  198.         end
  199.         if v_flg(lev2+1)==1
  200.             if v_flg(lev2+2)==1
  201.                 str_tit = [ini_str ', ' str_ss];        
  202.             else    
  203.                 str_tit = ini_str;      
  204.             end
  205.         else
  206.             if v_flg(lev2+2)==1
  207.                 str_tit = str_ss;       
  208.             else    
  209.                 str_tit = '';   
  210.             end
  211.         end
  212.         ind = find(flg_det==1);
  213.         if ~isempty(ind)
  214.             if isempty(str_tit) , s = '' ; else , s = ' and '; end
  215.             str_tit = [str_tit s 'Detail(s) at level(s) :'];
  216.             for k = ind
  217.                 str_tit = [str_tit ' ' sprintf('%.0f',k)];
  218.             end
  219.         end
  220.         wtitle(str_tit,'Parent',axe_hdl(2));
  221.         ax_hdl = axe_hdl(3);
  222.         [rep,ccfs_vm,levs,xlim,nb_cla] = ...
  223.         dw1dmisc('tst_vm',win_dw1dtool,4,ax_hdl,[1:Level_Anal]);
  224.         if rep==1 ,  delete(img_cfs); img_cfs = []; end
  225.         if isempty(img_cfs)
  226.             [x,xlim1,xlim2,ymax,ymin,nb_cla,levs,ccfs_vm] = ...
  227.                     dw1dmisc('col_cfs',win_dw1dtool,ccfs_vm,levs,xlim,nb_cla);
  228.             levlab  = flipud(int2str(levs(:)));
  229.             xmax    = length(x);
  230.             img_cfs = image(flipud(x),...
  231.                     'Visible',v_cfs,'Tag',tag_img_cfs,...
  232.                     'Userdata',[ccfs_vm,levs,xlim1,xlim2,nb_cla],...
  233.                     'Parent',ax_hdl);
  234.             xlim    = get(axe_hdl(1),'Xlim');
  235.             set(ax_hdl, ...
  236.                       'Xlim',xlim,              ...
  237.                       'YTicklabelMode','manual',...
  238.                       'YTick',[1:length(levs)], ...
  239.                       'YTicklabel',levlab,      ...
  240.                       'Ylim',[0.5 Level_Anal+0.5], ...
  241.                       'Tag',tag_axecfsini       ...
  242.                       );
  243.             wylabel('Level number','Parent',ax_hdl);
  244.             clear x
  245.             ax_hdl = axe_hdl(4);
  246.             image([0 1],[0 1],[1:nb_cla],...
  247.                     'Visible',v_cfs,...
  248.                     'Tag',tag_img_sca,...
  249.                     'Parent',ax_hdl);
  250.             set(ax_hdl,...
  251.                     'XTicklabel',[],'YTicklabel',[],...
  252.                     'XTick',[],'YTick',[],'Tag',tag_axecolmap);
  253.         else
  254.             set([img_cfs img_sca],'Visible',v_cfs);
  255.         end
  256.         set(axe_hdl(3:4),'Visible',v_cfs);
  257.         axe_act = axe_hdl(3);
  258.         wylabel('Level number','Parent',axe_act);
  259.         wtitle('Details Coefficients','Parent',axe_act);
  260.         if strcmp(deblankl(v_cfs),'on')
  261.             drawnow
  262.             wsetxlab(axe_hdl(4),'Scale of colors from MIN to MAX');
  263.         end
  264.         % Axes attachment.
  265.         %-----------------
  266.         dw1dsupm('dynv',win_dw1dtool,old_mode);
  267.         % Reference axes used by stat. & histo & ...
  268.         %-------------------------------------------
  269.         wmemtool('wmb',win_dw1dtool,n_param_anal,ind_axe_ref,axe_hdl(1));
  270.     case 'dynv'
  271.         % Axes attachment.
  272.         %-----------------
  273.         okNew = dw1dvdrv('test_mode',win_dw1dtool,'sup',in3);
  274.         if okNew>0
  275.             axe_app_ini = findobj(axe_handles,'flat','Tag',tag_axeappini);
  276.             axe_det_ini = findobj(axe_handles,'flat','Tag',tag_axedetini);
  277.             axe_cfs_ini = findobj(axe_handles,'flat','Tag',tag_axecfsini);
  278.             Level_Anal = wmemtool('rmb',win_dw1dtool,n_param_anal,...
  279.                                             ind_lev_anal);
  280.             dynvtool('get',win_dw1dtool,0,'force');
  281.             dynvtool('init',win_dw1dtool,...
  282.                     [],[axe_app_ini axe_det_ini,axe_cfs_ini],[],[1 0], ...
  283.                     '','','dw1dcoor',[win_dw1dtool,axe_cfs_ini,Level_Anal]);
  284.         end
  285.     case 'del_ss'
  286.         lin_handles = findobj(axe_handles,'Type','line');
  287.         ss_app = findobj(lin_handles,'Tag',tag_ss_inapp);
  288.         ss_det = findobj(lin_handles,'Tag',tag_ss_indet);
  289.         delete([ss_app ss_det]);
  290.     case 'clear'
  291.         % in3 new_mode or ...
  292.         % in3 = 0 : clean 
  293.         %--------------------
  294.         new_mode = in3;
  295.         axe_app_ini = findobj(axe_handles,'flat','Tag',tag_axeappini);
  296.         axe_det_ini = findobj(axe_handles,'flat','Tag',tag_axedetini);
  297.         axe_cfs_ini = findobj(axe_handles,'flat','Tag',tag_axecfsini);
  298.         axe_col_map = findobj(axe_handles,'flat','Tag',tag_axecolmap);
  299.         okNew = dw1dvdrv('test_mode',win_dw1dtool,'sup',new_mode);
  300.         switch okNew
  301.           case 1
  302.               dynvtool('stop',win_dw1dtool);
  303.               hdl_axes = [axe_app_ini,axe_det_ini,axe_cfs_ini,axe_col_map];
  304.               set(findobj(hdl_axes),'visible','off');
  305.               cleanaxe(hdl_axes);
  306.               drawnow;
  307.           case 2  % Show and Scroll Mode
  308.               lin_handles = findobj(axe_handles,'Type','line');
  309.               img_handles = findobj(axe_handles,'Type','image');
  310.               s_in_app    = findobj(lin_handles,'Tag',tag_s_inapp);
  311.               s_in_det    = findobj(lin_handles,'Tag',tag_s_indet);
  312.               ss_in_app   = findobj(lin_handles,'Tag',tag_ss_inapp);
  313.               ss_in_det   = findobj(lin_handles,'Tag',tag_ss_indet);
  314.               img_cfs     = findobj(img_handles,'Tag',tag_img_cfs);
  315.               old_app = findobj(axe_app_ini,'Tag',tag_app);
  316.               out1    = findobj(old_app,'Userdata',1);
  317.               if ~isempty(out1)
  318.                   old_app = old_app(find(old_app~=out1));
  319.               end
  320.               old_det = findobj(axe_det_ini,'Tag',tag_det);
  321.               out2    = findobj(old_det,'Userdata',1);
  322.               if ~isempty(out2)
  323.                   old_det = old_det(find(old_det~=out2));
  324.               end
  325.               set([s_in_app s_in_det out1 ...
  326.                    ss_in_app ss_in_det out2 img_cfs],'Visible','off');
  327.               delete([old_app' old_det']);
  328.         end
  329.     otherwise
  330.         errargt(mfilename,'Unknown Option','msg');
  331.         error('*');
  332. end
  333.