Moving Window for a specific Time

3 vues (au cours des 30 derniers jours)
Saad Alqahtani
Saad Alqahtani le 6 Juil 2021
Commenté : Saad Alqahtani le 6 Juil 2021
Hi,
So, the goal of this code is to calculate a Coefficient of Variation with time window of 5 seconds.
Here is my code.
% datanabs is a tourque value in Newton Meter
% t =(5*fsamp); moving window of 5 seconds
Mmean = movmean (datanabs,t); % mean of 5 seconds sliding window
Mstd = movstd(datanabs,t); % std of 5 seconds sliding window
CoV = (Mstd./Mmean)*100; % Here where I calcuulte the Coefficient of Variation
It's working but I think there is a better and efficint way to do it. Any help would be appreciated. Thanks in advance.
  2 commentaires
dpb
dpb le 6 Juil 2021
Well, if that is the definition of what you want for the moving window, don't know what would be more efficient although you don't need the two temporary arrays unless you need them for other reasons besides to compute the CV vector.
These use a N-point sliding window and return partial window values for ends so the length of the output is same as the length of the input. You can optionally discard the endpoints by selection of optional endpoints that will return shorter by the length of the window.
Or, you can choose to compute nonoverlapping windows and get fix(N/t) results instead; this can be done by reshape and direct application of mean,std and then back to vector.
Just all depends on what you want/need...
Saad Alqahtani
Saad Alqahtani le 6 Juil 2021
Got it. Thanks!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Startup and Shutdown 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