Function for Calculating Moving sum

Is there any function to calculate moving sum of a vector? I use "smooth" for calculating the moving average of a vector

1 Kommentar

F.
F. am 16 Jul. 2012
I'm sorry but I don't understand "moving sum of a vector" ... Could you explain it and give a little exemple ? thanks

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 16 Jul. 2012
Bearbeitet: Image Analyst am 16 Jul. 2012

1 Stimme

For a "moving" sum - the sum in a window - you can use conv(), or conv2() in two dimensions:
windowWidth = 15; % or whatever.
movingSum = conv(oneDsignal, ones(1, windowWidth));
for the moving average:
windowWidth = 15; % or whatever.
movingAverage = conv(oneDsignal, ones(1, windowWidth) / windowWidth);

4 Kommentare

Kaustella Kialain
Kaustella Kialain am 8 Apr. 2015
what is oneDsignal?
Stephen23
Stephen23 am 8 Apr. 2015
In this case oneDsignal is the input data to be smoothed, and the ones(..) term defines the smoothing window.
Tina Fuhrmann
Tina Fuhrmann am 11 Okt. 2017
Why does it work with conv?
Image Analyst
Image Analyst am 12 Okt. 2017
Why wouldn't it? If you replace each element with the average of elements around it, which is what conv() can do, then that's the moving average.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jonathan Sullivan
Jonathan Sullivan am 16 Jul. 2012

2 Stimmen

help filter
doc filter
Example: Take a 10 element moving average.
x = rand(1e3,1);
n = 10;
x_moving_average = filter(ones(1,n)/n,1,x);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by