How to replace (in a vector ) every value by the average of the previous n samples? (To smooth a signal)

2 visualizaciones (últimos 30 días)
Hi,
I need help with a code that replaces every value by the average of the previous 100 samples.
And still remains in the same length that it was before..
I tried this:
% resampling - smoothing, replacing each value in the mean of previous last
n = 100; % number of elements to create the mean over
num1 = length(SE_rest);
num2 = mod(num1,n);
SE_rest_resampled = SE_rest(1:num1-num2,1);
samples = reshape(SE_rest_resampled,n,length(SE_rest_resampled)/n); % reshape SE_rest_resampled to [n, (num1-num2)/n)
energies = ((sum(samples.*samples)));
but it changes the length of the vector, and I need it to stay in the same length - and just to be smoother.
Thanks !!!

Respuestas (1)

Ameer Hamza
Ameer Hamza el 27 de Mayo de 2020
Try movmean()
movmean(SE_rest, [100 0])

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by