See movmean(): https://www.mathworks.com/help/matlab/ref/movmean.html. For only using past values, write in like this
x; % signal
y = movmean(x, [4, 0]);
It will average 5 points.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!