weim - Running weighted average of input data given a window USAGE: function [y,w]=weim(N,wt,x) DESCRIPTION: it computes a weighted average using the window function this filter is designed for odd weight numbers only INPUT: N is numbers of weights wt is the shape of the desired window (see window.m) x is the input data OUTPUT: y: Smoothed data vector w: The window used for smoothing (from window.m) SEE ALSO: window.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [y,w]=weim(N,wt,x) 0002 % weim - Running weighted average of input data given a window 0003 % 0004 % USAGE: 0005 % function [y,w]=weim(N,wt,x) 0006 % 0007 % DESCRIPTION: 0008 % it computes a weighted average using the window function 0009 % this filter is designed for odd weight numbers only 0010 % 0011 % INPUT: 0012 % N is numbers of weights 0013 % wt is the shape of the desired window (see window.m) 0014 % x is the input data 0015 % 0016 % OUTPUT: 0017 % y: Smoothed data vector 0018 % w: The window used for smoothing (from window.m) 0019 % 0020 % SEE ALSO: 0021 % window.m 0022 % 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 w=window(N,wt); 0025 0026 r=size(x); 0027 if r(1) > 1, x=x'; end 0028 0029 ln=(N-1)/2; 0030 lx=length(x); 0031 lf=lx-ln+1; 0032 y=zeros(size(x)); 0033 0034 for i=1:lx, 0035 0036 if i <= ln, 0037 0038 y(i)=sum(x(1:ln+i).*w(ln+2-i:N))/sum(w(ln+2-i:N)); 0039 0040 elseif ((i > ln) & (i < lf)), 0041 0042 y(i)=sum(x(i-ln:i+ln).*w)/sum(w); 0043 0044 else % i >=lf 0045 0046 y(i)=sum(x(i-ln:lx).*w(1:length(i-ln:lx)))/sum(w(1:length(i-ln:lx))); 0047 0048 end 0049 end 0050 return 0051