Moving Window for a specific Time

조회 수: 5 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by