Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Need betterment for the Moving average filter
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Image Analyst
le 28 Déc 2013
Modifié(e) : Image Analyst
le 28 Déc 2013
You could use conv().
blurredSignal = conv(signal, ones(WindowWidth)/WindowWidth, 'same');
5 commentaires
Image Analyst
le 29 Déc 2013
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.
Cette question est clôturée.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

