Moving Window for a specific Time

4 次查看(过去 30 天)
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 个评论
dpb
dpb 2021-7-6
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...

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by