Simulink block to get the specified value
10 visualizzazioni (ultimi 30 giorni)
Paul il 6 Set 2021
One option to grab the value of a signal at a certain time and hold it afterwards is to pass it through a Triggered Subsystem, where the trigger signal is based on the time you want to grab the value. Like this:
Più risposte (1)
Andy Bartlett il 7 Set 2021
Modificato: Andy Bartlett il 7 Set 2021
You need your design to remember the past value of a signal, so your design will need some lasting memory. Lasting memory is also called state. The simplest way to get memory for a discrete-time model is to use a Unit Delay or Delay block.
You want to latch a signal value at a particular time, so you'll need to create a true/false signal that indicates value true when you want the latching to happened and false at all other times.
You can then use a switch block to control whether the new signal value goes into the delay block or the delay block output is fed back into itself. This figure shows the basic idea where the signal labelled Enable is the true/false control signal.
There is a subtle, but important choice of whether it is OK to get the latched value after one unit delay time step or immediately with zero delay. The image above will involve a one time step delay. If you need zero delay, then change the design to feed the signal labelled Xnew as the output instead of Xold.
Since you want to capture the very first value of the signal, you want an enable signal that is true at the beginning of simulation and always false after that. A constant and the good old unit delay can do this as shown in this image. A key is that the first output of the unit delay is its initial condition which is 1. After that, the delay's output will be its prior input which is always 0.
A model showing both the one time step delay and zero time step delay is attached. It works with R2013a and newer.
Note the delay blocks shown are custom examples and are not the Delay block provided by Simulink. Click to select each block of these custom delay blocks one at a time, then do Crtl-U to look at what is underneath their masks. That will be informative.
The two sets of outputs look like this.
Where the yellow signal is the one to be captured at a specific moment.
The green-ish signal is the true-false control signal for when the latching action is to happen.
The magenta is the captured and held signal.
Note, the sample times for all the blocks are 1 second..