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

波变换

开发平台:

Matlab

  1. function out1 = dw1dmngr(option,win_dw1dtool,in3,in4,in5)
  2. %DW1DMNGR Discrete wavelet 1-D general manager.
  3. %   OUT1 = DW1DMNGR(OPTION,WIN_DW1DTOOL,IN3,IN4,IN5)
  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.18 $
  8. % Default values.
  9. %----------------
  10. max_lev_anal = 12;
  11. % MemBloc0 of stored values.
  12. %---------------------------
  13. n_InfoInit   = 'DW1D_InfoInit';
  14. ind_filename =  1;
  15. ind_pathname =  2;
  16. nb0_stored   =  2;
  17. % MemBloc1 of stored values.
  18. %---------------------------
  19. n_param_anal   = 'DWAn1d_Par_Anal';
  20. ind_sig_name   = 1;
  21. ind_sig_size   = 2;
  22. ind_wav_name   = 3;
  23. ind_lev_anal   = 4;
  24. ind_axe_ref    = 5;
  25. ind_act_option = 6;
  26. ind_ssig_type  = 7;
  27. ind_thr_val    = 8;
  28. nb1_stored     = 8;
  29. % MemBloc2 of stored values.
  30. %---------------------------
  31. n_coefs_longs = 'Coefs_and_Longs';
  32. ind_coefs     = 1;
  33. ind_longs     = 2;
  34. nb2_stored    = 2;
  35. %***********************************************%
  36. %** OPTION = 'ini' - Only for precompilation. **%
  37. %***********************************************%
  38. if strcmp(option,'ini') , return; end
  39. %***********************************************%
  40. switch option
  41.     case 'anal'
  42.         active_option = wmemtool('rmb',win_dw1dtool,n_param_anal,ind_act_option);
  43.         if ~strcmp(active_option,'load_sig')
  44.             % Cleaning.
  45.             %----------
  46.             Signal_Anal = dw1dfile('sig',win_dw1dtool);
  47.             wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  48.             dw1dutil('clean',win_dw1dtool,'load_sig','new_anal');
  49.             % Setting GUI values.
  50.             %--------------------
  51.             dw1dutil('set_gui',win_dw1dtool,'load_sig','new_anal');
  52.             % Drawing.
  53.             %---------
  54.             dw1dvdrv('plot_sig',win_dw1dtool,Signal_Anal);
  55.             % Setting enabled values.
  56.             %------------------------
  57.             dw1dutil('enable',win_dw1dtool,'load_sig');
  58.         else
  59.             wmemtool('wmb',win_dw1dtool,n_param_anal,ind_act_option,'anal');
  60.         end
  61.         % Waiting message.
  62.         %-----------------
  63.         wwaiting('msg',win_dw1dtool,'Wait ... computing');
  64.         % Setting Analysis parameters
  65.         %-----------------------------
  66.         dw1dutil('set_par',win_dw1dtool,option);
  67.         % Setting GUI values.
  68.         %--------------------
  69.         dw1dutil('set_gui',win_dw1dtool,option);
  70.         mousefrm(0,'watch');
  71.         % Computing
  72.         %-----------
  73.         if strcmp(active_option,'load_dec')
  74.             dw1dfile('anal',win_dw1dtool,'new_anal');
  75.         else
  76.             dw1dfile('anal',win_dw1dtool);
  77.         end
  78.         % Drawing.
  79.         %---------
  80.         dw1dvdrv('plot_anal',win_dw1dtool);
  81.         % Setting enabled values.
  82.         %------------------------
  83.         dw1dutil('enable',win_dw1dtool,option);
  84.         % End waiting.
  85.         %-------------
  86.         wwaiting('off',win_dw1dtool);
  87.     case 'synt'
  88.         active_option = wmemtool('rmb',win_dw1dtool,n_param_anal,...
  89.                                         ind_act_option);
  90.         if ~strcmp(active_option,'load_cfs')
  91.             % Cleaning.
  92.             %----------
  93.             wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  94.             dw1dutil('clean',win_dw1dtool,'load_cfs','new_synt');
  95.             % Setting GUI values.
  96.             %--------------------
  97.             dw1dutil('set_gui',win_dw1dtool,'load_cfs');
  98.             % Drawing.
  99.             %---------
  100.             dw1dvdrv('plot_cfs',win_dw1dtool);
  101.             % Setting enabled values.
  102.             %------------------------
  103.             dw1dutil('enable',win_dw1dtool,'load_cfs');
  104.         else
  105.             wmemtool('wmb',win_dw1dtool,n_param_anal,ind_act_option,'synt');
  106.         end
  107.         % Begin waiting.
  108.         %--------------
  109.         wwaiting('msg',win_dw1dtool,'Wait ... computing');
  110.         % Setting Analysis parameters
  111.         %-----------------------------
  112.         dw1dutil('set_par',win_dw1dtool,option);
  113.         % Setting GUI values.
  114.         %--------------------
  115.         dw1dutil('set_gui',win_dw1dtool,option);
  116.         % Computing
  117.         %-----------
  118.         dw1dfile('anal',win_dw1dtool,'synt');
  119.         % Computing & Drawing.
  120.         %----------------------
  121.         dw1dvdrv('plot_synt',win_dw1dtool);
  122.         % Setting enabled values.
  123.         %------------------------
  124.         dw1dutil('enable',win_dw1dtool,option);
  125.         % End waiting.
  126.         %-------------
  127.         wwaiting('off',win_dw1dtool);
  128.     case 'stat'
  129.         mousefrm(0,'watch'); drawnow;
  130.         out1 = feval('dw1dstat','create',win_dw1dtool);
  131.     case 'hist'
  132.         mousefrm(0,'watch'); drawnow;
  133.         out1 = feval('dw1dhist','create',win_dw1dtool);
  134.     case 'comp'
  135.         mousefrm(0,'watch'); drawnow;
  136.         dw1dutil('enable',win_dw1dtool,option);
  137.         out1 = feval('dw1dcomp','create',win_dw1dtool);
  138.     case 'deno'
  139.         mousefrm(0,'watch'); drawnow;
  140.         dw1dutil('enable',win_dw1dtool,option);
  141.         out1 = feval('dw1ddeno','create',win_dw1dtool);
  142.     case {'return_comp','return_deno'}
  143.         % in3 = 1 : preserve compression
  144.         % in3 = 0 : discard compression
  145.         % in4 = hld_lin (optional)
  146.         %--------------------------------------
  147.         if in3==1
  148.             % Begin waiting.
  149.             %--------------
  150.             wwaiting('msg',win_dw1dtool,'Wait ... drawing');
  151.             % Computing
  152.             %-----------
  153.             dw1dfile('comp_ss',win_dw1dtool,in4);
  154.             % Cleaning axes & drawing.
  155.             %------------------------
  156.             dw1dvmod('ss_vm',win_dw1dtool,[1 4 6],1,0);
  157.             dw1dvmod('ss_vm',win_dw1dtool,[2 3 5],1);
  158.             dw1dvmod('ch_vm',win_dw1dtool,2);
  159.             % End waiting.
  160.             %-------------
  161.             wwaiting('off',win_dw1dtool);
  162.         end
  163.         dw1dutil('enable',win_dw1dtool,option);
  164.     case 'load_sig'
  165.         % Loading file.
  166.         %-------------
  167.         [sigInfos,Signal_Anal,ok] = ...
  168.             utguidiv('load_sig',win_dw1dtool,'Signal_Mask','Load Signal');
  169.         if ~ok, return; end
  170.         % Cleaning.
  171.         %----------
  172.         wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  173.         dw1dutil('clean',win_dw1dtool,option,'');
  174.         % Setting Analysis parameters.
  175.         %-----------------------------
  176.         wmemtool('wmb',win_dw1dtool,n_param_anal, ...
  177.                        ind_act_option,option,     ...
  178.                        ind_sig_name,sigInfos.name,...
  179.                        ind_sig_size,sigInfos.size ...
  180.                        );
  181.         wmemtool('wmb',win_dw1dtool,n_InfoInit, ...
  182.                        ind_filename,sigInfos.filename, ...
  183.                        ind_pathname,sigInfos.pathname  ...
  184.                        );
  185.         % Setting GUI values.
  186.         %--------------------
  187.         dw1dutil('set_gui',win_dw1dtool,option,'');
  188.         % Drawing.
  189.         %---------
  190.         dw1dvdrv('plot_sig',win_dw1dtool,Signal_Anal);
  191.         % Setting enabled values.
  192.         %------------------------
  193.         dw1dutil('enable',win_dw1dtool,option);
  194.         % End waiting.
  195.         %-------------
  196.         wwaiting('off',win_dw1dtool);
  197.     case 'load_cfs'
  198.         % Testing file.
  199.         %--------------
  200.         if nargin==2
  201.             % Testing file.
  202.             %--------------
  203.             [filename,pathname,ok] = utguidiv('load_var',win_dw1dtool,   ...
  204.                                        '*.mat','Load Coefficients (1D)', ...
  205.                                        {'coefs','longs'});
  206.             if ~ok, return; end
  207.             % Loading file.
  208.             %--------------
  209.             load([pathname filename],'-mat');
  210.             lev = length(longs)-2;
  211.             if lev>max_lev_anal
  212.                 wwaiting('off',win_dw1dtool);
  213. msg = sprintf(...
  214.    'The level of the decomposition nis too large (max = %d).',max_lev_anal);
  215.                 wwarndlg(msg,'Load Coefficients (1D)','block');
  216.                 return  
  217.             end
  218.             [Signal_Name,ext] = strtok(filename,'.');
  219.             in3 = '';
  220.         end
  221.         % Cleaning.
  222.         %----------
  223.         wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  224.         dw1dutil('clean',win_dw1dtool,option,in3);
  225.         if nargin==2
  226.             % Getting Analysis parameters.
  227.             %-----------------------------
  228.             len         = length(longs);
  229.             Signal_Size = longs(len);
  230.             Level_Anal  = len-2;
  231.             % Setting Analysis parameters
  232.             %-----------------------------
  233.             wmemtool('wmb',win_dw1dtool,n_param_anal,...
  234.                            ind_act_option,option,    ...
  235.                            ind_sig_name,Signal_Name, ...
  236.                            ind_lev_anal,Level_Anal,  ...
  237.                            ind_sig_size,Signal_Size  ...
  238.                            );
  239.             wmemtool('wmb',win_dw1dtool,n_InfoInit,...
  240.                            ind_filename,filename,  ...
  241.                            ind_pathname,pathname   ...
  242.                            );
  243.             % Setting coefs and longs.
  244.             %-------------------------
  245.             wmemtool('wmb',win_dw1dtool,n_coefs_longs, ...
  246.                            ind_coefs,coefs,ind_longs,longs);
  247.         end
  248.         % Setting GUI values.
  249.         %--------------------
  250.         dw1dutil('set_gui',win_dw1dtool,option);
  251.         % Drawing.
  252.         %---------
  253.         dw1dvdrv('plot_cfs',win_dw1dtool);
  254.         % Setting enabled values.
  255.         %------------------------
  256.         dw1dutil('enable',win_dw1dtool,option);
  257.         % End waiting.
  258.         %-------------
  259.         wwaiting('off',win_dw1dtool);
  260.     case 'load_dec'
  261.         % Testing file.
  262.         %--------------
  263.          fileMask = {...
  264.                '*.wa1;*.mat' , 'Decomposition  (*.wa1;*.mat)';
  265.                '*.*','All Files (*.*)'};        
  266.         [filename,pathname,ok] = utguidiv('load_var',win_dw1dtool, ...
  267.                                    fileMask,'Load Wavelet Analysis (1D)',...
  268.                                    {'coefs','longs','wave_name','data_name'});
  269.         if ~ok, return; end
  270.         % Loading file.
  271.         %--------------
  272.         load([pathname filename],'-mat');
  273.         lev = length(longs)-2;
  274.         if lev>max_lev_anal
  275.             wwaiting('off',win_dw1dtool);
  276.             msg = sprintf(...
  277.    'The level of the decomposition nis too large (max = %d).',max_lev_anal);
  278.             wwarndlg(msg,'Load Wavelet Analysis (1D)','block');
  279.             return
  280.         end
  281.         % Cleaning.
  282.         %----------
  283.         wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  284.         dw1dutil('clean',win_dw1dtool,option);
  285.         % Getting Analysis parameters.
  286.         %-----------------------------
  287.         len         = length(longs);
  288.         Signal_Size = longs(len);
  289.         Level_Anal  = len-2;
  290.         Signal_Name = data_name;
  291.         Wave_Name   = wave_name;
  292.         % Setting Analysis parameters
  293.         %-----------------------------
  294.         wmemtool('wmb',win_dw1dtool,n_param_anal, ...
  295.                        ind_act_option,option,    ...
  296.                        ind_sig_name,Signal_Name, ...
  297.                        ind_wav_name,Wave_Name,   ...
  298.                        ind_lev_anal,Level_Anal,  ...
  299.                        ind_sig_size,Signal_Size  ...
  300.                        );
  301.         wmemtool('wmb',win_dw1dtool,n_InfoInit, ...
  302.                        ind_filename,filename, ...
  303.                        ind_pathname,pathname  ...
  304.                        );
  305.         % Setting coefs and longs.
  306.         %-------------------------
  307.         wmemtool('wmb',win_dw1dtool,n_coefs_longs, ...
  308.                        ind_coefs,coefs,ind_longs,longs);
  309.         % Setting GUI values.
  310.         %--------------------
  311.         dw1dutil('set_gui',win_dw1dtool,option);
  312.         % Computing
  313.         %-----------
  314.         sig_rec = dw1dfile('anal',win_dw1dtool,'load_dec');
  315.         % Drawing.
  316.         %---------
  317.         dw1dvdrv('plot_sig',win_dw1dtool,sig_rec,1);
  318.         dw1dvdrv('plot_anal',win_dw1dtool);
  319.         % Setting enabled values.
  320.         %------------------------
  321.         dw1dutil('enable',win_dw1dtool,option);
  322.         % End waiting.
  323.         %-------------
  324.         wwaiting('off',win_dw1dtool);
  325.     case 'demo'
  326.         % in3 = Signal_Name
  327.         % in4 = Wave_Name
  328.         % in5 = Level_Anal
  329.         %------------------
  330.         Signal_Name = deblank(in3);
  331.         Wave_Name   = deblank(in4);
  332.         Level_Anal  = in5;
  333.         % Loading file.
  334.         %-------------
  335.         filename = [Signal_Name '.mat'];       
  336.         pathname = utguidiv('WTB_DemoPath',filename);
  337.         [sigInfos,Signal_Anal,ok] = ...
  338.             utguidiv('load_dem1D',win_dw1dtool,pathname,filename);
  339.         if ~ok, return; end
  340.         % Cleaning.
  341.         %----------
  342.         wwaiting('msg',win_dw1dtool,'Wait ... cleaning');
  343.         dw1dutil('clean',win_dw1dtool,option);
  344.         % Setting Analysis parameters
  345.         %-----------------------------
  346.         wmemtool('wmb',win_dw1dtool,n_param_anal,  ...
  347.                        ind_act_option,option,      ...
  348.                        ind_sig_name,sigInfos.name, ...
  349.                        ind_wav_name,Wave_Name,     ...
  350.                        ind_lev_anal,Level_Anal,    ...
  351.                        ind_sig_size,sigInfos.size  ...
  352.                        );
  353.         wmemtool('wmb',win_dw1dtool,n_InfoInit, ...
  354.                        ind_filename,sigInfos.filename,  ...
  355.                        ind_pathname,sigInfos.pathname   ...
  356.                        );
  357.         % Setting GUI values.
  358.         %--------------------
  359.         dw1dutil('set_gui',win_dw1dtool,option);
  360.         % Drawing.
  361.         %---------
  362.         dw1dvdrv('plot_sig',win_dw1dtool,Signal_Anal,1);
  363.         % Computing
  364.         %-----------
  365.         dw1dfile('anal',win_dw1dtool);
  366.         
  367.         % Drawing.
  368.         %---------
  369.         dw1dvdrv('plot_anal',win_dw1dtool);
  370.         % Setting enabled values.
  371.         %------------------------
  372.         dw1dutil('enable',win_dw1dtool,option);
  373.         % End waiting.
  374.         %-------------
  375.         wwaiting('off',win_dw1dtool);
  376.     case 'save_synt'
  377.         % Testing file.
  378.         %--------------
  379.         [filename,pathname,ok] = utguidiv('test_save',win_dw1dtool, ...
  380.                                      '*.mat','Save Synthesized Signal');
  381.         if ~ok, return; end
  382.         % Begin waiting.
  383.         %--------------
  384.         wwaiting('msg',win_dw1dtool,'Wait ... saving');
  385.         % Getting Analysis values.
  386.         %-------------------------
  387.         [wname,thrParams] = wmemtool('rmb',win_dw1dtool,n_param_anal,...
  388.                                      ind_wav_name,ind_thr_val);
  389.         if length(thrParams)==1
  390.             thrName = 'valTHR';  valTHR = thrParams;
  391.         else
  392.             thrName = 'thrParams';
  393.         end
  394.         ssig = dw1dfile('ssig',win_dw1dtool);
  395.         % Saving file.
  396.         %--------------
  397.         [name,ext] = strtok(filename,'.');
  398.         if isempty(ext) | isequal(ext,'.')
  399.             ext = '.mat'; filename = [name ext];
  400.         end
  401.         saveStr = name;
  402.         eval([saveStr '= ssig ;']);
  403.  
  404.         wwaiting('off',win_dw1dtool);       
  405.         try
  406.           save([pathname filename],saveStr,thrName,'wname');
  407.         catch          
  408.           errargt(mfilename,'Save FAILED !','msg');
  409.         end
  410.     case 'save_cfs'
  411.         % Testing file.
  412.         %--------------
  413.         [filename,pathname,ok] = utguidiv('test_save',win_dw1dtool, ...
  414.                                      '*.mat','Save Coefficients (1D)');
  415.         if ~ok, return; end
  416.         % Begin waiting.
  417.         %--------------
  418.         wwaiting('msg',win_dw1dtool,'Wait ... saving coefficients');
  419.         % Getting Analysis values.
  420.         %-------------------------
  421.         [wname,thrParams] = wmemtool('rmb',win_dw1dtool,n_param_anal,...
  422.                                      ind_wav_name,ind_thr_val);
  423.         if length(thrParams)==1
  424.             thrName = 'valTHR';  valTHR = thrParams;
  425.         else
  426.             thrName = 'thrParams';
  427.         end
  428.         [coefs,longs] = wmemtool('rmb',win_dw1dtool,n_coefs_longs,...
  429.                                        ind_coefs,ind_longs);
  430.         % Saving file.
  431.         %--------------
  432.         [name,ext] = strtok(filename,'.');
  433.         if isempty(ext) | isequal(ext,'.')
  434.             ext = '.mat'; filename = [name ext];
  435.         end
  436.         saveStr = {'coefs','longs',thrName,'wname'};
  437.         wwaiting('off',win_dw1dtool);
  438.         try
  439.           save([pathname filename],saveStr{:});
  440.         catch
  441.           errargt(mfilename,'Save FAILED !','msg');
  442.         end
  443.     case 'save_dec'
  444.         % Testing file.
  445.         %--------------
  446.          fileMask = {...
  447.                '*.wa1;*.mat' , 'Decomposition  (*.wa1;*.mat)';
  448.                '*.*','All Files (*.*)'};
  449.         [filename,pathname,ok] = utguidiv('test_save',win_dw1dtool, ...
  450.                                      fileMask,'Save Wavelet Analysis (1D)');
  451.         if ~ok, return; end
  452.         % Begin waiting.
  453.         %--------------
  454.         wwaiting('msg',win_dw1dtool,'Wait ... saving decomposition');
  455.         % Getting Analysis parameters.
  456.         %-----------------------------
  457.         [wave_name,data_name,thrParams] = wmemtool('rmb',win_dw1dtool,n_param_anal, ...
  458.                                              ind_wav_name,ind_sig_name,ind_thr_val);
  459.         if length(thrParams)==1
  460.             thrName = 'valTHR';  valTHR = thrParams;
  461.         else
  462.             thrName = 'thrParams';
  463.         end
  464.         [coefs,longs] = wmemtool('rmb',win_dw1dtool,n_coefs_longs,...
  465.                                        ind_coefs,ind_longs);
  466.         % Saving file.
  467.         %--------------
  468.         [name,ext] = strtok(filename,'.');
  469.         if isempty(ext) | isequal(ext,'.')
  470.             ext = '.wa1'; filename = [name ext];
  471.         end
  472.         saveStr = {'coefs','longs',thrName,'wave_name','data_name'};
  473.         wwaiting('off',win_dw1dtool);
  474.         try
  475.           save([pathname filename],saveStr{:});
  476.         catch
  477.           errargt(mfilename,'Save FAILED !','msg');
  478.         end
  479.     otherwise
  480.         errargt(mfilename,'Unknown Option','msg');
  481.         error('*');
  482. end