# moving average considering the first and end data points without changing window size, cyclic window

12 vues (au cours des 30 derniers jours)
nlm le 20 Mar 2020
Commenté : Rik le 21 Mar 2020
How can you calculate moving average, where for edges, it uses the first and last data (cyclic) points instead of decreasing the window size. For example, if my window size = 10, and number of data points = 100, then for an moving average at point 1, it uses end 5 values at 100,99,98,97,96 and 2,3,4,5,6. Similarly, at point 2, it uses, 1,100,99,98,97 and 3,4,5,6,7 so on and so forth.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Ameer Hamza le 20 Mar 2020
Modifié(e) : Ameer Hamza le 21 Mar 2020
Try this
x = 1:100;
window_size = 11;
window = ones(1, window_size)/window_size;
y = cconv(x, window, numel(x));
y = circshift(y, -floor(window_size/2));
Without cconv
x = 1:100;
window_size = 11;
left_window = floor((window_size-1)/2);
right_window = floor((window_size)/2);
x = [x(end-left_window+1:end) x x(1:right_window)];
y = movmean(x, [left_window right_window], 'Endpoints', 'discard');
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Ameer Hamza le 21 Mar 2020
Rik le 21 Mar 2020
I didn't know about the cconv function, so my first thought was to extend both side with the data from the other side (so your second option). I you keep learning

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by