smoothn.m

来自「一种新的时频分析方法的matlab源程序。」· M 代码 · 共 70 行

M
70
字号
function d=smoothn(x,n)
 
% The function SMOOTHN provides a horizontal variable window smoothing of 2-D data.
% Data x(r,c) that requires smoothing should be in column form.
%
% Calling sequence-
% d=smoothn(x,n)
%
% Input-
%	x	- 2-D matrix of data x(r,c)
%   n	- an odd number representing the full window width
% Output-
%	d	- 2-D horizontally filtered data d(r,c)
 
% Steven R.Long (NASA GSFC/WFF/NASIRF)	Initial
% J.Marshak (NASA GSFC)				    March 10, 2004 Modified
%				(               corrected the indexing of output)

%----- Get rows & columns of data input x
[r,c]=size(x);

%----- Get half-width of window
hw=(n-1)/2;

%----- Get the beginning point, center of first window			
bp=(n+1)/2;   

%----- Initialize the result data as being equal to the input 
d=x;

%----- Process each component
for j=1:c;
  %----- Smooth the data within requested window
  for i=bp:r-hw;
   % Sum over window width
   sum=0;
   for jj=i-hw:i+hw;
	  sum=sum+x(jj,j);
   end;
   % Average over window placed in center
   d(i,j)=sum/n;
  end;
  %----- Smooth the data outside requested window
  %----- by reducing the window length, but keeping it as an odd number
  % Reduce the window by 2
  nw=n-2;
  nhw=(nw-1)/2;
  nnb=bp;
  nne=r-hw;
  % Keep smoothing until window is at least 3 points
  while (nw > 1)
    nnb=nnb-1;
    sum=0;
    for jj=nnb-nhw:nnb+nhw
        sum=sum+x(jj,j);
    end;
    d(nnb,j)=sum/nw;
    nne=nne+1;
    sum=0;
    for jj=nne-nhw:nne+nhw
        sum=sum+x(jj,j);
    end;
    d(nne,j)=sum/nw;
    nw=nw-2;
    nhw=(nw-1)/2;
  end
end;

return;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?