Making a moving average filter without looking in to the future. So forecasting the data, how do you do it?

조회 수: 6 (최근 30일)
M = 11
% 4. Moving average filter
for n = 1:M
yma(n) = average(y([1:n+M-1]));
end
for n = M+1:length(t)-M
yma(n) = average(y([n-M:n+M]));
end
for n = length(t)-M+1:length(t)
yma(n) = average(y([n-M:length(t)]));
end
yma = yma';
  댓글 수: 3
Kaz Van Rijsewijk
Kaz Van Rijsewijk 2022년 4월 12일
Hello Mathieu,
This is the question that I have to answer and also apply to my script:
If we want to filter in real time we can't filter this way, we can only do it backwards.
24. Adjust the moving average filter accordingly, such that at the same value of M is filtered over as many points as before. Is there a phase delay now?
Mathieu NOE
Mathieu NOE 2022년 4월 12일
sorry ; it's late here and I must be tired ,
I don't understand the question 24

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2022년 4월 12일
편집: Steven Lord 2022년 4월 12일
Use the movmean function with the M = movmean(A, [kb kf]) syntax given on its documentation page. Choose kf = 0 to include 0 elements forward of the current element.
x = randi(10, 1, 5)
x = 1×5
3 6 9 6 8
M = movmean(x, [1 0])
M = 1×5
3.0000 4.5000 7.5000 7.5000 7.0000
N = 4;
check = (x(N-1)+x(N))/2 - M(N)
check = 0
Note that the expression for check (the moving mean for element 4) does not include x(5), so the moving mean computation didn't "look into the future".
  댓글 수: 1
Kaz Van Rijsewijk
Kaz Van Rijsewijk 2022년 4월 12일
Hello Steven,
Thank you! But just be sure does this still apply to next question. My first question was a bit unclear I think.
  • If we want to filter in real time we can't filter this way, we can only do it backwards.
24. Adjust the moving average filter accordingly, such that at the same value of M is filtered over as many points as before. Is there a phase delay now?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by