How to calculate the moving average of a finite duration data using sliding concept?

2 ビュー (過去 30 日間)
I want to compute the moving average of the data array as X = [2 3 4 5 6 8] using sliding window concept with window size of 4. This example is given in the following link. https://in.mathworks.com/help/dsp/ug/sliding-window-method-and-exponential-weighting-method.html .
For that, I am using the command movAvg = dsp.MovingAverage from DSP System Toolbox. But using that I am getting answer like as shown below.
X = [2 3 4 5 6 8];
movavgWindow = dsp.MovingAverage(4);
Y = movavgWindow(X)
Y = 1×6
0.5000 0.7500 1.0000 1.2500 1.5000 2.0000
But as per the link given above the actual answer would be like as shown below.
Y = [0.5 1.25 2.25 3.50 4.50 5.75];
So where is the mistake? Can anyone tell me why the answer is comming as so different even if I am using the same command as recommended in the documemt.

採用された回答

Matt J
Matt J 2022 年 3 月 23 日
Both are wrong.
X = [2 3 4 5 6 8];
win=ones(1,4)/4;
Y = conv(X,win,'full')
Y = 1×9
0.5000 1.2500 2.2500 3.5000 4.5000 5.7500 4.7500 3.5000 2.0000
  3 件のコメント
Matt J
Matt J 2022 年 3 月 23 日
編集済み: Matt J 2022 年 3 月 23 日
It is really so shocking that how the MATLAB inbult command can give wrong answers or there may be some mistake we are doing to understand about how the functions works.
Probably the latter, but I can't tell from the documentation what it's doing.
Then how to do this except selecting the range of Y from 1 to 6. Is there any way to do that?
One way:
X = [2 3 4 5 6 8];
Y=movmean(X,[3,0],'Endpoints',0)
Y = 1×6
0.5000 1.2500 2.2500 3.5000 4.5000 5.7500
Souarv De
Souarv De 2022 年 3 月 24 日
@Matt J Thanks Matt for helping me to understand the solution.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with DSP System Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by