Need betterment for the Moving average filter
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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.
Respuestas (1)
Image Analyst
el 28 de Dic. de 2013
Editada: Image Analyst
el 28 de Dic. de 2013
You could use conv().
blurredSignal = conv(signal, ones(WindowWidth)/WindowWidth, 'same');
5 comentarios
Gova ReDDy
el 28 de Dic. de 2013
Image Analyst
el 28 de Dic. de 2013
conv does a moving average, in other words an average within a single signal. If you want to average the last 500 elements of 4 separate signals you need to do
averagedSignal = (p1(end-499:end)+...
p2(end-499:end)+...
p3(end-499:end)+...
p4(end-499:end)+...)/4;
Gova ReDDy
el 29 de Dic. de 2013
Editada: Gova ReDDy
el 29 de Dic. de 2013
Gova ReDDy
el 29 de Dic. de 2013
Image Analyst
el 29 de Dic. de 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.
La pregunta está cerrada.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

