フィルターのクリア

How to create a moving average filter to a specific signal

119 ビュー (過去 30 日間)
Yian Chen
Yian Chen 2021 年 11 月 28 日
コメント済み: Image Analyst 2021 年 11 月 28 日
Hi
I wanna apply a moving average filter to my temperature dataset, it is a 92-day daily temperature dataset. How can I create the filter?
Thanks a lot!

回答 (2 件)

Chunru
Chunru 2021 年 11 月 28 日
編集済み: Chunru 2021 年 11 月 28 日
x = readmatrix("2013.txt");
n = 7; % filter order
y = filter(ones(n, 1)/n, 1, x);
plot(x); hold on;
plot(y);
legend('Original', 'MovAve')
To get rid of delay:
figure
y = filtfilt(ones(n, 1)/n, 1, x);
plot(x); hold on;
plot(y);
legend('Original', 'MovAve')
  3 件のコメント
Yian Chen
Yian Chen 2021 年 11 月 28 日
編集済み: Yian Chen 2021 年 11 月 28 日
And I apply [1/3 1/3 1/3] as a window function to my data, after the fourier transform of the result, I find there is a 'zeros' in my plot, what does that mean?
Chunru
Chunru 2021 年 11 月 28 日
See above for removing delay using filtfilt (doc it for more details).

サインインしてコメントする。


Image Analyst
Image Analyst 2021 年 11 月 28 日
Look at the movmean() function.
  2 件のコメント
Yian Chen
Yian Chen 2021 年 11 月 28 日
編集済み: Yian Chen 2021 年 11 月 28 日
Thanks! I apply [1/3 1/3 1/3] as a window function to my data, after the fourier transform of the result, I find there is a 'zeros' in my plot, what does that mean? The plot is above.
Image Analyst
Image Analyst 2021 年 11 月 28 日
@Yian Chen I don't see any zeros, and you might want to use more than 3 elements:
y = readmatrix('2013.txt')
plot(y, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);
grid on;
xlabel('Index', 'FontSize',fontSize)
% Filter it
windowWidth = 9
smoothy = movmean(y, windowWidth);
hold on;
plot(smoothy, 'r.-', 'LineWidth', 2, 'MarkerSize', 20);
legend('Original', 'Smoothed')
You could also try sgolayfilt() to smooth it. You can choose an order like 2 or 3 to follow the original data better than movmean() which uses a linear fit. An order of 2 or 3 will fit a quadratic or cubic to the data in each window position.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by