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 件のコメント
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
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)
M = movmean(x, [1 0])
N = 4;
check = (x(N-1)+x(N))/2 - M(N)
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".
参考
カテゴリ
Help Center および File Exchange で Digital Filter Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!