matlabsimulinkstateflow

How to process vector input in StateFlow


I'm new to StateFlow and have been looking at StateFlow tutorials but have not seen one that processes vectors.

My simulink model generates vectors of audio data for which I would like to process with a state machine. For example, if the audio data goes over a certain value, state1 is to be entered, then if it goes below another value, state2 is to be entered.

If I use the unbuffer block to send the data to the StateFlow block, the system runs very slowly.

So, how can I get StateFlow to run thru a vector input, processing each element in the vector?

Edit: I've attached a pic of my chart. Here I am trying to access the i'th element of the input, but I don't know how to declare the variable i and how to increment it to process the vector.

enter image description here


Solution

  • Just to clarify, when you say you have audio data as vectors, this answer assumes that you mean they are as frames. Vectors can be, and always have been, able to be input directly into a chart. Frames on the other hand have not.

    However this functionality has changed in recent versions. For instance Stateflow in R2014b does not allow frames to be input, but in R2015b does allow frames to be input. (I don't have access to R2015a to see exactly when the functionality changed.)

    In prior versions, the workaround is to put a Reshape block immediately before the Stateflow block. This will convert the frame into a (single column) vector which can be handled by Stateflow, and hence looped over in the code inside the chart.

    Once inside the chart, the data is manipulated just like in any piece of code. For instance if you have defined the input variable to be data and you have a counter variable i then data(i) will give you the i-th element of data.