
Originally Posted by
sensitive
Im trying to make a code in matlab for the moving average formula you gave. but im not sure the outputs are correct. I plotted the values of ys(i) and the values before the 50th points are all zeros. shouldnt it smoothed the data instead of
going to zeros..Or does the smoothed data starts from point 50th onwards and neglect the points before that?
n = 100;
N = 40;
l = 2*N + 1;
for i = 50:n
for j = -N:N
ys(i) = sum(xx(i+j))/l
end
end
Could you please correct me where Ive done wrong.thank you
try something like this:
Code:
x=rand(1,256); #dummy data to filter
lwind=11; #window length
lpad=floor(lwind/2); #extra zeros needed to start filter off and end it
x=[zeros(1,lpad],x,zeros(1,lpad]]
y=zeros(1,256);
for idx=1:256
y(idx)=sum(x((idx):(idx+lwind-1));
end
Note this will have start and end transients of length lpad
ZB