www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/toolbox/da/da_coeff_med_filter.m
function da=da_coeff_med_filter(da,coeff_names,aperture); % DA_COEFF_MED_FILTER provide median filtration of coefficients with the % da - discriminant model % names in coeff_names array % aperture - aperture of median filter % example: da_coeff_med_filter(da,{'c0 (-discr. fun.)' 'c1' 'c3' 'c22'},5); % % last modified 7.02.05 str=da.coefficients_txt; str=[{'c0 (-discr. fun.)'} str]; if nargin<2 [selection,ok] = listdlg('PromptString','Select coefficients:',... 'SelectionMode','multiple','ListString',str); else ok=0; selection=[]; for i=1:length(coeff_names) for j=1:length(str) if strcmp(str{j},coeff_names{i}) ok=1; selection=[selection j]; end end end end if ok if nargin<3 prompt = {'Enter filter aperture '}; dlg_title = 'Median filter'; num_lines= 1; def = {'5'}; answer = inputdlg(prompt,dlg_title,num_lines,def); else answer={num2str(aperture)}; end if ~isempty(answer) aperture=str2num(answer{1}); Data=[-da.discriminant_func da.coeff_data]; for i=1:length(selection) Data(:,selection(i))=med_filt(Data(:,selection(i)),aperture); waitbar_handle=waitbar(i/length(selection)); end delete(waitbar_handle); if selection(1)==1 da.discriminant_func=-Data(:,1); end for i=1:length(selection) if selection(i)>1 da.coeff_data(:,selection(i)-1)=Data(:,selection(i)); end end end end function Y=med_filt(X,ap); Y=X; L=length(X); if mod(ap,2) for i=((ap-1)/2+1):(L-(ap-1)/2) Y(i)=median(X((i-(ap-1)/2):(i+(ap-1)/2))); end else for i=ap/2:(L-ap/2) Y(i)=median(X((1+i-ap/2):(i+ap/2))); end end