Moving Window for a specific Time

4 ビュー (過去 30 日間)
Saad Alqahtani
Saad Alqahtani 2021 年 7 月 6 日
コメント済み: Saad Alqahtani 2021 年 7 月 6 日
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...
Saad Alqahtani
Saad Alqahtani 2021 年 7 月 6 日
Got it. Thanks!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by