Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sliding window on Simulink

77 views
Skip to first unread message

Santiago

unread,
May 30, 2012, 9:42:06 AM5/30/12
to
Hi,
I need to make a 3 second sliding window on Simulink that compares the max and min values within this window. How can I do this? I appreciate any help

K E

unread,
May 30, 2012, 10:46:08 AM5/30/12
to
On the File Exchange, you may be interested in slidefun (http://www.mathworks.com/matlabcentral/fileexchange/12550-slidefun-v4-0-sep-2008) which you could use to take the max and min of a window.
If you don't need the windowed values during your simulation, you could save the output (To Workspace or To File blocks), then run slidefun on the output time series.
If you do, perhaps a S-function could incorporate slidefun, but this isn't something I have done myself.

Phil Goddard

unread,
Jun 1, 2012, 7:32:48 PM6/1/12
to
If your data is discrete then you can implement this relatively easily using a MATLAB Fcn block.
For an example of using a MATLAB Fcn block see the tutorial:
http://www.goddardconsulting.ca/simulink-using-embedded-matlab.html
or the documentation for that block.

Just have the block act as a buffer, keeping track of the previous n values, and outputing their max and/or min value.

If your data is not discrete then you'll most likely have to resort to writing an S-Function.
This is because there can potentially be a different number of data points in the sliding window each time the min/max needs calculating, and it's easier to keep track of time in an S-Function that a MATLAB Fcn block.

There a couple of examples of writing S-Functions at
http://www.goddardconsulting.ca/simulink-writing-sfunctions.html
or again, lots of examples in the Writing S-Functions Guide.

Phil.
0 new messages