Info
此问题已关闭。 请重新打开它进行编辑或回答。
Need betterment for the Moving average filter
1 次查看(过去 30 天)
显示 更早的评论
Hello, I made a moving average filter that has five sub windows say P1,p2,p3,p4,p5 where p1 has the current 500 values of the signal and p2:previous 500 values ,p3:500 values prior to p2,p4:500 values prior to p3,p5:500 values prior to p4 as shown in the below code and also it replaces the current 500 values of the signal with the average of the 2500 values i.e,p1(current values)+p2+p3+p4+p5.
clc;
clear all;
nm=load('signal1.mat');
nm1=nm.nomotion(4000:40000,:);
p1=zeros(500,1);
p2=p1;
p3=p2;
p4=p3;
p5=p4;
for i=1:500:length(nm1)-500
if (i<500)
p5=nm1(i:i+499,:);
out1(i:i+499,:)=p5;
elseif (i<1000)
p4=nm1(i:i+499,:);
out1(i:i+499,:)=p4;
elseif(i<1500)
p3=nm1(i:i+499,:);
out1(i:i+499,:)=p3;
elseif(i<2000)
p2=nm1(i:i+499,:);
out1(i:i+499,:)=p2;
else
p1=nm1(i:i+499,:);
for k=1:1:length(p1)
out(k,1)=(p1(k)+p2(k)+p3(k)+p4(k)+p5(k))/5;
end;
p5=p4;
p4=p3;
p3=p2;
p2=out;
out1(i:i+499,:)=out;
end;
end;
plot(out1);hold on;plot(nm1,'-r');
The result after averaging is shown below with red showing averaged signal and blue showing input signal.But I think the averaging is not done properly.
can someone explain how to make a better moving average as mentioned above and the file is attached.
0 个评论
回答(1 个)
Image Analyst
2013-12-28
编辑:Image Analyst
2013-12-28
You could use conv().
blurredSignal = conv(signal, ones(WindowWidth)/WindowWidth, 'same');
5 个评论
Image Analyst
2013-12-29
No, probably not, unless I spent more time trying to figure out what's going on with your code than I can spend. Maybe someone else will. Sorry.
此问题已关闭。
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!