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

波变换

开发平台:

Matlab

  1. function varargout = utthrwpd(option,fig,varargin)
  2. %UTTHRWPD Utilities for thresholding (Wavelet Packet De-noising).
  3. %   VARARGOUT = UTTHRWPD(OPTION,FIG,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 29-Sep-98.
  5. %   Last Revision: 25-May-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.8.4.2 $  $Date: 2004/03/15 22:42:13 $
  8. % Tag property.
  9. %--------------
  10. tag_fra_tool = ['Fra_' mfilename];
  11. switch option
  12.   case {'move','up','create'} , 
  13.   otherwise
  14.     wfigPROP = wtbxappdata('get',fig,'WfigPROP');
  15.     if ~isempty(wfigPROP)
  16.         calledFUN = wfigPROP.MakeFun;
  17.     else
  18.         calledFUN = wdumfun;    
  19.     end
  20.     if ~isequal(option,'down')
  21.         % ud.handlesUIC = ...
  22.         %    [fra_utl;txt_top;rad_sof;rad_har; ...
  23.         %     sli_sel;edi_sel;txt_bin;edi_bin; ...
  24.         %     tog_res;pus_est];
  25.         %-----------------------------
  26.         uic = findobj(get(fig,'Children'),'flat','type','uicontrol');
  27.         fra = findobj(uic,'style','frame','tag',tag_fra_tool);
  28.         if isempty(fra) , return; end
  29.         ud = get(fra,'Userdata');
  30.         toolOPT = ud.toolOPT;
  31.         handlesUIC = ud.handlesUIC;
  32.         handlesOBJ = ud.handlesOBJ;
  33.         ind = 2;
  34.         txt_top = handlesUIC(ind); ind = ind+1;
  35.         pop_met = handlesUIC(ind); ind = ind+1;
  36.         rad_sof = handlesUIC(ind); ind = ind+1;
  37.         rad_har = handlesUIC(ind); ind = ind+1;
  38.         txt_sel = handlesUIC(ind); ind = ind+1;
  39.         sli_sel = handlesUIC(ind); ind = ind+1;
  40.         edi_sel = handlesUIC(ind); ind = ind+1;
  41.         txt_bin = handlesUIC(ind); ind = ind+1;
  42.         edi_bin = handlesUIC(ind); ind = ind+1;
  43.         tog_res = handlesUIC(ind); ind = ind+1;
  44.         pus_est = handlesUIC(ind); ind = ind+1;   
  45.     end
  46. end
  47. switch option
  48.     case 'down'
  49.         % in2 = [axe_perfo ; axe_histo; ...
  50.         %        lin_perfo ; lin_perfh ; sli_sel ; edi_sel; edi_bin];
  51.         % in3 = 1  for lin_perfo and in3 = 2 for lin_perfh
  52.         %--------------------------------------------------------------
  53.         sel_type = get(fig,'SelectionType');
  54.         if strcmp(sel_type,'open') , return; end
  55.         opt = varargin{2};   
  56.         if opt==1 , axe = varargin{1}(1); else , axe = varargin{1}(2); end
  57.         if (axe~=gca) , axes(axe); end;
  58.     
  59.         % Setting the thresholded coefs axes invisible.
  60.         %----------------------------------------------
  61.         feval(calledFUN,'clear_GRAPHICS',fig);
  62.         lin_perfo = varargin{1}(3);
  63.         lin_perfh = varargin{1}(4);
  64.         set([lin_perfo lin_perfh],'Color','g');
  65.         drawnow
  66.         argCbstr = [num2mstr(fig) ',' num2mstr(varargin{1}) ...
  67.                      ',' int2str(varargin{2})];
  68.         cba_move = [mfilename '(''move'',' argCbstr ');'];
  69.         cba_up   = [mfilename '(''up'','  argCbstr ');'];
  70.         wtbxappdata('new',fig,'save_WindowButtonUpFcn',get(fig,'WindowButtonUpFcn'));
  71.         set(fig,'WindowButtonMotionFcn',cba_move,'WindowButtonUpFcn',cba_up);
  72.     case 'move'
  73.         % in2 = [axe_perfo ; axe_histo; ...
  74.         %        lin_perfo ; lin_perfh ; sli_sel ; edi_sel; edi_bin];
  75.         % in3 = 1  for lin_perfo and in3 = 2 for lin_perfh
  76.         %--------------------------------------------------------------
  77.         opt = varargin{2};   
  78.         if opt==1 , axe = varargin{1}(1); else , axe = varargin{1}(2); end
  79.         p = get(axe,'currentpoint');
  80.         new_thresh = p(1,1);
  81.         sli_sel = varargin{1}(5);
  82.         min_sli = get(sli_sel,'Min');
  83.         max_sli = get(sli_sel,'Max');
  84.         new_thresh = max(min_sli,min(new_thresh,max_sli));
  85.         xnew = [new_thresh new_thresh];
  86.         xold = get(varargin{1}(3),'Xdata');
  87.         if isequal(xold,xnew) , return; end
  88.         set(varargin{1}(3:4),'Xdata',xnew);
  89.         set(sli_sel,'value',new_thresh);
  90.         set(varargin{1}(6),'string',sprintf('%1.4g',new_thresh));
  91.     case 'up'
  92.         % in2 = [axe_perfo ; axe_histo; ...
  93.         %        lin_perfo ; lin_perfh ; sli_sel ; edi_sel; edi_bin];
  94.         %--------------------------------------------------------------
  95.         save_WindowButtonUpFcn = wtbxappdata('del',fig,'save_WindowButtonUpFcn');
  96.         set(fig,'WindowButtonMotionFcn','wtmotion',...
  97. 'WindowButtonUpFcn',save_WindowButtonUpFcn);
  98.         set(varargin{1}(3:4),'Color',wtbutils('colors','linTHR'));
  99.         drawnow;
  100.     case {'create'}
  101.         % Get Globals.
  102.         %--------------
  103.         [Def_Txt_Height,Def_Btn_Height,Def_Btn_Width,Pop_Min_Width, ...
  104.          X_Spacing,Y_Spacing,sliYProp,Def_FraBkColor,Def_EdiBkColor] = ...
  105.             mextglob('get',...
  106.                 'Def_Txt_Height','Def_Btn_Height','Def_Btn_Width',   ...
  107.                 'Pop_Min_Width','X_Spacing','Y_Spacing','Sli_YProp', ...
  108.                 'Def_FraBkColor','Def_EdiBkColor');
  109.         % Defaults.
  110.         %----------
  111.         xleft = Inf; xright  = Inf; xloc = Inf;
  112.         ytop  = Inf; ybottom = Inf; yloc = Inf;
  113.         bkColor = Def_FraBkColor;
  114.         enaVal = 'off';
  115.         visVal = 'on';
  116.         toolOPT = 'wpdeno1';
  117.         % Inputs.
  118.         %--------        
  119.         nbarg = length(varargin);
  120.         for k=1:2:nbarg
  121.             arg = lower(varargin{k});
  122.             switch arg
  123.               case 'left'     , xleft   = varargin{k+1};
  124.               case 'right'    , xright  = varargin{k+1};
  125.               case 'xloc'     , xloc    = varargin{k+1};
  126.               case 'bottom'   , ybottom = varargin{k+1};
  127.               case 'top'      , ytop    = varargin{k+1};
  128.               case 'yloc'     , yloc    = varargin{k+1};
  129.               case 'bkcolor'  , bkColor = varargin{k+1};
  130.               case 'visible'  , visVal  = varargin{k+1};
  131.               case 'toolopt'  , toolOPT = varargin{k+1};
  132.             end 
  133.         end
  134.         % Structure initialization.
  135.         %--------------------------
  136.         colHIST = wtbutils('colors','wp1d','hist');
  137.         ud = struct(...
  138.                 'toolOPT',toolOPT, ...
  139.                 'visible',lower(visVal),...
  140.                 'handlesUIC',[], ...
  141.                 'handlesOBJ',[], ...
  142.                 'handleORI',     ...
  143.                 'handleTHR',     ...                 
  144.                 'histColor',colHIST ...
  145.                 );
  146.         % Figure units.
  147.         %--------------
  148.         str_numfig = num2mstr(fig);
  149.         old_units  = get(fig,'units');
  150.         fig_units  = 'pixels';
  151.         if ~isequal(old_units,fig_units), set(fig,'units',fig_units); end       
  152.         % String property.
  153.         %-----------------
  154.         default_bins = 50;
  155.         str_txt_top = 'Select thresholding method';
  156.         str_txt_sel = 'Select Global Threshold';
  157.         str_pop_met = wthrmeth(toolOPT,'names');
  158.         str_rad_sof = 'soft';
  159.         str_rad_har = 'hard';
  160.         str_txt_bin = 'Number of bins';
  161.         str_edi_bin = sprintf('%.0f',default_bins);
  162.         str_tog_res = 'Residuals';
  163.         str_pus_est = 'De-noise';
  164.         % Positions utilities.
  165.         %---------------------
  166.         dx = X_Spacing; bdx = 3;
  167.         dy = Y_Spacing; bdy = 4;       
  168.         d_txt  = (Def_Btn_Height-Def_Txt_Height);
  169.         deltaY = (Def_Btn_Height+dy);
  170.         d_lev  = 2;
  171.         sli_hi = Def_Btn_Height*sliYProp;
  172.         sli_dy = 0.5*Def_Btn_Height*(1-sliYProp);
  173.         % Setting frame position.
  174.         %------------------------
  175.         w_fra   = wfigmngr('get',fig,'fra_width');
  176.         h_fra   = 6*Def_Btn_Height+6*bdy;              
  177.         xleft   = utposfra(xleft,xright,xloc,w_fra);
  178.         ybottom = utposfra(ybottom,ytop,yloc,h_fra);
  179.         pos_fra = [xleft,ybottom,w_fra,h_fra];
  180.         % Position property.
  181.         %-------------------
  182.         txt_width = Def_Btn_Width;
  183.         dy_lev    = Def_Btn_Height+d_lev;
  184.         xleft = xleft+bdx;
  185.         w_rem = w_fra-2*bdx;
  186.         ylow  = ybottom+h_fra-Def_Btn_Height-bdy;
  187.         w_uic       = (5*txt_width)/2;
  188.         x_uic       = xleft+(w_rem-w_uic)/2;
  189.         y_uic       = ylow;
  190.         pos_txt_top = [x_uic, y_uic+d_txt/2, w_uic, Def_Txt_Height];
  191.         y_uic       = y_uic-Def_Btn_Height;
  192.         pos_pop_met = [x_uic, y_uic, w_uic, Def_Btn_Height];
  193.         y_uic       = y_uic-Def_Btn_Height-bdy;
  194.         w_rad       = Pop_Min_Width;
  195.         w_sep       = (w_uic-2*w_rad)/3;
  196.         x_rad       = x_uic+w_sep;
  197.         pos_rad_sof = [x_rad, y_uic, w_rad, Def_Btn_Height];
  198.         x_rad       = x_rad+w_rad+w_sep;
  199.         pos_rad_har = [x_rad, y_uic, w_rad, Def_Btn_Height];
  200.         y_uic       = y_uic-Def_Btn_Height-bdy;
  201.         pos_txt_sel = [x_uic, y_uic+d_txt/2, w_uic, Def_Txt_Height];
  202.         y_uic       = y_uic-Def_Btn_Height;
  203.         wid1        = (15*w_rem)/26;
  204.         wid2        = (8*w_rem)/26;
  205.         wid3        = (2*w_rem)/26;
  206.         wx          = (w_rem-wid1-wid2)/4;
  207.         
  208.         pos_sli_sel = [xleft+wx, y_uic+sli_dy, wid1-wx, sli_hi];
  209.         x_uic       = pos_sli_sel(1)+pos_sli_sel(3)+wx;
  210.         pos_edi_sel = [x_uic, y_uic, wid2, Def_Btn_Height];
  211.         y_uic       = y_uic-Def_Btn_Height-bdy;        
  212.         pos_txt_bin = [xleft+wx, y_uic+d_txt/2, wid1-wx, Def_Txt_Height];
  213.         x_uic       = pos_txt_bin(1)+pos_txt_bin(3)+wx;
  214.         pos_edi_bin = [x_uic, y_uic, wid2, Def_Btn_Height];
  215.         w_uic = w_fra/2-bdx;
  216.         x_uic = pos_fra(1);
  217.         h_uic = (3*Def_Btn_Height)/2;
  218.         y_uic = pos_fra(2)-h_uic-Def_Btn_Height;     
  219.         pos_pus_est = [x_uic, y_uic, w_uic, h_uic];
  220.         x_uic = x_uic+w_uic+2*bdx;
  221.         pos_tog_res = [x_uic, y_uic, w_uic, h_uic];
  222.         % Create UIC.
  223.         %------------
  224.         comProp = {...
  225.            'Parent',fig,    ...
  226.            'Unit',fig_units ...
  227.            'Visible',visVal ...
  228.            };
  229.         commonTxtProp = {comProp{:}, ...
  230.             'Style','Text',...
  231.             'Backgroundcolor',Def_FraBkColor...
  232.             };        
  233.         commonEdiProp = {comProp{:}, ...
  234.             'Style','Edit',...
  235.             'String','',...
  236.             'Backgroundcolor',Def_EdiBkColor,...
  237.             'HorizontalAlignment','center'...
  238.             };        
  239.         fra_utl = uicontrol(comProp{:}, ...
  240.                             'Style','frame', ...
  241.                             'Position',pos_fra, ...
  242.                             'Backgroundcolor',bkColor, ...
  243.                             'Tag',tag_fra_tool ...
  244.                             );
  245.         txt_top = uicontrol(commonTxtProp{:},      ...
  246.                             'Position',pos_txt_top,...
  247.                             'HorizontalAlignment','center',...
  248.                             'String',str_txt_top   ...
  249.                             );
  250.         cba = [mfilename '(''update_methName'',' str_numfig ');'];
  251.         pop_met = uicontrol(comProp{:}, ...
  252.                             'Style','Popup',...
  253.                             'Position',pos_pop_met,...
  254.                             'String',str_pop_met,...
  255.                             'HorizontalAlignment','center',...
  256.                             'Userdata',1,...
  257.                             'Callback',cba ...
  258.                             );
  259.         rad_sof = uicontrol(comProp{:}, ...
  260.                             'Style','RadioButton',...
  261.                             'Position',pos_rad_sof,...
  262.                             'HorizontalAlignment','center',...
  263.                             'String',str_rad_sof,...
  264.                             'Value',1,'Userdata',1 ...
  265.                             );
  266.         rad_har = uicontrol(comProp{:}, ...
  267.                             'Style','RadioButton',...
  268.                             'Position',pos_rad_har,...
  269.                             'HorizontalAlignment','center',...
  270.                             'String',str_rad_har,...
  271.                             'Value',0,'Userdata',0 ...
  272.                             );
  273.         cba = [mfilename '(''update_thrType'',' str_numfig ');'];
  274.         set(rad_sof,'Callback',cba);
  275.         set(rad_har,'Callback',cba);
  276.         txt_sel = uicontrol(commonTxtProp{:},      ...
  277.                             'Position',pos_txt_sel,...
  278.                             'HorizontalAlignment','center',...
  279.                             'String',str_txt_sel   ...
  280.                             );
  281.         cba_sli = [mfilename '(''updateTHR'',' str_numfig ',''sli'');'];
  282.         sli_sel = uicontrol(comProp{:}, ...
  283.                             'Style','Slider',...
  284.                             'Position',pos_sli_sel,...
  285.                             'Min',0,...
  286.                             'Max',1,...
  287.                             'Value',0.5, ...
  288.                             'Callback',cba_sli ...
  289.                             );
  290.         cba_edi = [mfilename '(''updateTHR'',' str_numfig ',''edi'');'];
  291.         edi_sel = uicontrol(commonEdiProp{:}, ...
  292.                             'Position',pos_edi_sel,...
  293.                             'Callback',cba_edi ...
  294.                             );
  295.         txt_bin = uicontrol(commonTxtProp{:}, ...
  296.                             'Position',pos_txt_bin,...
  297.                             'HorizontalAlignment','left',...
  298.                             'String',str_txt_bin...
  299.                             );
  300.         cba_bin = [mfilename '(''updateBIN'',' str_numfig ',''bin'');'];
  301.         edi_bin = uicontrol(commonEdiProp{:}, ...
  302.                             'Position',pos_edi_bin,...
  303.                             'String',str_edi_bin,   ...
  304.                             'Callback',cba_bin ...
  305.                             );
  306.         cba = [mfilename '(''residuals'',' str_numfig ');'];
  307.         tip = 'More on Residuals';
  308.         tog_res = uicontrol(comProp{:},             ...
  309.                             'Style','Togglebutton', ...
  310.                             'Position',pos_tog_res, ...
  311.                             'String',str_tog_res,   ...
  312.                             'Enable','off',         ...
  313.                             'Callback',cba,         ...
  314.                             'tooltip',tip,          ...
  315.                             'Interruptible','On'    ...
  316.                             );
  317.         cba_pus_est = [mfilename '(''denoise'',' str_numfig ');'];
  318.         pus_est = uicontrol(comProp{:},             ...
  319.                             'Style','Pushbutton',   ...
  320.                             'Position',pos_pus_est, ...
  321.                             'String',xlate(str_pus_est),   ...
  322.                             'callback',cba_pus_est  ...
  323.                             );
  324. % Add Context Sensitive Help (CSHelp).
  325. %-------------------------------------
  326.         hdl_COMP_DENO_STRA = [...
  327. fra_utl,txt_top,pop_met, ...
  328. txt_sel,sli_sel,edi_sel];
  329.         hdl_DENO_SOFTHARD = [rad_sof,rad_har];
  330. wfighelp('add_ContextMenu',fig,hdl_COMP_DENO_STRA,'COMP_DENO_STRA');
  331. wfighelp('add_ContextMenu',fig,hdl_DENO_SOFTHARD,'DENO_SOFTHARD');
  332. %-------------------------------------
  333. % Store handles.
  334. %--------------
  335. ud.handlesUIC = ...
  336.             [fra_utl;txt_top;pop_met;...
  337.              rad_sof;rad_har;txt_sel;sli_sel;edi_sel;...
  338.              txt_bin;edi_bin;tog_res;pus_est];
  339.         set(fra_utl,'Userdata',ud);
  340.         if nargout>0
  341.             varargout{1} = [pos_fra(1) , pos_pus_est(2) , pos_fra([3 4])];
  342.         end
  343.     case 'displayPerf'
  344.         % Displaying perfos.
  345.         %-------------------
  346.         [pos_axe_perfo,pos_axe_histo,cfs] = deal(varargin{:});
  347.         cfs = sort(abs(cfs));
  348.         fig_units = get(fig,'units');
  349.         suggthr = get(sli_sel,'value');
  350.         nb_cfs  = length(cfs);
  351.         if nb_cfs==0
  352.             xlim = [0 1];
  353.             ylim = [0 1];
  354.         else
  355.             sigmax = cfs(end);
  356.             if abs(sigmax)<eps , sigmax = 0.01; end
  357.             xlim = [0 sigmax];
  358.             ylim = [0 nb_cfs];
  359.         end
  360.         comAxeProp = {...
  361.           'Parent',fig, ...
  362.           'Units',fig_units, ...
  363.           'Drawmode','fast', ...
  364.           'Box','On'};
  365.         colTHR = wtbutils('colors','linTHR');
  366.         axe_perfo = axes(comAxeProp{:},...
  367.                          'Position',pos_axe_perfo,...
  368.                          'Xlim',xlim,'Ylim',ylim);
  369.         % Set a text as a super title.
  370.         %-----------------------------
  371.         wtitle('Sorted absolute values of coefs','Parent',axe_perfo)
  372.         lin_thres = line('xdata',cfs,...
  373.                          'ydata',1:nb_cfs,...
  374.                          'erasemode','none',...
  375.                          'color',ud.histColor,...
  376.                          'Parent',axe_perfo);
  377.         lin_perfo = line('EraseMode','xor',...
  378.                          'xdata',[suggthr suggthr],...
  379.                          'ydata',[0       nb_cfs],...
  380.                          'Color',colTHR,...
  381.                          'linestyle',':', ...
  382.                          'Parent',axe_perfo);
  383.         setappdata(lin_perfo,'selectPointer','V')
  384.         set(axe_perfo,'Userdata',lin_perfo);
  385.         % Displaying histogram.
  386.         %----------------------
  387.         default_bins = 50;
  388.         nb_bins = wstr2num(get(edi_bin,'String'));
  389.         if isempty(nb_bins) | (nb_bins<2) , nb_bins = default_bins; end
  390.         set(edi_bin,'String',sprintf('%.0f',nb_bins));
  391.         
  392.         axe_histo = axes(comAxeProp{:},...
  393.                          'Position',pos_axe_histo,...
  394.                          'NextPlot','Replace');
  395.         his       = wgethist(cfs,nb_bins,'left');
  396.         [xx,imod] = max(his(2,:));
  397.         mode_val  = (his(1,imod)+his(1,imod+1))/2;
  398.         his(2,:)  = his(2,:)/nb_cfs;
  399.         his       = AdjustHist(his,axe_perfo);
  400.         axes(axe_histo);
  401.         wplothis(axe_histo,his,ud.histColor);
  402.         ylim      = get(axe_histo,'Ylim');
  403.         lin_perfh = line('EraseMode','xor',...
  404.                          'xdata',[suggthr suggthr],...
  405.                          'ydata',[ylim(1)+eps ylim(2)-eps],...
  406.                          'Color',colTHR,...
  407.                          'linestyle',':', ...
  408.                          'Parent',axe_histo);
  409.         setappdata(lin_perfh,'selectPointer','V')
  410.         wtitle('Histogram of absolute values of coefs','Parent',axe_histo);
  411.         handles = [axe_perfo ; axe_histo; ...
  412.                    lin_perfo ; lin_perfh ; sli_sel ; edi_sel; edi_bin];
  413.         argCbstr = [num2mstr(fig) ',' num2mstr(handles)];
  414.         cba_lin_perfo = [mfilename '(''down'',' argCbstr ',1);'];
  415.         set(lin_perfo,'ButtonDownFcn',cba_lin_perfo);
  416.         cba_lin_perfh = [mfilename '(''down'',' argCbstr ',2);'];
  417.         set(lin_perfh,'ButtonDownFcn',cba_lin_perfh);
  418.         ud.handlesOBJ.axes  = [axe_perfo ; axe_histo]; 
  419.         ud.handlesOBJ.lines = [lin_perfo ; lin_perfh; lin_thres];
  420.         set(fra,'Userdata',ud);
  421.     case 'set'
  422.         nbarg = length(varargin);
  423.         if nbarg<1 , return; end
  424.         for k = 1:2:nbarg
  425.            argType = lower(varargin{k});
  426.            argVal  = varargin{k+1};
  427.            switch argType
  428.                case 'handleori' , ud.handleORI = argVal;
  429.                case 'handlethr' , ud.handleTHR = argVal;
  430.            end
  431.         end
  432.         set(fra,'Userdata',ud);
  433.     case 'enable_tog_res'
  434.         enaVal = varargin{1};
  435.         set(tog_res,'Enable',enaVal);
  436.     case 'denoise'
  437.         feval(calledFUN,'denoise',fig);
  438.     case 'setThresh'
  439.         sliVal = varargin{1};
  440.         set(sli_sel,'Min',sliVal(1),'Value',sliVal(2),'Max',sliVal(3));
  441.         set(edi_sel,'String',sprintf('%1.4g',sliVal(2)));
  442.     case 'get_GBL_par'
  443.         numMeth = get(pop_met,'value');
  444.         meth    = wthrmeth(toolOPT,'shortnames',numMeth);
  445.         valType = get(rad_sof,'value');
  446.         if valType==1 , sorh = 's'; else , sorh = 'h'; end
  447.         valSli  = get(sli_sel,'Value');
  448.         varargout = {numMeth,meth,valSli,sorh};
  449.     case 'update_GBL_meth'
  450.         % called by : calledFUN('update_GBL_meth', ...)
  451.         %------------------------------------------------
  452.         suggthr = varargin{1};
  453.         utthrwpd('updateTHR',fig,'meth',suggthr);
  454.     case 'update_methName'
  455.         feval(calledFUN,'update_GBL_meth',fig);
  456.     case 'updateBIN'
  457.         % Check the bins number.
  458.         %-----------------------
  459.         default_bins = 50; max_bins = 500;
  460.         nb_bins = wstr2num(get(edi_bin,'String'));
  461.         if isempty(nb_bins) || (nb_bins<2)
  462.             nb_bins = default_bins;
  463.             set(edi_bin,'String',sprintf('%.0f',nb_bins));
  464.             return
  465.         elseif (nb_bins>max_bins)
  466.             nb_bins = max_bins;
  467.             set(edi_bin,'String',sprintf('%.0f',nb_bins));
  468.         end
  469.         axe_perfo = handlesOBJ.axes(1);
  470.         axe_histo = handlesOBJ.axes(2);
  471.         lin_perfh = handlesOBJ.lines(2);
  472.         lin_thres = handlesOBJ.lines(3);
  473.         thresVal  = get(lin_thres,'Xdata');
  474.         his       = wgethist(thresVal,nb_bins,'left');
  475.         his(2,:)  = his(2,:)/length(thresVal);
  476.         his       = AdjustHist(his,axe_perfo);
  477.         child = findobj(axe_histo,'parent',axe_histo);
  478.         child(child==lin_perfh) = [];
  479.         delete(child)
  480.         set(axe_histo,'nextplot','add');
  481.         wplothis(axe_histo,his,ud.histColor);
  482.         ylim = get(axe_histo,'Ylim');
  483.         set(lin_perfh,'Ydata',[ylim(1)+eps ylim(2)-eps]);
  484.         wtitle('Histogram of absolute values of coefs','Parent',axe_histo);
  485.     case 'updateTHR'
  486.         upd_orig = varargin{1};
  487.         switch upd_orig
  488.           case 'sli'
  489.             new_thresh = get(sli_sel,'value');
  490.           case 'edi'
  491.             new_thresh = wstr2num(get(edi_sel,'string'));
  492.             if isempty(new_thresh)
  493.                 new_thresh = get(sli_sel,'value');
  494.             else
  495.                 ma = get(sli_sel,'Max');
  496.                 if new_thresh>ma
  497.                     new_thresh = ma;
  498.                 else
  499.                     mi = get(sli_sel,'Min');
  500.                     if new_thresh<mi , new_thresh = mi; end
  501.                 end
  502.             end
  503.           case 'meth'
  504.             new_thresh = varargin{2};
  505.         end
  506.         set(sli_sel,'value',new_thresh);
  507.         set(edi_sel,'string',sprintf('%1.4g',new_thresh));
  508.         lin_perfo = handlesOBJ.lines(1);
  509.         lin_perfh = handlesOBJ.lines(2);
  510.         xold = get(lin_perfo,'Xdata');
  511.         xnew = [new_thresh new_thresh];
  512.         if ~isequal(xold,xnew)
  513.             set([lin_perfo lin_perfh],'Xdata',xnew);
  514.             feval(calledFUN,'clear_GRAPHICS',fig);
  515.         end
  516.     case 'update_thrType'
  517.         rad = gcbo;
  518.         old = get(rad,'userdata');
  519.         if old==1 , set(rad,'Value',1); return; end
  520.         if isequal(rad,rad_sof)
  521.            type = 's'; other = rad_har;
  522.         else
  523.            type = 'h'; other = rad_sof;           
  524.         end
  525.         set(other,'Value',0,'Userdata',0);
  526.         set(rad,'Value',1,'Userdata',1);
  527.         feval(calledFUN,'clear_GRAPHICS',fig);
  528.     case 'residuals'
  529.         wmoreres('create',fig,tog_res,[],ud.handleORI,ud.handleTHR,'blocPAR');
  530.     otherwise
  531.       errargt(mfilename,'Unknown Option','msg');
  532.       error('*');
  533. end
  534. %=============================================================================%
  535. % INTERNAL FUNCTIONS
  536. %=============================================================================%
  537. %-----------------------------------------------------------------------------%
  538. function varargout = wthrmeth(toolOPT,varargin)
  539. switch toolOPT
  540.   case {'wpdeno1'}
  541.     thrMethods = {...
  542.         'Fixed form thr. (unscaled wn)',  'sqtwologuwn',   1; ...
  543.         'Fixed form thr. (scaled wn)',    'sqtwologswn',   2; ...
  544.         'Balance sparsity-norm',          'bal_sn',        3; ...
  545.         'Penalize high',                  'penalhi',       4; ...
  546.         'Penalize medium',                'penalme',       5; ...
  547.         'Penalize low',                   'penallo',       6  ...
  548.         };
  549.   case {'wpdeno2'}
  550.     thrMethods = {...
  551.         'Fixed form thr. (unscaled wn)',  'sqtwologuwn',   1; ...
  552.         'Fixed form thr. (scaled wn)',    'sqtwologswn',   2; ...
  553.         'Bal. sparsity-norm (sqrt)',      'sqrtbal_sn',    3; ...
  554.         'Penalize high',                  'penalhi',       4; ...
  555.         'Penalize medium',                'penalme',       5; ...
  556.         'Penalize low',                   'penallo',       6  ...
  557.         };
  558. end
  559. nbin = length(varargin);
  560. if nbin==0 , varargout{1} = thrMethods; return; end
  561. option = varargin{1};
  562. switch option
  563.   case 'names'
  564.      out = strvcat(1,thrMethods{:,1});
  565.      varargout{1} = out(2:end,:);
  566.      if nbin==2
  567.          num = varargin{2};
  568.          varargout{1} = deblank(varargout{1}(num,:));
  569.      end
  570.   case 'shortnames'
  571.      out = strvcat(1,thrMethods{:,2});
  572.      varargout{1} = out(2:end,:);
  573.      if nbin==2
  574.          num = varargin{2};
  575.          varargout{1} = deblank(varargout{1}(num,:));
  576.      end
  577.   case 'nums'
  578.      varargout{1} = cat(1,thrMethods{:,3});
  579. end
  580. %-----------------------------------------------------------------------------%
  581. function his = AdjustHist(his,axe)
  582. xlim = get(axe,'Xlim');
  583. d    = his(1,:)-his(1,1);
  584. his(1,:) = xlim(2)*(d/max(d));
  585. %-----------------------------------------------------------------------------%
  586. %=============================================================================%