MATLAB: Function for Calculating Moving sum

moving sum

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

Best Answer

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);
Related Question