Matlab定位窗口重叠50%

时间:2014-04-08 01:07:01

标签: matlab math

我使用以下代码来窗口化数据并找到每个窗口的平均值。当前用于直接在上一个窗口的末尾启动每个新窗口。如何修改此代码,以便每个新窗口与前一个窗口重叠50%。

 Fq = 51.2; //Sample Rate of accelerometer 
 windowLength = 5; //Length for each window in seconds
 startPos = 1; //Starting Position for 1st win

 endPos = startPos + (windowLength * floor(Fq)); //End Position for 1st win
 totalWindows = floor(length(walk)/Fq/windowLength);

 stats = zeros(windowLength,9);

 for i = 1:totalWindows
     epMean = mean(walk(startPos:endPos,:)); //calculate window mean

     //X, Y & Z axis values for each stat
     walkfeature(i,1:4) = epMean; 

     //Next window position
     startPos = endPos+1;
     endPos = startPos + (windowLength * floor(Fq))
 end

1 个答案:

答案 0 :(得分:0)

不是非常优化,但它接近原始代码,它可以让您指定任何所需的重叠:

windowLengthInPoint = windowLength * floor(Fq) ; %// store this value

overlap = 0.2 ;  %// in portion of windowLength - 20% in this example
increment = floor(windowLengthInPoint*overlap) ;

startPos = 1 ;
endPos = startPos + windowLengthInPoint ;
Lvec = length(walk) ;
while endPos <= Lvec
    epMean = mean(walk(startPos:endPos,:)); %//calculate window mean

     %// your other code
     %// ...

    startPos = startPos + increment ;
    endPos = startPos + windowLengthInPoint ;
end