Strange behavior: gain bocks which integrate step inputs

1 view (last 30 days)
Hi all!
I have the following problem. I have three signals which pass into some Compare to constant block. The Compare to constant blocks clearly output a boolean value. Let's call these boolean variable A,B and C. Now, depending on the values of A,B,C I should select an appropriate input of a 4-port switch. Therefore, I need to a function that takes the values of A,B,C as input, and which output an integer between 1 and 4.
This is my solution. I first convert A,B, C in integer through the well-known formula y = A*4+B*2+C*1, where A is the MSB and C is the LSB. Such formula is implemented through 3 Gain Blocks (with gains 4,2 and 1 respectively) blocks and a sum block with three inputs. Then the value of y is used as input of a look-up table which maps y into {1,2,3,4}, depending on which input of the switch I need.
However, I have the problem that the gain blocks "integrate" the boolean values. For instance, as I have a neat step at the input of the gain block (i.e. something like that _| ), but the output looks like a ramp (i.e. something like that _/). This leads to unexpected behavior of the system. I have tried to reduce the fundamental step size (I am using a fixed-step solver), and the situation gets a bit better, but not completely solved. How can I solve this?
Thanks! :)

Accepted Answer

Doug Eastman
Doug Eastman on 10 Apr 2013
The issue with the lines being slanted is due to the fact that Simulink sees these signals as continuous so it will connect the fixed-step discrete points with lines rather than stair-steps. The slopes don't actually matter though since the simulation is not being executed between the two points. If you would like to see the stair-step you could discretize the signals using a Zero-order Hold block with the same sample rate as your base step size.
Alternatively you could use a variable-step solver with zero crossing detection so that you will get a time step at the exact moment of transition for each of the compare to constant blocks. That will also product a clean vertical edge with a continuous signal.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!