Simulink: is there a way to only run a block once a (non-zero) signal arrives to it?

27 views (last 30 days)
Rafael Cordero
Rafael Cordero on 15 Jul 2020
Commented: Rafael Cordero on 16 Jul 2020
Hello world,
I'm doing some offline biosignal analysis on simulink. I pass an entire set of signals (e.g. 100 seconds of duration each) to Simulink and buffer them immediately (with buffer length corresponding to fs * 100 seconds). The idea is to perform a series of sequential signal processing operations on these 100-second frames rather than by considering each sample independently.
Let's say I have a signal processing block straight after this buffering. This processing block will essentially "run twice": the first time for the first 100 seconds where there is no signal (i.e there IS a "signal" but its a just a flat 0 line), and then the second time the next 100 seconds corresponding to the actual biosignals. Now this processing block includes a plot function and a send to workspace block. So what happens is that I'm plotting an empty plot and sending nonsense to the matlab workspace on the "first" time the preprocessing block is called.
So my question is: Is there any way to run a block ONLY when a buffered non-zero signal (which may also include SOME 0 elements)? Or, alternatively, is there any way to ensure these processing blocks only run when I'd like them to?
Thank you,
Rafael

Accepted Answer

Jonas
Jonas on 16 Jul 2020
Use an Enabled subsystem and use a 'Compare To Zero' block to feed the enable port.
If you want the subsystem to only execute once, you can opt for a Triggered subsystem.
  1 Comment
Rafael Cordero
Rafael Cordero on 16 Jul 2020
I used the enabled subsystem (didnt have to use the compare to zero block because if the enable input is a vector it will be considered 1 as long as there are SOME non-zero elements).
Thanks Jonas!

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!