I need help with solving the task in Simulink + Stateflow

2 views (last 30 days)
Hello everyone. I have this task, does anyone have any ideas on how to do this or ready-made examples of something like this?
Need to make the model of specified below system and make software test.
System description
Input:
- only one input
- during all time input gets a series of data
- at each cycle input signal is either 0 or 1
- type boolean
Output:
- only one output
- at each cycle time, the system sets the output 0 or 1 that depends on
conditions
- the system sets the output to 1 if the sum of 1 in the last input
series was odd.
- in other cases, the system sets the output to 0
- type boolean
Definition of the series:
Series starts with 2 nd 1 in sequence (1 | 1).
Series ends after 2 nd 0 in sequence (0 0 |).
Example of input data and series:
input 0 1 0 1 | 1 1 1 0 0 |1 0 0 1| 1 1 1 0 1 0 0| 0 0
output 0 0 0 0 | 0 0 0 0 1 |1 1 1 1| 1 1 1 1 1 1 0| 0 0
Requirements to the software models:
* should be done in simulink and stateflow
* test example above should be included as test case

Answers (1)

Epsilon
Epsilon on 11 Mar 2025
Hi Paul,
Processing the input data can be performed with two different states for series and non-series boolean values, using a Stateflow chart. These states can be used to evaluate the data and produce the desired output.
The following steps can be undertaken to achieve the task:
  1. Add a Chart: Begin by adding a ‘chart’ to your Simulink workspace. This chart will contain the states and logic necessary for processing the input.
  2. Input Data: Use a ‘From Workspace’ block to pass the input data to this chart. The data can be defined in the base workspace.
  3. Define States: Inside the chart, create two states to represent the series and non-series data. Utilize variables to store the last and the second-to-last inputs.
  4. State Transitions: Implement transitions to switch between the states based on the series definition.
  5. Series State Logic: Within the series state, introduce a counter variable to tally the number of 1’s.
  6. Output Update: Upon entering the non-series state, check whether the counter is even or odd and update the output accordingly.
I've attached an image of an example implementation I tried, which might be helpful.
Also, the Stateflow Onramp is a great resource to get started with Stateflow. Kindly refer to the following link for the same: https://matlabacademy.mathworks.com/details/stateflow-onramp/stateflow

Categories

Find more on Decision Logic in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!