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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154205/image.jpeg)
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!