Back in 2010, I wrote a post explaining how to apply a scalar algorithm to a vector using the For Each subsystem. At that time, only discrete algorithms could be vectorized that way. In R2011b, the For Each subsystem now supports continuous sample times.
Let's look at a simple example.
Filtering sensors data
In multiple occasions in the past I ended up acquiring the signal of a slow rate sensor and using this signal into a fast rate controller. In order avoid feeding a discontinuous signal to my controller, I used to insert a Transfer Function block to filter the slow rate signal. A simplified version of this processing look like this:
The problem is that often the sensors do not provide a scalar value, but a vector. For example, a vision system can return the three components of a Cartesian position. In that case, I had to separate the components and filter them individually:
For a vector of three elements, this is not too bad. But I have seen models where hundreds of signals had to be separated and recombined. In R2011b, all you have to do is to put the Transfer Function block inside the For Each Subsystem, and it will adapt automatically to the number of elements of the input signal.
In addition to making the model easier to edit, it also speeds up the model initialization and generate more efficient code, because the model contains less blocks.
Now it's you turn
For a more complex example, I recommend looking at the demo titled Modeling Objects with Identical Dynamics using For Each Subsystem.
How are you going to take advantage of the continuous sample time support inside the For Each Subsystem? Modeling a farm of wind turbines? Multiple planes flying together? An army of identical robots? Leave a comment here.
7 CommentsOldest to Newest
I would like to make a plug for supporting the FOR-EACH subsystem in the HDL Coder. It seems like it should be relatively straight forward to map the FOR loop to an HDL FOR-GENERATE statement. That would add a significant amount of power to the product.
Just a thought.
Thank you for point this out. The way I previously solved the problem was by constructing the filter using “primitive blocks”: gain, integration and summation (as a state block diagram). This method has one advantage in that the resulting transfer function can be different for each element of the vector by using a diagonal matrix for the gain block.
As you can guess, determining what will be the next feature supported by Simulink HDL coder is a question of prioritization.
I recommend contacting technical support with a description of your use case if this enhancement could have a significant effect on your application.
You are bringing up an important point. Many Simulink blocks (like Gain, Sum and Integrator) support vectorization and do not need to be placed inside the For Each subsystem.
The For Each subsystem becomes useful when your algorithm requires blocks that do not support vectorization. Unfortunately, this is currently not possible to pass different sets of parameters to each iterations of the For Each. We are aware of this need and are looking into improving this in a future release.
Excellent addition! I was surprised that this feature wasn’t supported when the ForEachSubsystem was originally introduced, but glad to see it now. Does this block now support hybrid subsystems with continuous blocks and discrete blocks with different sample times? I see also that the block can support a Model Reference. Are there any constraints on the Model Reference other than that it can’t be running in Normal mode? I assume that just like other blocks, there is no way use different model arguments to the different iterations of the Model Reference?
Also, the link at the top of the post to the relevant page in the doc is pointing to the R2011A documentation.
- Yes the For Each subsystem now supports hybrid systems containing multiple sample times, discrete and continuous.
– You are right when mentioning that you cannot pass different arguments or parameters for different iterations, this is something we are looking to improve in the future.
– Thanks you for mentioning the wrong link, it should be fixed now.
is there simulink block to get signal from fuzzy logic output to a parallel signal to output help me sir