Brain Teaser - Moving Average Filtering Algorithm

I have a 1st dataset of 86400 wind speed (WS) values ​​in Matlab and need help filtering it. This requires a certain level of dexterity.

If the average WS exceeds:

  • 25 m / s in a time interval of 600 s
  • 28 m / s in a time interval of 30 seconds
  • 30 m / s in a time interval of 3 s

If any of these parameters is satisfied, WS is considered β€œinvalid” until the average WS level falls below 22 m / s for 300 s.

Here is what I have for a 600 second call. I do 600 and 300 seconds of moving average from the data contained in the "data set". I filter the intervals from the first occurrence of an average of 25 m / s to the next occurrence of a value below 22 m / s as "NaN". After filtering, I will do another 600 seconds, and the intervals with the values ​​marked with the NaN icon will remain on NaN.

i.e.

Rolling600avg(:,1) = tsmovavg(dataset(:,2), 's', 600, 1); Rolling300avg(:,1) = tsmovavg(dataset(:,2), 's', 300, 1); a = find(Rolling600avg(:,2)>25) b = find(Rolling300avg(:,2)<22) dataset(a:b(a:find(b==1)),2)==NaN; %?? Not sure 

This will require clever use of the β€œsearch” and some indexing. Can anyone help me out? Filters 28 m / s and 30 m / s will follow the same method.

+6
source share
1 answer

If I follow your question, one approach is to use a for loop to determine where NaN should start and end.

 m = [19 19 19 19 28 28 19 19 28 28 17 17 17 19 29 18 18 29 18 29]; %Example data a = find(m>25); b = find(m<22); m2 = m; % Use a loop to isolate segments that should be NaNs; for ii = 1:length(a) firstNull = a(ii) lastNull = b( find(b>firstNull,1) )-1 % THIS TRIES TO FIND A VALUE IN B GREATER THAN A(II) % IF THERE IS NO SUCH VALUE THEN NANS SHOULD FILL TO THE END OF THE VECTOR if isempty(lastNull), lastNull=length(m); end m2(firstNull:lastNull) = NaN end 

Note that this only works if tsmovavg returns a vector of equal length, like the one passed to it. If not, it is more complicated and will require some changes.

There is probably a way to avoid the for loop, but this is a pretty simple solution.

+1
source

All Articles