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

波变换

开发平台:

Matlab

  1. function varargout = wdretool(option,varargin)
  2. %WDRETOOL Wavelet Density and Regression tool.
  3. %   VARARGOUT = WDRETOOL(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 05-Dec-96.
  5. %   Last Revision: 05-Feb-2004.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.12.4.2 $  $Date: 2004/03/15 22:42:38 $
  8. % Test inputs.
  9. %-------------
  10. if nargin==0 , option = 'createREG'; end
  11. [option,winAttrb] = utguidiv('ini',option,varargin{:});
  12. % Memory Blocks of stored values.
  13. %================================
  14. % MB1.
  15. %-----
  16. n_membloc1   = 'MB_1';
  17. ind_xdata    = 1;
  18. ind_ydata    = 2;
  19. ind_xbounds  = 3;
  20. ind_filename = 4;
  21. ind_pathname = 5;
  22. ind_sig_name = 6;
  23. nb2_stored   = 6;
  24. % MB2.
  25. %-----
  26. n_membloc2   = 'MB_2';
  27. ind_status   = 1;
  28. ind_lin_den  = 2;
  29. ind_gra_area = 3;
  30. nb1_stored   = 3;
  31. % MB3.
  32. %-----
  33. n_membloc3 = 'MB_3';
  34. ind_coefs  = 1;
  35. ind_longs  = 2;
  36. ind_sig    = 3;
  37. nb4_stored = 3;
  38. % Default values.
  39. %----------------
  40. def_MinBIN = 64;
  41. def_DefBIN = 256;
  42. default_wave = 'sym4';
  43. NB_max_lev = 8;
  44. NB_def_lev = 5;
  45. yLevelDir  = -1;
  46. % Tag property.
  47. %--------------
  48. tag_ori = 'Sig';
  49. tag_dat = 'Proc_Data';
  50. tag_app = 'App';
  51. tag_est = 'Est';
  52. switch option
  53.   case {'createDEN','createREG'}
  54.   case 'close' ,
  55.   otherwise
  56.     win_tool = varargin{1};
  57.     handles  = wfigmngr('getValue',win_tool,['WDRE_handles']);
  58.     hdl_UIC  = handles.hdl_UIC;
  59.     hdl_AXE  = handles.hdl_AXE;
  60.     txt_hdl  = handles.hdl_TXT;
  61.     hdl_MEN  = handles.hdl_MEN;
  62.     men_sav  = hdl_MEN(end);
  63.     dummy    = struct2cell(hdl_UIC);
  64.     [txt_bin,sli_bin,edi_bin,pus_dec,chk_den] = deal(dummy{:});
  65.     axe_hdl  = struct2cell(hdl_AXE);
  66.     [axe_L_1,axe_R_1,axe_L_2,axe_R_2,axe_cfs,axe_det,axe_app] =  ...
  67.            deal(axe_hdl{:});
  68.     axe_hdl  = cat(2,axe_hdl{:});
  69.     colors   = wfigmngr('getValue',win_tool,['WDRE_colors']);
  70.     toolATTR = wfigmngr('getValue',win_tool,['WDRE_toolATTR']);
  71.     switch option
  72.       case {'load','demo'}
  73.       otherwise , toolMode = toolATTR.toolMode;
  74.     end
  75. end
  76. switch option
  77.     case {'createDEN','createREG'}
  78.         % Parameters initialization.
  79.         %---------------------------
  80.         indic_vis_lev = getLevels(NB_max_lev,yLevelDir);
  81.         % Get Globals.
  82.         %-------------
  83.         [Def_Txt_Height,Def_Btn_Height,X_Spacing,Y_Spacing, ...
  84.          sliYProp,Def_EdiBkColor, Def_FraBkColor] = ...
  85.             mextglob('get',...
  86.                 'Def_Txt_Height','Def_Btn_Height','X_Spacing','Y_Spacing', ...
  87.                 'Sli_YProp','Def_EdiBkColor','Def_FraBkColor' ...
  88.                 );
  89.         % Window initialization.
  90.         %-----------------------
  91.         switch option
  92.           case 'createREG'
  93.             win_title = 'Regression Estimation 1-D';
  94.             estiNAME  = 'esti_REG';
  95. figExtMode = 'ExtFig_Tool_1';
  96.           case 'createDEN'
  97.             win_title = 'Density Estimation 1-D';
  98.             estiNAME  = 'esti_DEN';
  99. figExtMode = 'ExtFig_Tool_3';
  100.         end
  101.         [win_tool,pos_win,win_units,str_numwin,...
  102.             frame0,pos_frame0,Pos_Graphic_Area,pus_close] = ...
  103.                wfigmngr('create',win_title,winAttrb,figExtMode,mfilename,1,1,0);
  104.         if nargout>0 , varargout{1} = win_tool; end
  105.         % Menu construction for current figure.
  106.         %--------------------------------------
  107.         m_files = wfigmngr('getmenus',win_tool);
  108.         switch option
  109.           case 'createREG'
  110. % Add Help for Tool.
  111. %------------------
  112. wfighelp('addHelpTool',win_tool, ...
  113. 'One-Dimensional Estimation - &Random Design','REGR_GUI');
  114. wfighelp('addHelpTool',win_tool, ...
  115. 'One-Dimensional Estimation - &Fixed Design','REGF_GUI');
  116. % Add Help Item.
  117. %----------------
  118. wfighelp('addHelpItem',win_tool,'Regression Estimation','REG_EST');
  119. wfighelp('addHelpItem',win_tool,'Available Methods','COMP_DENO_METHODS');
  120. wfighelp('addHelpItem',win_tool,'Variance Adaptive Thresholding','VARTHR');
  121. wfighelp('addHelpItem',win_tool,'Loading and Saving','REG_LOADSAVE');
  122. m_load = wfigmngr('getmenus',win_tool,'load');  
  123.             lab = 'Data for &Fixed Design Regression';
  124.             men_fix = uimenu(m_load,...
  125.                          'Label',lab,'Position',1, ...
  126.                          'Callback',               ...
  127.                          [mfilename '(''load'','   ...
  128.                              str_numwin ',''fixreg'');'] ...
  129.                          );
  130.             lab = 'Data for &Stochastic Design Regression';
  131.             men_sto = uimenu(m_load,...
  132.                         'Label',lab,'Position',2, ...
  133.                         'Callback',               ...
  134.                         [mfilename '(''load'','   ...
  135.                             str_numwin ',''storeg'');'] ...
  136.                         );
  137.             men_den = [];
  138.             men_sav = uimenu(m_files,...
  139.                          'Label','&Save Estimated Function',...
  140.                          'Position',2,            ...
  141.                          'Enable','Off',          ...
  142.                          'Callback',              ...
  143.                          [mfilename '(''save'','  ...
  144.                              str_numwin ',''fun'');']...
  145.                          );
  146.             m_demo = uimenu(m_files,...
  147.                         'Label','&Example Analysis','Position',3,'Separator','Off');
  148.  
  149.             numDEM = 1;
  150.             labDEM = 'Fixed Design';
  151.             m_demo_1 = uimenu(m_demo, ...
  152.                         'Label',labDEM,'Position',numDEM,'Separator','Off');
  153.             demoSET = {...
  154.               'fixreg' , 'Example I'     , 'ex1nfix'  , 'db2'  , 5 ; ...
  155.               'fixreg' , 'Example II'    , 'ex2nfix'  , 'sym4' , 5 ; ...
  156.               'fixreg' , 'Example II'    , 'ex3nfix'  , 'db3'  , 5 ; ...
  157.               'fixreg' , 'Noisy blocks'  , 'noisbloc' , 'haar' , 5 ; ...
  158.               'fixreg' , 'Noisy Doppler' , 'noisdopp' , 'db5'  , 5 ; ...
  159.               'fixreg' , 'Noisy bumps'   , 'noisbump' , 'db5'  , 5   ...
  160.               };
  161.             setDEMOS(m_demo_1,mfilename,str_numwin,demoSET,0)
  162.             numDEM = 2;
  163.             labDEM = ['Fixed Design - Interval Dependent Noise Variance'];
  164.             m_demo_2 = uimenu(m_demo, ...
  165.                         'Label',labDEM,'Position',numDEM,'Separator','Off');
  166.             demoSET = {...
  167.               'fixreg' , 'Noisy blocks (I)  - 3 intervals' , 'nblocr1' , 'sym4', 5 , '{3}' ; ...
  168.               'fixreg' , 'Noisy blocks (II) - 3 intervals' , 'nblocr2' , 'sym4', 5 , '{3}' ; ...
  169.               'fixreg' , 'Noisy Doppler (I) - 3 intervals' , 'ndoppr1' , 'sym4', 5 , '{3}' ; ...
  170.               'fixreg' , 'Noisy bumps (I)   - 3 intervals' , 'nbumpr1' , 'sym4', 5 , '{3}' ; ...
  171.               'fixreg' , 'Noisy bumps (II)  - 2 intervals' , 'nbumpr2' , 'sym4', 5 , '{2}' ; ...
  172.               'fixreg' , 'Noisy bumps (III) - 4 intervals' , 'nbumpr3' , 'sym4', 5 , '{4}' ; ...
  173.               'fixreg' , 'Elec. consumption - 3 intervals' , 'nelec'   , 'sym4', 5 , '{3}'   ...
  174.               };
  175.             setDEMOS(m_demo_2,mfilename,str_numwin,demoSET,0)
  176.             numDEM = 3;
  177.             labDEM = 'Stochastic Design';
  178.             m_demo_3 = uimenu(m_demo,...
  179.                         'Label',labDEM,'Position',numDEM,'Separator','On');
  180.             demoSET = {...
  181.               'storeg' , 'Example I'     , 'ex1nsto'  , 'sym4' ,5 ; ...
  182.               'storeg' , 'Example II'    , 'ex2nsto'  , 'haar' ,5 ; ...
  183.               'storeg' , 'Example III'   , 'ex3nsto'  , 'db6'  ,5 ; ...
  184.               'storeg' , 'Noisy Doppler' , 'noisdopp' , 'db5'  ,5 ; ...
  185.               'storeg' , 'Noisy bumps'   , 'noisbump' , 'db5'  ,5   ...
  186.               };
  187.             setDEMOS(m_demo_3,mfilename,str_numwin,demoSET,0)
  188.  
  189.             numDEM = 4;
  190.             labDEM = ['Stochastic Design '...
  191.                 ' - Interval Dependent Noise Variance'];
  192.             m_demo_4 = uimenu(m_demo,...
  193.                         'Label',labDEM,'Position',numDEM,'Separator','Off');
  194.             demoSET = {...
  195.               'storeg' , 'Noisy blocks (I)  - 3 intervals' , 'snblocr1' , 'sym4', 5 , '{3}' ; ...
  196.               'storeg' , 'Noisy blocks (II) - 3 intervals' , 'snblocr2' , 'sym4', 5 , '{3}' ; ...
  197.               'storeg' , 'Noisy Doppler (I) - 3 intervals' , 'sndoppr1' , 'sym4', 5 , '{3}' ; ...
  198.               'storeg' , 'Noisy bumps (I)   - 3 intervals' , 'snbumpr1' , 'sym4', 5 , '{3}' ; ...
  199.               'storeg' , 'Noisy bumps (II)  - 2 intervals' , 'snbumpr2' , 'sym4', 5 , '{2}' ; ...
  200.               'storeg' , 'Noisy bumps (III) - 4 intervals' , 'snbumpr3' , 'sym4', 5 , '{4}' ; ...
  201.               'storeg' , 'Elec. consumption - 3 intervals' , 'snelec'   , 'sym4', 5 , '{3}'   ...
  202.               };
  203.             setDEMOS(m_demo_4,mfilename,str_numwin,demoSET,0)
  204.           case 'createDEN'
  205. % Add Help for Tool.
  206. %------------------
  207. wfighelp('addHelpTool',win_tool, ...
  208. '&One-Dimensional Estimation','EDEN_GUI');
  209. % Add Help Item.
  210. %----------------
  211. wfighelp('addHelpItem',win_tool,'Available Methods','COMP_DENO_METHODS');
  212. wfighelp('addHelpItem',win_tool,'Variance Adaptive Thresholding','VARTHR');
  213. wfighelp('addHelpItem',win_tool,'Loading and Saving','EDEN_LOADSAVE');
  214. wfighelp('addHelpItem',win_tool,'Density Estimation','DENS_EST');
  215.   
  216.             lab = '&Load data for Density Estimate';
  217.             men_fix = [];
  218.             men_sto = [];
  219.             men_den = uimenu(m_files,...
  220.                          'Label',lab,'Position',1, ...
  221.                          'Callback',               ...
  222.                          [mfilename '(''load'','   ...
  223.                              str_numwin ',''denest'');'] ...
  224.                          );
  225.             men_sav = uimenu(m_files,...
  226.                          'Label','&Save Density', ...
  227.                          'Position',2,           ...
  228.                          'Enable','Off',         ...
  229.                          'Callback',             ...
  230.                          [mfilename '(''save'',' ...
  231.                              str_numwin ',''den'');'] ...
  232.                          );
  233.             numDEM = 3;
  234.             demoSET = {...
  235.               'denest' , 'ex1cusp1' , 'ex1cusp1' , 'sym4'  , 5 ; ...
  236.               'denest' , 'ex2cusp1' , 'ex2cusp1' , 'sym6'  , 5 ; ...
  237.               'denest' , 'ex1cusp2' , 'ex1cusp2' , 'sym4'  , 5 ; ...
  238.               'denest' , 'ex2cusp2' , 'ex2cusp2' , 'coif1' , 5 ; ...
  239.               'denest' , 'ex1gauss' , 'ex1gauss' , 'sym3'  , 5 ; ...
  240.               'denest' , 'ex2gauss' , 'ex2gauss' , 'sym4'  , 5   ...
  241.               };
  242.             m_demo = uimenu(m_files,'Label','&Example Analysis ','Position',3);
  243.             setDEMOS(m_demo,mfilename,str_numwin,demoSET,0);
  244.         end
  245.         % Begin waiting.
  246.         %---------------
  247.         wwaiting('msg',win_tool,'Wait ... initialization');
  248.         % General parameters initialization.
  249.         %-----------------------------------
  250.         dx = X_Spacing;
  251.         dy = Y_Spacing;
  252.         d_txt  = (Def_Btn_Height-Def_Txt_Height);
  253.         deltaY = (Def_Btn_Height+dy);
  254.         sli_hi = Def_Btn_Height*sliYProp;
  255.         sli_dy = 0.5*Def_Btn_Height*(1-sliYProp);
  256.         minimum_bin = 16;
  257.         maximun_bin = 1024;
  258.         default_bin = 256;
  259.         % String property of objects.
  260.         %----------------------------
  261.         str_pus_dec = 'Decompose';
  262.         str_chk_den = 'Overlay Estimated Function';
  263.         str_txt_bin = 'Nb bins';
  264.         str_edi_bin = sprintf('%.0f',default_bin);
  265.         % Command part of the window.
  266.         %============================
  267.         comFigProp = {'Parent',win_tool,'Unit',win_units};
  268.         % Data, Wavelet and Level parameters.
  269.         %------------------------------------
  270.         xlocINI = pos_frame0([1 3]);
  271.         ytopINI = pos_win(4)-dy;
  272.         toolPos = utanapar('create',win_tool, ...
  273.                     'xloc',xlocINI,'top',ytopINI,...
  274.                     'enable','off',      ...
  275.                     'wtype','dwt',       ...
  276.                     'deflev',NB_def_lev, ...
  277.                     'maxlev',NB_max_lev  ...
  278.                     );
  279.         pop_lev = utanapar('handles',win_tool,'lev');
  280.         % Callbacks.
  281.         %-----------
  282.         cba_sli_bin = [mfilename '(''upd_bin'',' str_numwin ',''sli'');'];
  283.         cba_edi_bin = [mfilename '(''upd_bin'',' str_numwin ',''edi'');'];
  284.         cba_pus_dec = [mfilename '(''decompose'',' str_numwin ');'];
  285.         cba_chk_den = [mfilename '(''show_lin_den'',' str_numwin ');'];
  286.         % Bins settings.
  287.         %---------------
  288.         w_bas = toolPos(3)/48;        
  289.         h_uic = Def_Btn_Height;
  290.         w_uic = 11*w_bas;
  291.         x_uic = toolPos(1);
  292.         y_uic = toolPos(2)-h_uic-2*dy;
  293.         pos_txt_bin = [x_uic, y_uic+d_txt/2, w_uic, Def_Txt_Height];
  294.         x_uic = x_uic+w_uic;
  295.         w_uic = 27*w_bas;
  296.         pos_sli_bin = [x_uic, y_uic+sli_dy, w_uic, sli_hi];
  297.         x_uic = x_uic+w_uic+4;
  298.         w_uic = 10*w_bas-4;
  299.         pos_edi_bin = [x_uic, y_uic, w_uic, h_uic];
  300.        
  301.         txt_bin = uicontrol(comFigProp{:},...
  302.                             'Style','Text',...
  303.                             'Position',pos_txt_bin,...
  304.                             'HorizontalAlignment','left',...
  305.                             'Backgroundcolor',Def_FraBkColor,...
  306.                             'String',str_txt_bin...                            
  307.                             );
  308.  
  309.         sli_bin = uicontrol(comFigProp{:},...
  310.                             'Style','Slider',...
  311.                             'Position',pos_sli_bin,...
  312.                             'Min',minimum_bin,...
  313.                             'Max',maximun_bin,...
  314.                             'Value',default_bin, ...
  315.                             'Enable','off', ...
  316.                             'Callback',cba_sli_bin ...
  317.                             );
  318.         edi_bin = uicontrol(comFigProp{:},...
  319.                             'Style','Edit',...
  320.                             'Backgroundcolor',Def_EdiBkColor,...
  321.                             'Position',pos_edi_bin,...
  322.                             'String',str_edi_bin,...
  323.                             'Enable','off',...
  324.                             'Callback',cba_edi_bin ...
  325.                             );
  326.         % Decompose pushbutton.
  327.         %----------------------
  328.         h_uic = 3*Def_Btn_Height/2;
  329.         y_uic = y_uic-h_uic-2*dy;
  330.         w_uic = pos_frame0(3)/2;
  331.         x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  332.         pos_pus_dec = [x_uic, y_uic, w_uic, h_uic];
  333.         pus_dec = uicontrol(comFigProp{:},          ...
  334.                             'Style','Pushbutton',   ...
  335.                             'Position',pos_pus_dec, ...
  336.                             'String',xlate(str_pus_dec),   ...
  337.                             'Enable','off',         ...
  338.                             'Interruptible','On',   ...
  339.                             'Callback',cba_pus_dec  ...
  340.                             );
  341.         % Thresholding tool.
  342.         %-------------------
  343.         ytopTHR = pos_pus_dec(2)-2*dy;
  344.         toolPos = utthrw1d('create',win_tool, ...
  345.                  'xloc',xlocINI,'top',ytopTHR,...
  346.                  'ydir',yLevelDir,       ...
  347.                  'levmax',NB_def_lev,    ...
  348.                  'levmaxMAX',NB_max_lev, ...
  349.                  'status','Off',         ...
  350.                  'toolOPT',estiNAME      ...
  351.                  );
  352.         % Estimated Line(s) Check.
  353.         %-------------------------
  354.         w_uic = (3*pos_frame0(3))/4;
  355.         x_uic = pos_frame0(1)+(pos_frame0(3)-w_uic)/2;
  356.         h_uic = Def_Btn_Height;
  357.         y_uic = toolPos(2)-Def_Btn_Height/2-h_uic;
  358.         pos_chk_den = [x_uic, y_uic, w_uic, h_uic];
  359.         if isequal(option,'createDEN') , vis = 'Off'; else , vis = 'On'; end  
  360.         chk_den = uicontrol(comFigProp{:},          ...
  361.                             'Style','checkbox',     ...
  362.                             'Visible',vis,          ...
  363.                             'Position',pos_chk_den, ...
  364.                             'String',str_chk_den,   ...
  365.                             'Enable','off',         ...
  366.                             'Callback',cba_chk_den  ...
  367.                             );
  368.         % Callbacks update.
  369.         %------------------
  370.         hdl_den = utthrw1d('handles',win_tool);
  371.         utanapar('set_cba_num',win_tool,[m_files;hdl_den(:)]);
  372.         pop_lev = utanapar('handles',win_tool,'lev');
  373.         tmp     = num2mstr(pop_lev );
  374.         cba_pop_lev = [mfilename '(''upd_lev'',' str_numwin ',' tmp ');'];
  375.         set(pop_lev,'Callback',cba_pop_lev);
  376.         % General graphical parameters initialization.
  377.         %--------------------------------------------
  378.         txtLRProp = {'off','bold',14};
  379.         % Axes construction parameters.
  380.         %------------------------------
  381.         NB_lev    = NB_max_lev;    % dummy
  382.         w_gra_rem = Pos_Graphic_Area(3);
  383.         h_gra_rem = Pos_Graphic_Area(4);
  384.         ecx_left  = 0.08*pos_win(3);
  385.         ecx_med   = 0.07*pos_win(3);
  386.         ecx_right = 0.06*pos_win(3);
  387.         w_axe     = (w_gra_rem-ecx_left-ecx_med-ecx_right)/2;
  388.         x_cfs     = ecx_left;
  389.         x_det     = x_cfs+w_axe+ecx_med;
  390.         ecy_up    = 0.06*pos_win(4);
  391.         ecy_mid_1 = 0.07*pos_win(4);
  392.         ecy_mid_2 = ecy_mid_1;
  393.         ecy_mid_3 = ecy_mid_1;
  394.         ecy_det   = (0.04*pos_win(4))/1.4;
  395.         ecy_down  = ecy_up;
  396.         h_min     = h_gra_rem/12;
  397.         h_max     = h_gra_rem/5;
  398.         h_axe_std = (h_min*NB_lev+h_max*(NB_max_lev-NB_lev))/NB_max_lev;
  399.         h_space   = ecy_up+ecy_mid_1+ecy_mid_2+ecy_mid_3+...
  400.                     (NB_lev-1)*ecy_det+ecy_down;
  401.         h_detail  = (h_gra_rem-2*h_axe_std-h_space)/(NB_lev+1);
  402.         y_low_ini = pos_win(4);
  403.         % Building data axes.
  404.         %--------------------
  405.         comAxeProp = {...
  406.           comFigProp{:},'Visible','off','Drawmode','fast','Box','On'};
  407.         y_low_ini = y_low_ini-h_axe_std-ecy_up;
  408.         pos_L_1   = [x_cfs y_low_ini w_axe h_axe_std];
  409.         axe_L_1   = axes(comAxeProp{:},'Position',pos_L_1);
  410.         pos_R_1   = [x_det y_low_ini w_axe h_axe_std];
  411.         axe_R_1   = axes(comAxeProp{:},'Position',pos_R_1);
  412.         y_low_ini = y_low_ini-h_axe_std-ecy_mid_1;
  413.         pos_L_2   = [x_cfs y_low_ini w_axe h_axe_std];
  414.         axe_L_2   = axes(comAxeProp{:},'Position',pos_L_2);
  415.         pos_R_2   = [x_det y_low_ini w_axe h_axe_std];
  416.         axe_R_2   = axes(comAxeProp{:},'Position',pos_R_2);
  417.         y_low_ini = y_low_ini-h_axe_std-ecy_mid_2;
  418.         % Building approximation axes on the right part.
  419.         %-----------------------------------------------
  420.         pos_app = [x_det y_low_ini w_axe h_detail];
  421.         axe_app = axes(comAxeProp{:},'Position',pos_app);
  422.         str_txt = ['a' wnsubstr(abs(NB_max_lev))];
  423.         txt_app = txtinaxe('create',str_txt,axe_app,'r',txtLRProp{:});
  424.         y_low_ini = y_low_ini-h_detail-ecy_mid_3+ecy_det;
  425.         % Building details axes on the left part.
  426.         %----------------------------------------
  427.         comAxePropMore = {...
  428.           comAxeProp{:},'XTicklabelMode','manual','XTickLabel',[]};
  429.         axe_cfs = zeros(1,NB_max_lev);
  430.         txt_cfs = zeros(1,NB_max_lev);
  431.         y_cfs   = y_low_ini;
  432.         pos_cfs = [x_cfs y_cfs w_axe h_detail];
  433.         for j = 1:NB_max_lev
  434.             k = indic_vis_lev(j);
  435.             pos_cfs(2) = pos_cfs(2)-pos_cfs(4)-ecy_det;
  436.             axe_cfs(k) = axes(comAxePropMore{:},'Position',pos_cfs);
  437.             str_txt    = ['d' wnsubstr(k)];
  438.             txt_cfs(k) = txtinaxe('create',str_txt,axe_cfs(k),'l',txtLRProp{:});
  439.             set(txt_cfs(k),'Userdata',k,'tag','');
  440.         end
  441.         utthrw1d('set',win_tool,'axes',axe_cfs);
  442.         % Building details axes on the right part.
  443.         %-----------------------------------------
  444.         axe_det = zeros(1,NB_max_lev);
  445.         txt_det = zeros(1,NB_max_lev);
  446.         y_det   = y_low_ini;
  447.         pos_det = [x_det y_det w_axe h_detail];
  448.         for j = 1:NB_max_lev
  449.             k = indic_vis_lev(j);
  450.             pos_det(2) = pos_det(2)-pos_det(4)-ecy_det;
  451.             axe_det(k) = axes(comAxePropMore{:},'Position',pos_det);
  452.             str_txt    = ['d' wnsubstr(k)];
  453.             txt_det(k) = txtinaxe('create',str_txt,axe_det(k),'r',txtLRProp{:});
  454.         end
  455.         %  Normalization.
  456.         %----------------
  457.         Pos_Graphic_Area = wfigmngr('normalize',win_tool,Pos_Graphic_Area);
  458.         drawnow
  459.         % Set default wavelet.
  460.         %---------------------
  461.         cbanapar('set',win_tool,'wav',default_wave);
  462. % Add Context Sensitive Help (CSHelp).
  463. %-------------------------------------
  464. hdl_BINS  = [txt_bin,sli_bin,edi_bin];
  465. switch option
  466. case 'createDEN' , helpName = 'EDEN_BINS';
  467. case 'createREG' , helpName = 'REG_BINS';
  468. end
  469. wfighelp('add_ContextMenu',win_tool,hdl_BINS,helpName);
  470. %-------------------------------------
  471.         % Memory blocks update.
  472.         %----------------------
  473.         wmemtool('ini',win_tool,n_membloc2,nb1_stored);
  474.         wmemtool('ini',win_tool,n_membloc1,nb2_stored);
  475.         wmemtool('ini',win_tool,n_membloc3,nb4_stored);
  476.         wmemtool('wmb',win_tool,n_membloc2,...
  477.                                 ind_status,0,        ...
  478.                                 ind_lin_den,[NaN,NaN], ...
  479.                                 ind_gra_area,Pos_Graphic_Area ...
  480.                                 );
  481.         fields = {...
  482.           'txt_bin','sli_bin','edi_bin', ...
  483.           'pus_dec','chk_den'            ...
  484.           };
  485.         values = {...
  486.            txt_bin,sli_bin,edi_bin, ...
  487.            pus_dec,chk_den          ...
  488.            };
  489.         hdl_UIC = cell2struct(values,fields,2);
  490.         hdl_MEN = [men_fix ; men_sto ; men_den ; men_sav];
  491.         fields = {...
  492.           'axe_L_1' , 'axe_R_1' , 'axe_L_2' , 'axe_R_2' ,  ...
  493.           'axe_cfs' , 'axe_det' , 'axe_app' ...
  494.           };
  495.         values = {...
  496.           axe_L_1 , axe_R_1 , axe_L_2 , axe_R_2 ,  ...
  497.           axe_cfs , axe_det , axe_app ...
  498.            };
  499.         hdl_AXE = cell2struct(values,fields,2);
  500.         hdl_TXT = [NaN  NaN  NaN  NaN  txt_cfs txt_det txt_app];
  501.         handles = struct(...
  502.             'hdl_MEN',hdl_MEN, ...
  503.             'hdl_UIC',hdl_UIC, ...
  504.             'hdl_AXE',hdl_AXE, ...
  505.             'hdl_TXT',hdl_TXT  ...
  506.             );
  507.         wfigmngr('storeValue',win_tool,['WDRE_handles'],handles);
  508.         %-----------------------------------------------------------------
  509.         % colors = struct( ...
  510.         %   'sigColor',[1 0 0],'denColor',[1 0 0],'appColor',[0 1 1], ...
  511.         %   'detColor',[0 1 0],'cfsColor',[0 1 0],'estColor',[1 1 0]  ...
  512.         %   );
  513.         %-----------------------------------------------------------------
  514.         colors = wtbutils('colors','wdre');
  515.         wfigmngr('storeValue',win_tool,['WDRE_colors'],colors);
  516.         toolATTR = struct('toolMode','','toolState','','level',[],'wname','','NBClasses',[]);
  517.         wfigmngr('storeValue',win_tool,['WDRE_toolATTR'],toolATTR);
  518.         % End waiting.
  519.         %---------------
  520.         wwaiting('off',win_tool);
  521.     case {'load','demo'}
  522.         tool_OPT = varargin{2};
  523.         switch option
  524.           case 'load'
  525.             dialName = ['Load data - '];
  526.             switch tool_OPT
  527.               case 'denest' , dialName = [dialName 'density estimation' ];
  528.               case 'fixreg' , dialName = [dialName 'fixed design'];
  529.               case 'storeg' , dialName = [dialName 'stochastic design'];
  530.             end
  531.             [filename,pathname,ok] = ...
  532.                 utguidiv('test_load',win_tool,'*.mat',dialName);
  533.             if ~ok, return; end
  534.           case 'demo'
  535.             sig_Name = deblank(varargin{3});
  536.             wav_Name = deblank(varargin{4});
  537.             lev_Anal = varargin{5};
  538.             if length(varargin)>5  & ~isempty(varargin{6})
  539.                 parDemo = varargin{6};
  540.             else
  541.                 parDemo = '';
  542.             end
  543.             filename = [sig_Name '.mat'];
  544.             pathname = utguidiv('WTB_DemoPath',filename);
  545.         end
  546.         % Loading file.
  547.         %--------------
  548.         wwaiting('msg',win_tool,'Wait ... loading');
  549.         fullName = fullfile(pathname,filename);
  550.         [fileStruct,err] = wfileinf(fullName);
  551.         if ~err
  552.             try
  553.               load(fullName,'-mat');
  554.             catch
  555.               err = 1;
  556.               msg = sprintf('File %s is not a valid file.', filename);
  557.             end
  558.         end
  559.         if ~err
  560.             % Keep only numeric values.
  561.             %--------------------------
  562.             dum = struct2cell(fileStruct);
  563.             dumClass = dum(4,:);
  564.             idxClass = find(~strcmp(dumClass,'double') & ...
  565.                        ~strcmp(dumClass,'uint8') & ...
  566.                        ~strcmp(dumClass,'sparse'));
  567.             fileStruct(idxClass) = [];
  568.             err = isempty(fileStruct);
  569.         end
  570.         if ~err
  571.             % Keep only one dim values.
  572.             %--------------------------
  573.             dum = struct2cell(fileStruct);
  574.             dumSize = dum(2,:);
  575.             dumSize = cat(1,dumSize{:});
  576.             mini    = min(dumSize,[],2);
  577.             maxi    = max(dumSize,[],2);
  578.             idxSize = find(mini~=1 | maxi<2);
  579.             fileStruct(idxSize) = [];
  580.             err = isempty(fileStruct);
  581.         end
  582.         if ~err
  583.             err = 1;
  584.             switch tool_OPT
  585.               case 'denest'
  586.                 xdata = eval(fileStruct(1).name);
  587.                 ydata = ones(size(xdata));
  588.                 err = 0;
  589.               case {'fixreg','storeg'}
  590.                 % Seek X and Y values.
  591.                 %---------------------
  592.                 dum = struct2cell(fileStruct);
  593.                 dum = lower(dum(1,:));
  594.                 idxVarSET = [1:length(dum)];
  595.                 flagX = 0;
  596.                 flagY = 0;
  597.                 idx_Xdata = find(strcmp(dum,'xdata'));
  598.                 if ~isempty(idx_Xdata)
  599.                    flagX = 1;
  600.                    idxVarSET = setdiff(idxVarSET,idx_Xdata);
  601.                 else
  602.                    idxSET = strmatch('x',dum);
  603.                    if ~isempty(idxSET)
  604.                        flagX = 1;
  605.                        idx_Xdata = idxSET(1);
  606.                        idxVarSET = setdiff(idxVarSET,idx_Xdata);
  607.                    end
  608.                 end
  609.                 idx_Ydata = find(strcmp(dum,'ydata'));
  610.                 if ~isempty(idx_Ydata)
  611.                    flagY = 1;
  612.                    idxVarSET = setdiff(idxVarSET,idx_Ydata);
  613.                 else
  614.                    idxSET = strmatch('y',dum);
  615.                    if ~isempty(idxSET)
  616.                        flagY = 1;
  617.                        idx_Ydata = idxSET(1);
  618.                        idxVarSET = setdiff(idxVarSET,idx_Ydata);
  619.                    end
  620.                 end
  621.                 if ~flagX & ~isempty(idxVarSET)
  622.                     flagX = 1;
  623.                     idx_Xdata = idxVarSET(1);
  624.                     idxVarSET(1) = [];
  625.                 end
  626.                 if ~flagY & ~isempty(idxVarSET)
  627.                     flagY = 1;
  628.                     idx_Ydata = idxVarSET(1);
  629.                     idxVarSET(1) = [];
  630.                 end
  631.                 if ~isempty(idx_Xdata)
  632.                      xdata = eval(fileStruct(idx_Xdata).name);
  633.                 end
  634.                 if ~isempty(idx_Ydata)
  635.                      ydata = eval(fileStruct(idx_Ydata).name);
  636.                 end
  637.                 fileStruct([idx_Xdata,idx_Ydata]) = [];
  638.                 if flagX & ~flagY
  639.                    flagY = 1;
  640.                    ydata = xdata;
  641.                    xdata = [1:length(ydata)];
  642.                 elseif flagY & ~flagX
  643.                    flagX = 1;
  644.                    xdata = [1:length(ydata)];
  645.                 end
  646.                 if flagX & flagY & (length(xdata)==length(ydata))
  647.                     err = 0;
  648.                 end
  649.             end
  650.         end
  651.         if err
  652.             msg = ['File not found or invalid values for variables!'];
  653.         elseif ~isreal(xdata) | ~isreal(ydata)
  654.             msg = strvcat(sprintf('File %s doesn''t contain real data.', filename),' ');
  655.             err = 1;                     
  656.         end
  657.         if err
  658.             wwaiting('off',win_tool);
  659.             errordlg(msg,'Load ERROR','modal');
  660.             return            
  661.         end
  662.         
  663.         [sig_Name,ext] = strtok(filename,'.');
  664.         sig_Size = length(xdata);
  665.         xbounds  = [min(xdata),max(xdata)];
  666.         % Begin waiting.
  667.         %---------------
  668.         wwaiting('msg',win_tool,'Wait ... cleaning');
  669.         % Tool Settings.
  670.         %---------------
  671.         levm   = wmaxlev(sig_Size,'haar');
  672.         levmax = min(levm,NB_max_lev);
  673.         if isequal(option,'demo')
  674.             anaPar = {'wav',wav_Name};
  675.         else
  676.             wav_Name = cbanapar('get',win_tool,'wav');
  677.             lev_Anal = NB_def_lev;
  678.             anaPar = {};
  679.         end
  680.         strlev = int2str([1:levmax]');
  681.         anaPar = {anaPar{:},'n_s',{sig_Name,sig_Size}, ...
  682.                   'lev',{'String',strlev,'Value',lev_Anal}};
  683.         defaultBIN = min([def_DefBIN,fix(sig_Size/4)]);
  684.         minBIN     = min([def_MinBIN,defaultBIN]);            
  685.         maxBIN     = sig_Size;     
  686.         % Store tool settings & analysis parameters.
  687.         %------------------------------------------- 
  688.         toolATTR.toolMode  = tool_OPT;
  689.         toolATTR.toolState = 'ini';
  690.         toolATTR.level     = lev_Anal;
  691.         toolATTR.wname     = wav_Name;
  692.         toolATTR.NBClasses = defaultBIN;
  693.         wfigmngr('storeValue',win_tool,['WDRE_toolATTR'],toolATTR);
  694.         % Store analysis parameters.
  695.         %--------------------------- 
  696.         wmemtool('wmb',win_tool,n_membloc2,ind_status,0);
  697.  
  698.         wmemtool('wmb',win_tool,n_membloc1,   ...
  699.                        ind_filename,filename, ...
  700.                        ind_pathname,pathname, ...
  701.                        ind_sig_name,sig_Name, ...
  702.                        ind_xdata,xdata, ...
  703.                        ind_ydata,ydata, ...
  704.                        ind_xbounds,xbounds ...
  705.                        );
  706.         % Clean , Set analysis & GUI values.
  707.         %-----------------------------------
  708.         dynvtool('stop',win_tool)
  709.         utthrset('stop',win_tool);
  710.         wdretool('clean',win_tool,option);
  711.         cbanapar('set',win_tool,anaPar{:});
  712.         % Set bins.
  713.         %-----------
  714.         set(sli_bin,'Min',minBIN,'Value',defaultBIN,'Max',maxBIN)
  715.         set(edi_bin,'String',int2str(defaultBIN));
  716.         % Setting axes and UIC. 
  717.         %----------------------
  718.         wdretool('position',win_tool,lev_Anal);
  719.         wdretool('enable',win_tool,'ini','on');
  720.         wdretool('set_axes',win_tool);
  721.         % Plot.
  722.         %------
  723.         color   = colors.sigColor;
  724.         linProp = {...
  725.             'Parent',axe_L_1, ...
  726.             'Color',color,    ...
  727.             'LineStyle','none',...
  728.             'Marker','o',     ...
  729.             'Markersize',2,   ...
  730.             'MarkerEdgeColor',color, ...
  731.             'MarkerFaceColor',color, ...
  732.             'tag',tag_ori     ...
  733.             };
  734.         
  735.         switch tool_OPT
  736.           case 'denest'
  737.             xval = linspace(xbounds(1),xbounds(2),sig_Size);
  738.             ll = line(linProp{:},'Xdata',xval,'Ydata',xdata);
  739.             ylim = getylim(xdata);
  740.             set(axe_L_1,'Xlim',xbounds,'Ylim',ylim,'Xtick',[],'XtickLabel',[])
  741.             wtitle('Data','Parent',axe_L_1)
  742.             color  = colors.denColor;
  743.             his    = wgethist(xdata,minBIN);
  744.             wplothis(axe_L_2,his,color);
  745.             strTitle = sprintf('%d bins - Histogram',minBIN);
  746.             wtitle(strTitle,'Parent',axe_L_2)
  747.             wdretool('set_Bins',win_tool);
  748.             
  749.           case {'fixreg','storeg'}
  750.             lin_ori = line(linProp{:},'Xdata',xdata,'Ydata',ydata);
  751.             utthrw1d('set',win_tool,'handleORI',lin_ori);
  752.             ylim = getylim(ydata);
  753.             set(axe_L_1,'Ylim',ylim)          
  754.             wtitle('Data (X,Y)','Parent',axe_L_1)
  755.             if tool_OPT(1)=='s' , wdretool('set_Bins',win_tool); end
  756.         end
  757.         % Plotting Processed data.
  758.         %------------------------
  759.         wdretool('plot_Processed_Data',win_tool);
  760.         % if DEMO, analyze and estimate.
  761.         %-------------------------------
  762.         if isequal(option,'demo')
  763.             wdretool('decompose',win_tool);
  764.             if ~isempty(parDemo)
  765.                  utthrw1d('demo',win_tool,'wdre',parDemo);
  766.             end
  767.             wdretool('estimate',win_tool);
  768.             wdretool('show_lin_den',win_tool,'On')
  769.         end
  770.         cbanapar('enable',win_tool,'On');
  771.         % End waiting.
  772.         %-------------
  773.         wwaiting('off',win_tool);
  774.     case 'save'
  775.         % Testing file.
  776.         %--------------
  777.         dialName = ['Save estimated '];
  778.         switch toolMode
  779.           case {'fixreg','storeg'} , dialName = [dialName 'function'];
  780.           case 'denest' , dialName = [dialName 'denest' ];
  781.         end
  782.         [filename,pathname,ok] = utguidiv('test_save',win_tool, ...
  783.                                      '*.mat',dialName);
  784.         if ~ok, return; end
  785.         % Begin waiting.
  786.         %--------------
  787.         wwaiting('msg',win_tool,'Wait ... saving');
  788.         % Saving file.
  789.         %--------------
  790.         [name,ext] = strtok(filename,'.');
  791.         if isempty(ext) | isequal(ext,'.')
  792.             ext = '.mat'; filename = [name ext];
  793.         end
  794.         % Get de-noising parameters & de-noised signal.
  795.         %-----------------------------------------------
  796.         toolATTR = wfigmngr('getValue',win_tool,'WDRE_toolATTR');
  797.         NB_lev = toolATTR.level;
  798.         wname  = toolATTR.wname;
  799.         [thrStruct,hdl_den] = utthrw1d('get',win_tool,...
  800.                                  'thrstruct','handleTHR');
  801.         thrParams = {thrStruct(1:NB_lev).thrParams};
  802.         xdata = get(hdl_den,'Xdata');
  803.         ydata = get(hdl_den,'Ydata');
  804.         try
  805.           save([pathname filename],'xdata','ydata','thrParams','wname');
  806.         catch
  807.           errargt(mfilename,'Save FAILED !','msg');
  808.         end
  809.    
  810.         % End waiting.
  811.         %-------------
  812.         wwaiting('off',win_tool);
  813.     case 'decompose'
  814.     
  815.         % Compute decomposition and plot.
  816.         %--------------------------------
  817.         wwaiting('msg',win_tool,'Wait ... computing');
  818.         % Clean HDLG.
  819.         %---------------
  820.         utthrw1d('clean_thr',win_tool);
  821.         wdretool('show_lin_den',win_tool,'off')
  822.         % Get analyzis parameters.
  823.         %-------------------------
  824.         [wname,NB_lev] = cbanapar('get',win_tool,'wav','lev');
  825.         NBClasses = round(get(sli_bin,'Value'));
  826.         % Tool Settings.
  827.         %---------------
  828.         toolATTR.toolState = 'dec';
  829.         toolATTR.level     = NB_lev;
  830.         toolATTR.wname     = wname;
  831.         toolATTR.NBClasses = NBClasses;
  832.         wfigmngr('storeValue',win_tool,['WDRE_toolATTR'],toolATTR);
  833.         % Get Handles.
  834.         %-------------
  835.         indic_vis_lev = getLevels(NB_lev,yLevelDir);
  836.         % Clean axes
  837.         %------------
  838.         axes2clean = [axe_R_2,axe_cfs,axe_det,axe_app];
  839.         obj2del = findobj(axes2clean,'type','line');
  840.         delete(obj2del)
  841.         % Get X bounds values.
  842.         %---------------------
  843.         xbounds = wmemtool('rmb',win_tool,n_membloc1,ind_xbounds);        
  844.         xmin = xbounds(1);  xmax = xbounds(2);
  845.         % Compute.
  846.         %---------
  847.         sig_pro = wmemtool('rmb',win_tool,n_membloc3,ind_sig);
  848.         [coefs,longs] = wavedec(sig_pro,NB_lev,wname);
  849.         [det,app] = getFullDecTec(coefs,longs,wname,NB_lev);
  850.         wmemtool('wmb',win_tool,n_membloc3, ...
  851.                        ind_coefs,coefs, ...
  852.                        ind_longs,longs ...
  853.                        );
  854.         % Initializing by level threshold.
  855.         %---------------------------------
  856.         maxTHR = zeros(1,NB_lev);
  857.         for k = 1:NB_lev
  858.             maxTHR(k) = max(abs(detcoef(coefs,longs,k)));
  859.         end
  860.         valTHR = wdretool('compute_LVL_THR',win_tool);
  861.         valTHR = min(valTHR,maxTHR);
  862.         % Plotting Coefficients.
  863.         %-----------------------
  864.         hdl_lines = NaN*ones(NB_max_lev,1);
  865.         color = colors.cfsColor;
  866.         len   = longs(end);
  867.         viewSTEMS = 1;
  868.         if viewSTEMS 
  869.            dummy =  wfilters(wname);
  870.            lf = length(dummy);
  871.         end
  872.         x_cfs = linspace(xbounds(1),xbounds(2),len);
  873.         for j = 1:NB_lev
  874.             k       = indic_vis_lev(j);
  875.             axe_act = axe_cfs(k);
  876.             axes(axe_act);            
  877.             cfs = detcoef(coefs,longs,k);
  878.             tag = ['cfs_' int2str(k)];
  879.             ybounds = [-valTHR(k) , valTHR(k) , -maxTHR(k) , maxTHR(k)];            
  880.             if ~viewSTEMS
  881.                 cfs = cfs(ones(1,2^k),:);
  882.                 cfs = wkeep1(cfs(:)',len);                
  883.                 hdl_lines(k) = plotline(axe_act,x_cfs,cfs,color,tag,ybounds);
  884.             else
  885.                 ld = length(cfs);
  886.                 xd = coefsLOC([1:ld],k,lf,len);                
  887.                 x_tmp = x_cfs(xd);               
  888.                 hh = plotstem(axe_act,x_tmp,cfs,color,1,tag,ybounds);
  889.                 hdl_lines(k) = hh(3);
  890.             end
  891.             utthrw1d('plot_dec',win_tool,k,{maxTHR(k),valTHR(k),xmin,xmax,k});
  892.         end
  893.         i_axe_cfs_max = indic_vis_lev(NB_lev);
  894.         xt = get(axe_app,{'Xtick','XtickLabel'});
  895.         set([axe_det,axe_cfs],'Xtick',[],'XtickLabel',[]);
  896.         set([axe_cfs(i_axe_cfs_max),axe_det(i_axe_cfs_max)], ...
  897.            'Xtick',xt{1},'XtickLabel',xt{2}, ...
  898.            'XtickMode','auto','XTickLabelMode','auto' ...
  899.            );
  900.         set(axe_hdl,'Xlim',[xmin xmax])
  901.         set(txt_hdl(end),'String',['a' wnsubstr(abs(NB_lev))]);
  902.   
  903.         % Dynvtool Attachement.
  904.         %---------------------
  905.         if ~isequal(toolMode,'denest')
  906.            axe_IND = []; axe_CMD = axe_hdl;       
  907.         else
  908.            axe_IND = axe_hdl(1); axe_CMD = axe_hdl(2:end);
  909.         end
  910.         dynvtool('init',win_tool,axe_IND,axe_CMD,[],[1 0],'','','')
  911.         % Initialization of Denoising structure.
  912.         %---------------------------------------
  913.         utthrw1d('set',win_tool,...
  914.                        'thrstruct',{xmin,xmax,valTHR,hdl_lines},...
  915.                        'intdepthr',[]);
  916.         % Enabling HDLG.
  917.         %---------------
  918.         wdretool('enable',win_tool,'dec','on');
  919.         % Setting prog status.
  920.         %----------------------
  921.         wmemtool('wmb',win_tool,n_membloc2,ind_status,1);
  922.         % End waiting.
  923.         %-------------
  924.         wwaiting('off',win_tool);
  925.     case 'estimate'
  926.         % Compute decomposition and plot.
  927.         %--------------------------------
  928.         wwaiting('msg',win_tool,'Wait ... computing');
  929.         % Diseable De-noising Tool.
  930.         %---------------------------
  931.         utthrw1d('enable',win_tool,'off');
  932.         % Read Tool Memory Block.
  933.         %-----------------------
  934.         [coefs,longs] = wmemtool('rmb',win_tool,n_membloc3,ind_coefs,ind_longs);
  935.         NB_lev    = toolATTR.level;
  936.         wname     = toolATTR.wname;
  937.         NBClasses = toolATTR.NBClasses;
  938.         indic_vis_lev = getLevels(NB_lev,yLevelDir);
  939.         % De-noising & Plot de-noised signal.
  940.         %------------------------------------
  941.         cden = utthrw1d('den_M2',win_tool,coefs,longs);
  942.         xbounds = wmemtool('rmb',win_tool,n_membloc1,ind_xbounds);
  943.         xmin = xbounds(1); xmax = xbounds(2);
  944.         xval = linspace(xmin,xmax,NBClasses);
  945.         [det,app,sig_est] = getFullDecTec(cden,longs,wname,NB_lev);
  946.         % Reset dynvtool.
  947.         %----------------
  948.         dynvtool('get',win_tool,0,'force');
  949.         % Plotting details.
  950.         %------------------
  951.         color = colors.detColor;
  952.         for j = 1:NB_lev
  953.             k   = indic_vis_lev(j);
  954.             tag = ['det_' int2str(k)];
  955.             ll  = plotline(axe_det(k),xval,det(k,:),color,tag);
  956.         end
  957.         % Plotting approximation.
  958.         %------------------------
  959.         color = colors.appColor;
  960.         plotline(axe_app,xval,app,color,tag_app);
  961.         set(txt_hdl(end),'String',['a' wnsubstr(abs(NB_lev))]);
  962.         % Plotting Estimation.
  963.         %---------------------
  964.         color = colors.estColor;
  965.         if ~isequal(toolMode,'denest')
  966.             lin_den = wmemtool('rmb',win_tool,n_membloc2,ind_lin_den);
  967.             set(lin_den,'Ydata',sig_est);
  968.         else
  969.             xdata = wmemtool('rmb',win_tool,n_membloc1,ind_xdata);
  970.         end
  971.         lin_den = plotline(axe_R_2,xval,sig_est,color,tag_est);
  972.         i_axe_cfs_max = indic_vis_lev(NB_lev);
  973.         xt = get(axe_app,{'Xtick','XtickLabel'});
  974.         set([axe_det,axe_cfs],'Xtick',[],'XtickLabel',[]);
  975.         set([axe_cfs(i_axe_cfs_max),axe_det(i_axe_cfs_max)], ...
  976.            'Xtick',xt{1},'XtickLabel',xt{2}, ...
  977.            'XtickMode','auto','XTickLabelMode','auto' ...
  978.            );
  979.         % Dynvtool Attachement.
  980.         %---------------------
  981.         if ~isequal(toolMode,'denest')
  982.            axe_IND = []; axe_CMD = axe_hdl;       
  983.         else
  984.            axe_IND = axe_hdl(1); axe_CMD = axe_hdl(2:end);
  985.         end
  986.         dynvtool('init',win_tool,axe_IND,axe_CMD,[],[1 0],'','','')
  987.         % Enabling HDLG.
  988.         %---------------
  989.         utthrw1d('set',win_tool,'handleTHR',lin_den);
  990.         utthrw1d('enable',win_tool,'on');
  991.         wdretool('enable',win_tool,'den','on');
  992.         % Storing tool State.
  993.         %--------------------
  994.         toolATTR.toolState = 'den';
  995.         wfigmngr('storeValue',win_tool,['WDRE_toolATTR'],toolATTR);
  996.         
  997.         % End waiting.
  998.         %-------------
  999.         wwaiting('off',win_tool);
  1000.     case 'show_lin_den'
  1001.         if isequal(toolMode,'denest') , return; end
  1002.         lin_den = wmemtool('rmb',win_tool,n_membloc2,ind_lin_den);
  1003.         ok = ishandle(lin_den(1));
  1004.         if length(varargin)>1
  1005.             vis = lower(varargin{2});
  1006.             if isequal(vis,'on') & ok , val = 1; else , val = 0; end 
  1007.             set(chk_den,'value',val);
  1008.         else
  1009.             vis = deblank(getonoff(get(chk_den,'value')));
  1010.             if ~ok , set(chk_den,'value',0); end
  1011.         end
  1012.         
  1013.         if ok
  1014.             if isequal(vis,'on')
  1015.                 strTitle1 = ['Data (X,Y) and Estimate Y = f(X)'];
  1016.                 strTitle2 = ['Processed Data (X,Y) and Estimate Y = f(X)'];
  1017.             end
  1018.             set(lin_den,'Visible',vis);
  1019.         end
  1020.         wtitle('Data (X,Y)','Parent',axe_L_1)
  1021.         wtitle('Processed Data (X,Y)','Parent',axe_R_1)
  1022.     case 'position'
  1023.         NB_lev  = varargin{2};
  1024.         set(chk_den,'Visible','off');
  1025.         pos_old = utthrw1d('get',win_tool,'position');
  1026.         utthrw1d('set',win_tool,'position',{1,NB_lev})
  1027.         pos_new = utthrw1d('get',win_tool,'position');
  1028.         ytrans  = pos_new(2)-pos_old(2);
  1029.         pos_chk = get(chk_den,'Position');
  1030.         pos_chk(2) = pos_chk(2)+ytrans;
  1031.         switch toolMode
  1032.           case 'denest' , vis_chk = 'off';
  1033.           otherwise ,     vis_chk = 'on';
  1034.         end
  1035.         set(chk_den,'Position',pos_chk,'Visible',vis_chk);
  1036.     case 'upd_lev'
  1037.         pop_lev = varargin{2};
  1038.         lev_New = get(pop_lev,'value');
  1039.         wdretool('position',win_tool,lev_New);
  1040.         wdretool('set_axes',win_tool);
  1041.         lev_Anal = toolATTR.level;
  1042.         flagView = 2;
  1043.         if isequal(lev_New,lev_Anal)
  1044.             state =  toolATTR.toolState;
  1045.             switch state
  1046.                 case 'ini' ,
  1047.                     flagView = 1;
  1048.                     wdretool('enable',win_tool,'ini');
  1049.                 case 'dec' , 
  1050.                     wdretool('enable',win_tool,'dec');
  1051.                 case 'den' ,
  1052.                     val = get(chk_den,'Value');
  1053.                     wdretool('enable',win_tool,'dec','on');
  1054.                     wdretool('enable',win_tool,'den','on');
  1055.                     set(chk_den,'Value',val);
  1056.             end
  1057.         else
  1058.             flagView = 0;
  1059.             wdretool('enable',win_tool,'ini');
  1060.         end
  1061.         if flagView<2
  1062.             wdretool('show_lin_den',win_tool,'off')
  1063.             axe_off = [axe_R_2,axe_app,axe_det];
  1064.             axe_off = axe_off(ishandle(axe_off));
  1065.             lin_Off = findobj(axe_off,'type','line');
  1066.             set(lin_Off,'Visible','off');
  1067.         end
  1068.     case 'upd_bin'
  1069.         typ_upd = varargin{2};
  1070.         switch typ_upd
  1071.           case 'sli'
  1072.             nbOld = round(wstr2num(get(edi_bin,'String')));
  1073.             nbNew = round(get(sli_bin,'Value'));
  1074.           case 'edi'
  1075.             sliVal = get(sli_bin,{'Min','Value','Max'});
  1076.             minNb = sliVal{1};
  1077.             nbOld = sliVal{2};
  1078.             maxNb = sliVal{3};
  1079.             nbNew = round(wstr2num(get(edi_bin,'String')));
  1080.             if isempty(nbNew) | (nbNew<minNb) | (nbNew>maxNb)
  1081.                nbNew = nbOld;
  1082.             end
  1083.         end
  1084.         set(edi_bin,'String',int2str(nbNew));
  1085.         set(sli_bin,'Value',nbNew)
  1086.         if isequal(nbNew,nbOld) , return; end
  1087.         wdretool('clean',win_tool,'bin');
  1088.     case 'compute_LVL_THR'
  1089.         [numMeth,meth,alfa,sorh] = utthrw1d('get_LVL_par',win_tool);
  1090.         [coefs,longs] = wmemtool('rmb',win_tool,n_membloc3,ind_coefs,ind_longs);
  1091.         switch toolMode
  1092.           case 'denest'
  1093.             varargout{1}  = wthrmngr('dw1ddenoDEN',meth,coefs,longs,alfa); 
  1094.           case {'fixreg','storeg'}
  1095.             varargout{1}  = wthrmngr('dw1ddenoLVL',meth,coefs,longs,alfa);
  1096.         end
  1097.     case 'update_LVL_meth'
  1098.         wdretool('clear_GRAPHICS',win_tool);
  1099.         valTHR = wdretool('compute_LVL_THR',win_tool);
  1100.         utthrw1d('update_LVL_meth',win_tool,valTHR);
  1101.  
  1102.     case 'clear_GRAPHICS'
  1103.         status = wmemtool('rmb',win_tool,n_membloc2,ind_status);
  1104.         if status<1 , return; end
  1105.         wdretool('enable',win_tool,'den','off');
  1106.         wdretool('show_lin_den',win_tool,'off')
  1107.         axe_off = [axe_R_2,axe_app,axe_det];
  1108.         axe_off = axe_off(ishandle(axe_off));
  1109.         lin_Off = findobj(axe_off,'type','line');
  1110.         set(lin_Off,'Visible','off');
  1111.     case 'enable'
  1112.         type = varargin{2};
  1113.         if length(varargin)>2 , enaVal = varargin{3}; else , enaVal = 'on'; end
  1114.         switch type
  1115.           case 'ini'
  1116.             set([men_sav;chk_den],'Enable','off');
  1117.             utthrw1d('status',win_tool,'off');
  1118.             set([pus_dec;sli_bin;edi_bin],'Enable','on');
  1119.           case 'dec'
  1120.             NB_lev = toolATTR.level;
  1121.             set(chk_den,'Value',0);
  1122.             set([men_sav;chk_den],'Enable','off');
  1123.             utthrw1d('status',win_tool,'on');
  1124.             utthrw1d('enable',win_tool,'on');
  1125.             utthrw1d('enable',win_tool,enaVal,[1:NB_lev]);
  1126.           case 'den'
  1127.             set([men_sav;chk_den],'Enable',enaVal);
  1128.             utthrw1d('enable_tog_res',win_tool,enaVal);
  1129.             if strncmpi(enaVal,'on',2) , status = 1; else , status = 0; end
  1130.             wmemtool('wmb',win_tool,n_membloc2,ind_status,status);
  1131.         end
  1132.     case 'clean'
  1133.         calling_opt = varargin{2};        
  1134.         wdretool('show_lin_den',win_tool,'off')
  1135.         lin_den = wmemtool('rmb',win_tool,n_membloc2,ind_lin_den);
  1136.         lin_den = lin_den(ishandle(lin_den));
  1137.         delete(lin_den);
  1138.         wmemtool('wmb',win_tool,n_membloc2,ind_lin_den,[NaN,NaN]); 
  1139.         switch calling_opt
  1140.           case {'load','demo'}
  1141.             obj2del = [findobj(axe_hdl,'type','line'); ...
  1142.                        findobj(axe_hdl,'type','patch')];
  1143.             delete(obj2del)
  1144.             switch toolMode
  1145.               case 'fixreg'
  1146.                 win_title = 'Regression Estimation 1-D - Fixed Design';
  1147.                 set(win_tool,'Name',win_title);
  1148.               case 'storeg'
  1149.                 win_title = 'Regression Estimation 1-D - Stochastic Design';
  1150.                 set(win_tool,'Name',win_title);
  1151.             end
  1152.             sig_name = wmemtool('rmb',win_tool,n_membloc1,ind_sig_name);
  1153.             cbanapar('set',win_tool,'nam',sig_name);
  1154.             utthrw1d('clean_thr',win_tool);
  1155.           case 'bin'
  1156.             switch toolMode
  1157.               case 'denest'  , axetoClean = axe_hdl([2,4:end]);
  1158.               case {'fixreg','storeg'} , axetoClean = axe_hdl(2:end);
  1159.             end
  1160.             obj2del = [findobj(axetoClean,'type','line'); ...
  1161.                        findobj(axetoClean,'type','patch')];
  1162.             delete(obj2del)
  1163.             wdretool('set_Bins',win_tool);
  1164.             wdretool('plot_Processed_Data',win_tool);
  1165.             wdretool('enable',win_tool,'ini');
  1166.         end
  1167.     case 'set_Bins'
  1168.         xdata  = wmemtool('rmb',win_tool,n_membloc1,ind_xdata);
  1169.         nbBINS = get(sli_bin,'Value');
  1170.         toolATTR.NBClasses = nbBINS;
  1171.         wfigmngr('storeValue',win_tool,['WDRE_toolATTR'],toolATTR);
  1172.         switch toolMode
  1173.           case 'denest'
  1174.             color  = colors.denColor;
  1175.             his    = wgethist(xdata,nbBINS);
  1176.             wplothis(axe_R_1,his,color);
  1177.             wtitle('Binned Data','Parent',axe_R_1)
  1178.           case 'fixreg'
  1179.           case 'storeg'
  1180.             color  = colors.denColor;
  1181.             his    = wgethist(xdata,nbBINS);
  1182.             wplothis(axe_L_2,his,color);
  1183.             wtitle('Histogram of X','Parent',axe_L_2)
  1184.         end
  1185.     case 'plot_Processed_Data'
  1186.         [xdata,ydata] = wmemtool('rmb',win_tool,n_membloc1, ...
  1187.                                        ind_xdata,ind_ydata);
  1188.         [sig_pro,xval] = wedenreg(toolATTR,xdata,ydata);
  1189.         wmemtool('wmb',win_tool,n_membloc3,ind_sig,sig_pro);
  1190.    
  1191.         % Plotting Processed data & initial Estimation(s).
  1192.         %-------------------------------------------------        
  1193.         switch toolMode
  1194.           case {'fixreg','storeg'}
  1195.             color = colors.sigColor;
  1196.             lin_processed = plotline(axe_R_1,xval,sig_pro,color,tag_dat);            
  1197.             color = colors.estColor;
  1198.             lin_den = wmemtool('rmb',win_tool,n_membloc2,ind_lin_den);
  1199.             lin_den(1) = plotline(axe_L_1,xval,sig_pro,color,'');
  1200.             lin_den(2) = plotline(axe_R_1,xval,sig_pro,color,'');
  1201.             set(lin_den(1:2),'Visible','Off');
  1202.             ylim = getylim(ydata);
  1203.             set(axe_L_1,'Ylim',ylim);
  1204.             wmemtool('wmb',win_tool,n_membloc2,ind_lin_den,lin_den);
  1205.             hdl_est = plotline(axe_R_2,xval,sig_pro,color,tag_est);
  1206.             set(hdl_est,'Visible','Off');
  1207.             set(axe_hdl,'Xlim',[xval(1) xval(end)]);
  1208.           case {'denest'}
  1209.  
  1210.         end
  1211.     case 'set_axes'
  1212.         %*************************************************************%
  1213.         %** OPTION = 'set_axes' - Set axes positions and visibility **%
  1214.         %*************************************************************%
  1215.         if strcmp(toolMode,'nul') , return; end
  1216.         Pos_Graphic_Area = wmemtool('rmb',win_tool,n_membloc2,ind_gra_area);
  1217.         
  1218.         % Hide axes
  1219.         %-----------
  1220.         if ~isequal(toolMode,'denest')
  1221.             lin_den = wmemtool('rmb',win_tool,n_membloc2,ind_lin_den);
  1222.             if ishandle(lin_den(1)) , vis_den = get(lin_den(1),'Visible'); end
  1223.         end
  1224.         obj_in_axes = findobj(axe_hdl);
  1225.         set(obj_in_axes,'Visible','off');
  1226.         % Parameters initialization.
  1227.         %---------------------------
  1228.         NB_lev = cbanapar('get',win_tool,'lev');
  1229.         indic_vis_lev = getLevels(NB_lev,yLevelDir);
  1230.  
  1231.         % General graphical parameters initialization.
  1232.         %---------------------------------------------
  1233.         pos_win   = get(win_tool,'Position');
  1234.         ecy_up    = 0.06*pos_win(4);
  1235.         ecy_mid_1 = 0.07*pos_win(4);
  1236.         ecy_mid_2 = ecy_mid_1;
  1237.         ecy_mid_3 = ecy_mid_1;
  1238.         ecy_det   = (0.04*pos_win(4))/1.4;
  1239.         ecy_down  = ecy_up;
  1240.         h_gra_rem = Pos_Graphic_Area(4);
  1241.         h_min     = h_gra_rem/12;
  1242.         h_max     = h_gra_rem/5;
  1243.         h_axe_std = (h_min*NB_lev+h_max*(NB_max_lev-NB_lev))/NB_max_lev;
  1244.         h_space   = ecy_up+ecy_mid_1+ecy_mid_2+ecy_mid_3+...
  1245.                     (NB_lev-1)*ecy_det+ecy_down;
  1246.         h_detail  = (h_gra_rem-2*h_axe_std-h_space)/(NB_lev+1);
  1247.         y_low_ini = 1;
  1248.         % Building data axes.
  1249.         %--------------------
  1250.         y_low_ini = y_low_ini-h_axe_std-ecy_up;
  1251.         pos_L_1 = get(axe_L_1,'Position');
  1252.         pos_L_1([2 4]) = [y_low_ini h_axe_std];
  1253.         set(axe_L_1,'Position',pos_L_1);
  1254.         pos_R_1 = get(axe_R_1,'Position');
  1255.         pos_R_1([2 4]) = [y_low_ini h_axe_std];
  1256.         set(axe_R_1,'Position',pos_R_1);
  1257.         axe_vis = [axe_L_1,axe_R_1];
  1258.         
  1259.         y_low_ini = y_low_ini-h_axe_std-ecy_mid_1;
  1260.         pos_L_2  = get(axe_L_2,'Position');
  1261.         pos_L_2([2 4]) = [y_low_ini h_axe_std];
  1262.         set(axe_L_2,'Position',pos_L_2)
  1263.         pos_R_2  = get(axe_R_2,'Position');
  1264.         pos_R_2([2 4]) = [y_low_ini h_axe_std];
  1265.         set(axe_R_2,'Position',pos_R_2)
  1266.         switch toolMode
  1267.           case 'denest' , axe_vis = [axe_vis,axe_L_2,axe_R_2];
  1268.           case 'fixreg' , axe_vis = [axe_vis,axe_R_2];
  1269.           case 'storeg' , axe_vis = [axe_vis,axe_L_2,axe_R_2];
  1270.         end
  1271.         % Position for approximation axes on the right part.
  1272.         %---------------------------------------------------
  1273.         y_low_ini = y_low_ini-h_detail-ecy_mid_2;
  1274.         pos_axes = pos_R_2;
  1275.         pos_y   = [y_low_ini , h_detail];
  1276.         pos_axes([2 4]) = pos_y;
  1277.         set(axe_app,'Position',pos_axes);
  1278.         axe_vis = [axe_vis,axe_app];
  1279.         y_low_ini = y_low_ini-ecy_mid_3+ecy_det;
  1280.         % Position for details axes on the left part.
  1281.         %--------------------------------------------          
  1282.         pos_y  = [y_low_ini , h_detail];
  1283.         for j = 1:NB_lev
  1284.             i_axe    = indic_vis_lev(j);
  1285.             axe_act  = axe_cfs(i_axe);
  1286.             pos_axes = get(axe_act,'Position');
  1287.             pos_y(1) = pos_y(1)-h_detail-ecy_det;
  1288.             pos_axes([2 4]) = pos_y;
  1289.             set(axe_act,'Position',pos_axes);
  1290.             axe_vis = [axe_vis axe_act];
  1291.         end
  1292.         i_axe_cfs_min = indic_vis_lev(1);
  1293.         i_axe_cfs_max = indic_vis_lev(NB_lev);
  1294.         % Position for details axes on the right part.
  1295.         %---------------------------------------------
  1296.         pos_y   = [y_low_ini , h_detail];
  1297.         for j = 1:NB_lev
  1298.             i_axe    = indic_vis_lev(j);
  1299.             axe_act  = axe_det(i_axe);
  1300.             pos_axes = get(axe_act,'Position');
  1301.             pos_y(1) = pos_y(1)-h_detail-ecy_det;
  1302.             pos_axes([2 4]) = pos_y;
  1303.             set(axe_act,'Position',pos_axes);
  1304.             axe_vis  = [axe_vis axe_act];
  1305.         end
  1306.         i_axe_det_min = indic_vis_lev(1);
  1307.         % Modification of app_text.
  1308.         %--------------------------
  1309.         status = wmemtool('rmb',win_tool,n_membloc2,ind_status);
  1310.         if status==0
  1311.             txt_app = txt_hdl(end);
  1312.             num_app = NB_lev;
  1313.             set(txt_app,'string',['a' wnsubstr(abs(num_app))]);
  1314.         end
  1315.         % Set axes.
  1316.         %-----------
  1317.         xt = get(axe_L_1,{'Xtick','XtickLabel'});
  1318.         ind_axe_cfs = [i_axe_cfs_min:i_axe_cfs_max-1];
  1319.         set(axe_cfs(ind_axe_cfs),'Xtick',[],'XtickLabel',[]);
  1320.         set([axe_cfs(i_axe_cfs_max),axe_det(i_axe_cfs_max)], ...
  1321.             'Xtick',xt{1},'XtickLabel',xt{2} , ...
  1322.             'XtickMode','auto','XTickLabelMode','auto' ...
  1323.             )
  1324.         titles = get([axe_cfs;axe_det],'title');
  1325.         titles = cat(1,titles{:});
  1326.         set(titles,'String','');
  1327.         obj_in_axes_vis = findobj(axe_vis);
  1328.         set(obj_in_axes_vis,'Visible','on');
  1329.         if ~isequal(toolMode,'denest')
  1330.             if ishandle(lin_den(1)) , set(lin_den,'Visible',vis_den); end
  1331.         end
  1332.        %  hdl_den = utthrw1d('get',win_tool,'handleTHR')
  1333.        %  set(hdl_den,'color','g')
  1334.         
  1335.         % Setting axes title
  1336.         %--------------------
  1337.         switch toolMode
  1338.           case 'fixreg'
  1339.             wtitle('Data (X,Y)','Parent',axe_L_1);
  1340.             wtitle('Regression Estimate Y = f(X)','Parent',axe_R_2);
  1341.           case 'storeg'
  1342.             wtitle('Data (X,Y)','Parent',axe_L_1)
  1343.             wtitle('Histogram of X','Parent',axe_L_2);
  1344.             wtitle('Regression Estimate Y = f(X)','Parent',axe_R_2);
  1345.             wtitle('Processed Data (X,Y)','Parent',axe_R_1);
  1346.           case 'denest'
  1347.             wtitle('Data','Parent',axe_L_1);
  1348.             wtitle(sprintf('%d bins - Histogram',def_MinBIN),'Parent',axe_L_2);
  1349.             wtitle('Binned Data','Parent',axe_R_1);
  1350.             wtitle('Density Estimate','Parent',axe_R_2);
  1351.         end
  1352.         wtitle('Details coefficients','Parent',axe_cfs(i_axe_cfs_min));
  1353.         wtitle('Details','Parent',axe_det(i_axe_det_min));
  1354.         wtitle('Approximation','Parent',axe_app);
  1355.     case 'close'
  1356.     otherwise
  1357.         errargt(mfilename,'Unknown Option','msg');
  1358.         error('*');
  1359. end
  1360. %=============================================================================%
  1361. % INTERNAL FUNCTIONS
  1362. %=============================================================================%
  1363. function setDEMOS(m_demo,funcName,str_numwin,demoSET,sepFlag)
  1364. beg_call_str = [funcName '(''demo'',' str_numwin ','''];
  1365. [nbDEM,nbVAL] = size(demoSET);
  1366. for k=1:nbDEM
  1367.     typ = demoSET{k,1};
  1368.     nam = demoSET{k,2};
  1369.     fil = demoSET{k,3};
  1370.     wav = demoSET{k,4};
  1371.     len = length(wav);
  1372.     wavDum = [wav , blanks(4-len)];
  1373.     lev = int2str(demoSET{k,5});
  1374.     if nbVAL>5 , par = demoSET{k,6}; else , par = '[]'; end
  1375.     libel = ['with  ' wavDum '   at level ' lev '  --->  ' nam];
  1376.     action = [beg_call_str ...
  1377.               typ ''',''' fil ''',''' wav  ''',' lev ',' par ');'];
  1378.     if sepFlag & (k==1) , sep = 'on'; else , sep = 'off'; end
  1379.     uimenu(m_demo,'Label',libel,'Separator',sep,'Callback',action);
  1380. end
  1381. %-----------------------------------------------------------------------------%
  1382. function indic_vis_lev = getLevels(level,yDir)
  1383. indic_vis_lev = [1:level]';
  1384. if yDir==-1 , indic_vis_lev = flipud(indic_vis_lev); end
  1385. %-----------------------------------------------------------------------------%
  1386. function [det,app,sig] = getFullDecTec(coefs,longs,wname,level)
  1387. det  = wrmcoef('d',coefs,longs,wname,[1:level]);
  1388. app  = wrcoef('a',coefs,longs,wname,level);
  1389. if nargout<3 , return; end
  1390. sig  = waverec(coefs,longs,wname);
  1391. %-----------------------------------------------------------------------------%
  1392. function ylim = getylim(sig)
  1393. mini = min(sig);
  1394. maxi = max(sig);
  1395. dy   = maxi-mini;
  1396. tol  = sqrt(eps);
  1397. if abs(dy)<tol
  1398.     maxi = maxi+tol;
  1399.     mini = mini-tol;
  1400. end;
  1401. ylim = [mini maxi]+0.05*dy*[-1 1];
  1402. %-----------------------------------------------------------------------------%
  1403. function ll = plotline(axe,x,y,color,tag,ylimplus)
  1404. vis = get(axe,'visible');
  1405. ll = findobj(axe,'type','line','tag',tag);
  1406. if isempty(ll)
  1407.      ll = line(...
  1408.             'Parent',axe,'Xdata',x,'Ydata',y, ...
  1409.             'Color',color,'Visible',vis,'tag',tag);
  1410. else
  1411.      set(ll,'Xdata',x,'Ydata',y,'Color',color,'Visible',vis,'tag',tag);
  1412. end
  1413. if nargin<6
  1414.     ylim = getylim(y);
  1415. else
  1416.     ylim = getylim([y(:) ; ylimplus(:)]);
  1417. end
  1418. set(axe,'Ylim',ylim);
  1419. %-----------------------------------------------------------------------------%
  1420. function loc = coefsLOC(idx,lev,lf,lx)
  1421. %COEFSLOC coefficient location
  1422. up  = idx;
  1423. low = idx;
  1424. for j=1:lev
  1425.     low = 2*low+1-lf;
  1426.     up  = 2*up;
  1427. end
  1428. loc = max(1,min(lx,round((low+up)/2)));
  1429. %-----------------------------------------------------------------------------%
  1430. function h = plotstem(axe,x,y,color,flgzero,tag,ylimplus)
  1431. %PLOTSTEM Plot discrete sequence data.
  1432. vis = get(axe,'visible');
  1433. xAxeColor = get(axe,'xcolor');
  1434. q = [min(x) max(x)];
  1435. h = NaN*ones(1,4);
  1436. h(1) = line(...
  1437.               'Xdata',[q(1) q(2)],'Ydata',[0 0],...
  1438.               'Parent',axe,'color',xAxeColor ...
  1439.               );
  1440. indZ = find(abs(y)<eps);
  1441. xZ   = x(indZ);
  1442. yZ   = y(indZ);
  1443. x(indZ) = [];
  1444. y(indZ) = [];
  1445. n = length(x);
  1446. if n>0
  1447.     MSize = 3; Mtype = 'o';
  1448.     MarkerEdgeColor = color;
  1449.     MarkerFaceColor = color;
  1450.     xx = [x;x;NaN*ones(size(x))];
  1451.     yy = [zeros(1,n);y;NaN*ones(size(y))];
  1452.     h(2) = line(...
  1453.                   'Xdata',xx(:),'Ydata',yy(:),...
  1454.                   'Parent',axe,'LineStyle',...
  1455.                   '-','Color',color...
  1456.                   );
  1457.     h(3) = line(...
  1458.                   'Xdata',x,'Ydata',y,...
  1459.                   'Parent',axe,...
  1460.                   'Marker',Mtype, ...
  1461.                   'MarkerEdgeColor',MarkerEdgeColor, ...
  1462.                   'MarkerFaceColor',MarkerFaceColor, ...
  1463.                   'MarkerSize',MSize, ...
  1464.                   'LineStyle','none',...
  1465.                   'Color',color ...
  1466.                   );
  1467. end
  1468. nZ = length(xZ);
  1469. if flgzero & (nZ>0)
  1470.     MSize = 3; Mtype = 'o';
  1471.     h(4) = line(...
  1472.                   'Xdata',xZ,'Ydata',yZ,...
  1473.                   'Parent',axe,...
  1474.                   'Marker',Mtype, ...
  1475.                   'MarkerEdgeColor',xAxeColor, ...
  1476.                   'MarkerFaceColor',xAxeColor, ...
  1477.                   'MarkerSize',MSize, ...
  1478.                   'LineStyle','none',...
  1479.                   'Color',xAxeColor...
  1480.                   );
  1481. end
  1482. set(h(ishandle(h)),'Visible',vis,'tag',tag);
  1483. if nargin<7
  1484.     ylim = getylim(y);
  1485. else
  1486.     ylim = getylim([y(:) ; ylimplus(:)]);
  1487. end
  1488. set(axe,'Ylim',ylim);
  1489. %-----------------------------------------------------------------------------%
  1490. %=============================================================================%
  1491. %=============================================================================%
  1492. function [ysig,xsig,coefs,longs] = wedenreg(toolATTR,x,y)
  1493. %WEDENREG Density and Regression Estimation.
  1494. %== Initialisation ==========================================================%
  1495. toolMode  = toolATTR.toolMode;
  1496. level     = toolATTR.level;
  1497. wname     = toolATTR.wname;
  1498. NBClasses = toolATTR.NBClasses;
  1499. if nargin<3 , y = ones(size(x)); end
  1500. %============================================================================%
  1501. %== Traitement sur les couples (Xm,Ym) ======================================%
  1502. interpol = 0; % pas d'interpolation.
  1503. [sx,sy] = prepxy(toolMode,x,y,NBClasses,interpol);
  1504. ind_sx  = find(sx>0);
  1505. %============================================================================%
  1506. %============================================================================%
  1507. % Calcul de la grille en x.
  1508. %-------------------------
  1509. xmin = min(x);
  1510. xmax = max(x);
  1511. xsig = [0:NBClasses-1]/(NBClasses-1);
  1512. xsig = (xmax-xmin)*xsig+xmin;
  1513. %============================================================================%
  1514. %============================================================================%
  1515. % Normalization & Processed Data.
  1516. %-------------------------------
  1517. switch toolMode
  1518.     case {'denest'}
  1519.         ysig = sy;
  1520.         delta = xsig(2)-xsig(1);
  1521.         integ = sum(ysig)*delta;
  1522.         ysig = ysig/integ;
  1523.         
  1524.     case {'fixreg','storeg'}
  1525.         ysig = zeros(size(sx));
  1526.         ysig(ind_sx) = sy(ind_sx)./sx(ind_sx);
  1527. end
  1528. % Decomposition of processed signal.
  1529. %-----------------------------------
  1530. if nargout>2
  1531.     [coefs,longs] = wavedec(ysig,level,wname);
  1532.     varargout = {ysig,xsig,coefs,longs};
  1533. else
  1534.     varargout = {ysig,xsig};
  1535. end
  1536. %============================================================================%
  1537. % INTERNAL FUNCTIONS for WEDENREG
  1538. %============================================================================%
  1539. %----------------------------------------------------------------------------%
  1540. function [sx,sy] = prepxy(option,x,y,NBClasses,interpol)
  1541. %PREPXY Traitement des couples (X,Y)
  1542. %   
  1543. %   [sx,sy] = prepxy(option,x,y,NBClasses,interpol)
  1544. %
  1545. %   Entrees:
  1546. %       option    = 'denest','fixreg','storeg'
  1547. %       (x,y)     = couples des donnees (y==1 pour 'estidens') 
  1548. %       NBClasses = Nombre de classes de la grille sur [0,1].
  1549. %                   La grille sur l'intervalle [0,1] est:
  1550. %                   xgrid = [0.5:NBClasses-0.5]/NBClasses
  1551. %
  1552. %   Sorties:
  1553. %       sx = nombre d'element dans chaque classe.
  1554. %       sy = somme des elements de chaque classe.
  1555. %               (sy == sx pour 'denest' )
  1556. %----------------------------------------%
  1557. % On change l'intervalle.                %
  1558. % On travaille sur l'intervalle [0,1]    %
  1559. %----------------------------------------%
  1560. xmin  = min(x);
  1561. xmax  = max(x);
  1562. x     = (x-xmin)/(xmax-xmin);
  1563. I1    = find(x==1);
  1564. x(I1) = x(I1)-eps;
  1565. %----------------------------------------%
  1566. % La grille sur l'intervalle [0,1] est : %
  1567. % xf = [0.5:NBClasses-0.5]/NBClasses     %
  1568. %----------------------------------------%
  1569. ex = round(NBClasses*x+0.5); 
  1570. %----------------------------------------%
  1571. % Recherche des valeurs repetees et      %
  1572. % manquantes de ex.                      %
  1573. % Calcul des sommes des valeurs de y     %
  1574. % pour chaque ex distinct.               %
  1575. %----------------------------------------%
  1576. lx = length(ex);
  1577. sx = full(sum(sparse(1:lx,ex,1,lx,NBClasses)));
  1578. switch option
  1579.    case 'denest' , sy = sx;
  1580.    case 'fixreg' , sy = full(sum(sparse(1:lx,ex,y,lx,NBClasses)));
  1581.    case 'storeg'
  1582.      sy = full(sum(sparse(1:lx,ex,y,lx,NBClasses)));
  1583.      if nargin<5 , return; end
  1584.      % PROBLEME DES VALEURS MANQUANTES: interpol = 1;
  1585.      %----------------------------------------------
  1586.      if interpol
  1587.          % Interpolation lineaire pour les trous.
  1588.          Ind_0  = find(sx==0);
  1589.          Ind_sx = (find(sx>0))';
  1590.          for k=1:length(Ind_0)
  1591.              Ik = Ind_0(k);
  1592.              av = find(Ind_sx<Ik);
  1593.              ap = find(Ind_sx>Ik);
  1594.              Iav = Ind_sx(av(length(av)));
  1595.              Iap = Ind_sx(ap(1));
  1596.              sy(Ik) = ( (sy(Iap)*(Ik-Iav))/sx(Iap)+ ...
  1597.                         (sy(Iav)*(Iap-Ik))/sx(Iav) )/(Iap-Iav);
  1598.              sx(Ik) = 1;
  1599.          end
  1600.      end
  1601. end
  1602. %----------------------------------------------------------------------------%
  1603. %============================================================================%