Is It Necessary to Select an Odd Span for Smoothing Data Using Moving Average Filter?

6 ビュー (過去 30 日間)
Coo Boo
Coo Boo 2020 年 2 月 24 日
コメント済み: Bjorn Gustavsson 2020 年 2 月 25 日
Hi,
When I use the moving average method in 'smooth' function, the number of data points for calculating the smoothed value must be an odd integer. If I specify span as an even number or as a fraction that results in an even number of data points, span is automatically reduced by 1. Is it necessary to select an odd span for smoothing data using the moving average filter? Does anyone know the reason?
Thanks,

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 2 月 24 日
編集済み: Bjorn Gustavsson 2020 年 2 月 24 日
You can check what happens when smooting by averaging over an even number of points. simply use convolution to carry out the averaging:
Signal = zeros(107,1);
Signal(53) = 1;
filter_length = 2;
Filtered_signal = conv2(Signal,ones(filter_length,1),'same');
plot(51:60,[Signal(51:60),Filtered_signal(51:60)],'o-')
Then you'll see that there will be a shift of the filtered signal. That is rather undesired - often enough that Mathworks decided to explicitly prevent that.
HTH
  4 件のコメント
Coo Boo
Coo Boo 2020 年 2 月 25 日
Sorry,
But I cannot understand. When we select an odd filter length, we have the signal shift too. Can you explain more?
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 2 月 25 日
Do you really get that when you use my example and only change filter_length to 3?
(HINT: I dont)
HTH

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by