MATLAB: Does the output signal plot from a RELAY block seem to be discrete, but, from the sample time legend confirms that its continuous in Simulink 7.7 (R2011a)

simulink

I have simple model with the following blocks:
1. Hystersis
2. Relay block.
The Hystersis block in the model emulates the Relay block, meaning, the output is set to '1' if the input value is above a specific value and '0' vice-versa. Both the blocks inherit their sample times from the 'Fixed-Step Discrete' solver and have a step size of '0.2'.
Upon updating the model, I expect the outputs of both these blocks on the Scope to be plotted as fixed step discrete. But, this is not the case in my observation. This can be determined in two ways:
– Save Scope output to workspace. The two inputs two the scope block have different plotStyle. This can be verified by executing:
sd.signals.plotStyle
ans =
0 1
– Update the model using the 'Format->Sample Time Display -> Colors' option. The output lines from both the blocks are black, representing continuous sample time. But, the plot of only the hysteresis block is 'continuous', where as Relay block has a 'discrete' output.
Further, the 'Scope' block is red colored, representing a discrete block, but, its inputs are continuous.

Best Answer

There are many interesting things to note from the simulation of this model. These observations can be answered in the questions below:
1. Does 'sd.signals.plotStyle = 1' for Relay block output represent a discrete signal ?
A. Yes. 'sd.signals.plotStyle = 1' represents that a signal is discrete.
2. Why is the scope colored as red (discrete) while all incoming signals to scope are continuous (black) ?
A. There is some ambiguity in the coloring scheme for the scope block. In essence, the black signal line - 'continuous' and red - 'discrete' are both continuous in time. But, the scope block assumes the color 'red' due to the settings for the model, which, in this example is 'Fixed-Step-Discrete'.
3. Why is the plot for relay block output discrete, while for hysteresis is continuous ?
A. In Simulink, RELAY block is special in the way it is implemented. It is executes as :
- Continuous in time
- Discrete in Amplitude
The above observations imply that the relay block is executing 'continuous in time', but, its outputs are stored as only '0' or '1' with no intermediate values. Hence, we observe that the output from relay block looks like 'discrete in time', which is not actually whats going on.
In order to see the outputs of both Hysteresis and Relay blocks as discrete, you have to force the Hysteresis block to execute as fixed step discrete. To do so, use a 'Rate Transition Block' to feed the Hysteresis and relay blocks, as shown in the 'example_solution.mdl' attached to the solution below.