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

波变换

开发平台:

Matlab

  1. function [out1,out2] = dw1ddecm(option,win_dw1dtool,in3,in4)
  2. %DW1DDECM Discrete wavelet 1-D full decomposition mode manager.
  3. %   [OUT1,OUT2] = DW1DDECM(OPTION,WIN_DW1DTOOL,IN3,IN4)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 12-Mar-96.
  5. %   Last Revision: 16-Jul-1999.
  6. %   Copyright 1995-2002 The MathWorks, Inc.
  7. %   $Revision: 1.15 $
  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. % MemBloc4 of stored values.
  21. %---------------------------
  22. n_miscella     = 'DWAn1d_Miscella';
  23. ind_graph_area =  1;
  24. ind_view_mode  =  2;
  25. ind_savepath   =  3;
  26. nb4_stored     =  3;
  27. % Tag property of objects.
  28. %-------------------------
  29. tag_declev    = 'Pop_DecLev';
  30. tag_txtdeclev = 'Txt_DecLev';
  31. tag_axe_dec   = 'Axe_Dec';
  32. tag_txt_dec   = 'Txt_Dec';
  33. tag_s_dec     = 'S_dec';
  34. tag_ss_dec    = 'SS_dec';
  35. tag_a_dec     = 'A_dec';
  36. tag_d_dec     = 'D_dec';
  37. axe_handles   = findobj(get(win_dw1dtool,'Children'),'flat','Type','axes');
  38. txt_a_handles = findobj(axe_handles,'Type','text');
  39. switch option
  40.     case 'ssig'
  41.         % in3 = chk_handle
  42.         %-----------------
  43.         [flg_s_ss,ccfs] = dw1dvmod('get_vm',win_dw1dtool,2);
  44.         val = get(in3,'Value');
  45.         flg_s_ss(2) = val; 
  46.         dw1dvmod('set_vm',win_dw1dtool,2,flg_s_ss,ccfs);
  47.         ss_dec  = findobj(axe_handles,'Tag',tag_ss_dec);
  48.         Level_Anal = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_lev_anal);
  49.         num = Level_Anal+2;
  50.         txt_dec = findobj(txt_a_handles,'Userdata',num,'Tag',tag_txt_dec);
  51.         if val==0
  52.             set(ss_dec,'Visible','off');
  53.             set(txt_dec,'String','s');      
  54.         else
  55.             set(ss_dec,'Visible','on');
  56.             ss_type = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_ssig_type);
  57.             set(txt_dec,'String',['s/' ss_type]);   
  58.         end
  59.     case 'dec'
  60.         wwaiting('msg',win_dw1dtool,'Wait ... computing');
  61.         pop_handles = findobj(win_dw1dtool,'Style','popupmenu');
  62.         pop = findobj(pop_handles,'Tag',tag_declev);
  63.         lev = get(pop,'Value');
  64.         a_dec = findobj(axe_handles,'Type','line','tag',tag_a_dec);
  65.         if ~isempty(a_dec) & lev~=get(a_dec,'Userdata')
  66.             delete(a_dec); 
  67.             a_dec = []; 
  68.         end
  69.         if isempty(a_dec) , dw1ddecm('view',win_dw1dtool,-1,lev); end
  70.         wwaiting('off',win_dw1dtool);
  71.     case 'view'
  72.         % in3 = old_mode or ...
  73.         % in3 = -1 : same mode
  74.         % in3 =  0 : clean
  75.         %---------------------------
  76.         % in4 = level (optional)
  77.         %---------------------------
  78.         old_mode = in3;
  79.         [Wave_Name,Level_Anal,Signal_Size] = ... 
  80.                         wmemtool('rmb',win_dw1dtool,n_param_anal,...
  81.                                 ind_wav_name,ind_lev_anal,ind_sig_size);
  82.         if nargin==3 , level = Level_Anal; else level = in4; end
  83.         [v_flg,ccfs_m] = dw1dvmod('get_vm',win_dw1dtool,2);
  84.         vis_str = getonoff(v_flg);
  85.         v_s     = vis_str(1,:);
  86.         v_ss    = vis_str(2,:);
  87.         [axe_hdl,txt_hdl] = dw1ddecm('axes',win_dw1dtool,level);
  88.         lin_handles = findobj(axe_hdl,'Type','line');
  89.         s_dec  = findobj(lin_handles,'Tag',tag_s_dec);
  90.         ss_dec = findobj(lin_handles,'Tag',tag_ss_dec);
  91.         a_dec  = findobj(lin_handles,'Tag',tag_a_dec);
  92.         d_dec  = findobj(lin_handles,'Tag',tag_d_dec);
  93.         if ~isempty(a_dec)
  94.             if level~=get(a_dec,'Userdata') , delete(a_dec); a_dec = []; end
  95.         end
  96.         for k = 1:length(d_dec)
  97.             if get(d_dec(k),'Userdata')>level , d_dec(k) = -d_dec(k); end
  98.         end
  99.         if ~isempty(d_dec)
  100.             inv_d = -d_dec(find(d_dec<0));
  101.             if ~isempty(inv_d) , set(inv_d,'Visible','off'); end
  102.         end
  103.         nb_axe = level+2;
  104.         ind = [1:level,Level_Anal+1:Level_Anal+2];
  105.         set([axe_hdl(ind) txt_hdl(ind)],'Visible','On');
  106.         ind   = Level_Anal+2;
  107.         axAct = axe_hdl(ind);
  108.         ss_type = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_ssig_type);
  109.         if v_flg(1)==1
  110.             if v_flg(2)==1 , txt = ['s/' ss_type]; else txt = 's'; end
  111.         else
  112.             if v_flg(2)==1 , txt = ss_type;        else txt = '';  end
  113.         end
  114.         set(txt_hdl(ind),'String',txt);
  115.         if isempty(s_dec)
  116.             [x,ymin,ymax] = dw1dfile('sig',win_dw1dtool,1);
  117.             xmin = 1;  xmax = length(x);
  118.             set(axe_hdl,'Xlim',[xmin xmax]);
  119.             axes(axAct);
  120.             col = wtbutils('colors','sig');
  121.             line('Parent',axAct,'Xdata',[1:length(x)],'Ydata',x,...
  122.                  'Color',col,'Visible',v_s,'Tag',tag_s_dec);
  123.             set(axAct,'Ylim',[ymin ymax],'Userdata',ind,'Tag',tag_axe_dec);
  124.         else
  125.             set(s_dec,'Visible',v_s);
  126.         end
  127.         if isempty(ss_dec)
  128.             [x,ymin,ymax] = dw1dfile('ssig',win_dw1dtool,1);
  129.             ylim = get(axAct,'Ylim');
  130.             if ylim(1)<ymin , ymin = ylim(1); end
  131.             if ylim(2)>ymax , ymax = ylim(2); end
  132.             axes(axAct);
  133.             col = wtbutils('colors','ssig');
  134.             line('Parent',axAct,'Xdata',[1:length(x)],'Ydata',x,...
  135.                     'Color',col,'Visible',v_ss,'Tag',tag_ss_dec);
  136.             set(axAct,'Ylim',[ymin,ymax],'Userdata',ind,'Tag',tag_axe_dec);
  137.         else
  138.             set(ss_dec,'Visible',v_ss);
  139.         end
  140.         ind   = Level_Anal+1;
  141.         axAct = axe_hdl(ind);
  142.         if isempty(a_dec)
  143.             [x,ymin,ymax] = dw1dfile('app',win_dw1dtool,level,3);
  144.             col_app = wtbutils('colors','app',Level_Anal);
  145.             line(...
  146.                  'Parent',axAct,       ...
  147.                  'Xdata',[1:length(x)],...
  148.                  'Ydata',x,            ...
  149.                  'Color',col_app(level,:),...
  150.                  'Userdata',level,'Tag',tag_a_dec);
  151.             set(axAct,'Ylim',[ymin ymax],'Tag',tag_axe_dec);
  152.         else
  153.             set(a_dec,'Visible','on');
  154.         end
  155.         set(txt_hdl(ind),'String',['a' wnsubstr(level)]);
  156.         if isempty(d_dec)
  157.             [x,set_ylim,ymin,ymax] = dw1dfile('det',win_dw1dtool,1:Level_Anal,1);
  158.             col_det = wtbutils('colors','det',Level_Anal);
  159.             for k = Level_Anal:-1:1
  160.                 axe = axe_hdl(k);
  161.                 if k>level , vis = 'off'; else , vis = 'on'; end
  162.                 line(...
  163.                      'Parent',axe,         ...
  164.                      'Xdata',[1:size(x,2)],...
  165.                      'Ydata',x(k,:),       ...
  166.                      'Color',col_det(k,:), ...
  167.                      'Userdata',k,         ...
  168.                      'Visible',vis,        ...
  169.                      'Tag',tag_d_dec       ...
  170.                      );
  171.                 prop = {'Userdata',k,'Tag',tag_axe_dec};
  172.                 if set_ylim ,  prop = {'Ylim',[ymin(k) ymax(k)],prop{:}}; end
  173.                 set(axe,prop{:});
  174.             end
  175.         else
  176.             set(d_dec(1:level),'Visible','on');
  177.         end
  178.         set(axe_hdl(2:end),...
  179.                 'XTicklabelMode','manual', ...
  180.                 'XTickLabel',[]            ...
  181.                 );
  182.         axeAct = axe_hdl(end);
  183.         axes(axeAct);
  184.         i_lev   = int2str(level);
  185.         str_tit = sprintf('Decomposition at level %s : s = a%s', i_lev ,i_lev);
  186.         for k =level:-1:1
  187.             str_tit = [str_tit ' + d' int2str(k)];
  188.         end
  189.         str_tit = [str_tit ' .'];
  190.         wtitle(str_tit,'Parent',axeAct);
  191.         % Axes attachment.
  192.         %-----------------
  193.         okNew = dw1dvdrv('test_mode',win_dw1dtool,'dec',old_mode);
  194.         if okNew
  195.             set(axe_hdl,'Xlim',[1 Signal_Size]);
  196.             dynvtool('init',win_dw1dtool,[],axe_hdl,[],[1 0]);
  197.         end
  198.         % Reference axes used by stat. & histo & ...
  199.         %-------------------------------------------
  200.         wmemtool('wmb',win_dw1dtool,n_param_anal,ind_axe_ref,axe_hdl(1));
  201.     case 'axes'
  202.         % in3 = level_view
  203.         %-----------------
  204.         Level_Anal = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_lev_anal);
  205.         if nargin==2 , in3 = Level_Anal; end
  206.         % Axes Positions.
  207.         %----------------
  208.         pos_graph = wmemtool('rmb',win_dw1dtool,n_miscella,ind_graph_area);
  209.         pos_win   = get(win_dw1dtool,'Position');
  210.         win_units = get(win_dw1dtool,'Units');
  211.         nb_axes_tot = Level_Anal+2;
  212.         nb_axes = in3+2;
  213.         bdxl    = 0.1*pos_win(3);
  214.         bdxr    = 0.05*pos_win(3);
  215.         w_used  = pos_graph(3)-bdxl-bdxr;
  216.         bdy = 0.05*pos_win(4);
  217.         ecy = 0.02*pos_win(4);
  218.         h_used = (pos_graph(4)-2*bdy-(nb_axes-1)*ecy)/nb_axes;
  219.         pos_axe = [bdxl pos_graph(2)+bdy w_used h_used];
  220.         pos_axe = pos_axe(ones(1,nb_axes),:);
  221.         y_axe   = pos_axe(1,2);
  222.         for k=2:nb_axes
  223.             y_axe = y_axe+h_used+ecy;
  224.             pos_axe(k,2) = y_axe;
  225.         end
  226.         out1 = zeros(1,nb_axes_tot);
  227.         out2 = zeros(1,nb_axes_tot);
  228.         out1tmp = findobj(axe_handles,'flat','Tag',tag_axe_dec);
  229.         if ~isempty(out1tmp)
  230.             out2tmp = findobj(txt_a_handles,'Tag',tag_txt_dec);
  231.             for k = 1:nb_axes_tot
  232.                 out1(k) = findobj(out1tmp,'flat','Userdata',k);
  233.                 out2(k) = findobj(out2tmp,'Userdata',k);
  234.             end
  235.             set([out1 out2],'Visible','off');
  236.         else
  237.             axeProp = {...
  238.                'Parent',win_dw1dtool,...
  239.                'Units',win_units,    ...
  240.                'Visible','off',      ...
  241.                'Nextplot','add',     ...
  242.                'DrawMode','Fast',    ...
  243.                'Box','On',           ...
  244.                'Tag',tag_axe_dec     ...
  245.                };
  246.             for k = 1:nb_axes_tot
  247.                 if k~=1
  248.                     axeProp = {axeProp{:}, ...
  249.                                'XTicklabelMode','manual','XTickLabel',[]};
  250.                 end
  251.                 out1(k) = axes(axeProp{:},'Userdata',k);
  252.                 switch k
  253.                   case nb_axes_tot ,   txt_str = 's/ss';                    
  254.                   case nb_axes_tot-1 , txt_str = 'a';                    
  255.                   otherwise ,          txt_str = ['d' wnsubstr(k)];                   
  256.                 end
  257.                 out2(k) = txtinaxe('create',txt_str,out1(k),'l','off');
  258.                 set(out2(k),'Userdata',k,'Tag',tag_txt_dec);
  259.             end
  260.         end
  261.         fontsize = wmachdep('fontsize','normal',20);
  262.         set(out2,'FontSize',fontsize);
  263.         for k = 1:nb_axes-2
  264.             set(out1(k),'Position',pos_axe(k,:));
  265.             txtinaxe('pos',out2(k));
  266.         end
  267.         ind = nb_axes-2;
  268.         for k = nb_axes_tot-1:nb_axes_tot
  269.             ind = ind+1;
  270.             set(out1(k),'Position',pos_axe(ind,:));
  271.             txtinaxe('pos',out2(k));
  272.         end
  273.     case 'del_ss'
  274.         lin_handles = findobj(axe_handles,'Type','line');
  275.         ss_sig      = findobj(lin_handles,'Tag',tag_ss_dec);
  276.         delete(ss_sig);
  277.     case 'clear'
  278.         dynvtool('stop',win_dw1dtool);
  279.         out1 = findobj(axe_handles,'flat','Tag',tag_axe_dec);
  280.         delete(out1);
  281.         
  282.     otherwise
  283.         errargt(mfilename,'Unknown Option','msg');
  284.         error('*');
  285. end
  286.