How to generate a triggered pulse using Simulink

53 views (last 30 days)
I want to generate a pulse using Simulink when triggered. The output signal is initially 0, then becomes 1 when triggered for a specified time, then -1 for the same amount of time, then back to 0 and hold until triggered again. How can I do this using Simulink.

Accepted Answer

Richard
Richard on 28 Aug 2024
This is how I ended up doing it. It is not elegant, but it works.There is a minor issue with using 0 as a threshold on the switch since the time values are a little bit off due to numerical accuracy in the integrator. If there is a better way to do this, I would appreciate a comment.

More Answers (1)

Shubham
Shubham on 26 Aug 2024
Hi Richard,
To generate a pulse in Simulink that behaves as you described, you can use a combination of blocks to create a state machine that responds to a trigger input. Here’s a step-by-step guide to set this up:
Components Needed
  1. Trigger Block: To receive the trigger signal.
  2. Stateflow Chart: To manage the state transitions and timing.
  3. Pulse Generator or Constant Blocks: To define the output levels (0, 1, -1).
Steps to Implement
  1. Open Simulink and create a new model.
  2. Use a Pulse Generator or a Constant Block to simulate the trigger input. This block will provide the trigger signal to initiate the pulse sequence.
  3. Drag a Stateflow Chart block from the Simulink library into your model. Stateflow is ideal for managing the sequence of states (0, 1, -1, 0) based on the trigger.
  4. Design the Stateflow Chart:
  • Open the Stateflow chart and create four states: Idle, High, Low, and BackToZero.
  • Idle: The default state where the output is 0.
  • High: The state where the output is 1.
  • Low: The state where the output is -1.
  • BackToZero: The state where the output returns to 0.
  • Define transitions:
  • Idle to High: Triggered by the input signal.
  • High to Low: After a specified time duration.
  • Low to BackToZero: After the same duration as High.
  • BackToZero to Idle: Immediately after reaching 0.
5. Use temporal logic in Stateflow, such as after(time, sec), to control the duration of the High and Low states. For example, if you want the pulse to last 1 second in each state, use after(1, sec).
6. In each state, set the output value. For example:
  • Idle: output = 0;
  • High: output = 1;
  • Low: output = -1;
  • BackToZero: output = 0;
7. Connect Blocks:
  • Connect the trigger signal to the Stateflow chart.
  • Connect the output of the Stateflow chart to a Scope or any other block to observe the output signal.
8. Run the simulation to ensure that the model behaves as expected. When the trigger is activated, the output should follow the sequence 0 → 1 → -1 → 0.
  1 Comment
Richard
Richard on 26 Aug 2024
Thank you for the response. Is there a way to do this without State Machines. I don't have Stateflow.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!