Moving Window for a specific Time

4 visualizzazioni (ultimi 30 giorni)
Saad Alqahtani
Saad Alqahtani il 6 Lug 2021
Commentato: Saad Alqahtani il 6 Lug 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 Commenti
dpb
dpb il 6 Lug 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 il 6 Lug 2021
Got it. Thanks!

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by