📄 smooth.m
字号:
function y = smooth(x, h, ends, k, n)
% y = smooth(x, h, ends, k, n)
%
% smooth smooths data x with filter h with zero delay at point k.
%
% in: x data to be smoothed (data may be multivariate)
% h filter impulse response; (default hanning(21)).
% (Impulse response is normalized if not forbidden.)
% ends form of data ends handling:
% 'F' fixed end value 'M' mirror image of data ends
% 'N' none (default) 'P' point reflection at data ends
% 'Z' zeroes
% k delay of the filter (default (length(h)+1)/2)
% n (optional argument) if present filter is not normalized
%
% out: y smoothed data
% (c) Heimo Ihalainen 15.2.1988 (14.2.1989 HI) (20.5.1989 HI) (17.6.1989 HI)
[N,p] = size(x); nor = 0;
if N==1; N1 = p; p = N; N = N1; x = x.'; tr = 1; else tr = 0; end; y = x;
if nargin<2; h = hanning(21); end; h = h(:); l = max(size(h));
if nargin<3; ends = 'N'; end
if nargin<4; k = floor((l+1)/2); end; m = max(abs(k),l);
if nargin<5; h = h/sum(h); nor = 1; end;
%
if ends=='N'; beg = zeros(m,p); las = zeros(m-1,p); H = cumsum(h);
elseif ends=='F'; beg = ones(m,1)*x(1,:); las = ones(m-1,1)*x(N,:);
elseif ends=='M'; beg = x(m+1:-1:2,:); las = x(N-1:-1:N-m+1,:);
elseif ends=='P'; beg = 2*x(1,:)-x(m:-1:2,:);
las = 2*x(N,:)-x(N-1:-1:N-m+1,:);
elseif ends=='Z'; beg = zeros(m,p); las = zeros(m-1,p);
else error(['Such ends option is not known ' ends ' ??']);
end
%
for i=1:p;
x1 = fconv(h,[beg(:,i);x(:,i);las(:,i)]); y(:,i) = x1(k+m:N+k+m-1);
if ends=='N'&nor&k<l&k>1;
y(1:l-k,i) = y(1:l-k,i)./(1-H(l-k:-1:1));
y(N-k+2:N,i) = y(N-k+2:N,i)./H(l-1:-1:l-k+1);
end
end
if tr==1; y = y.'; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -