How to Process Signals as Frames in Simulink
Learn how to use frame-based processing in Simulink® models to accelerate simulations and mimic the behavior of real-time systems. Paired with DSP System Toolbox™, you can configure signal processing blocks to create and operate on frames of data, allowing for multiple samples to be handled in a single timestep. See how to use Simulink graphical features including signal dimension labels and color-coded sample times to inspect and debug system models. You can also use the Simulink Profiler to assess the effects of differing data frame sizes on simulation performance.
Grouping and processing signal data as frames in Simulink models can often lead to improved simulation performance. It also more closely mimics how streams of signal data are handled by real-time digital signal processing systems allowing for more accurate simulations of real world behavior in hardware. In this video, we'll cover the basics of working with frames in Simulink including introducing them to a model, enabling blocks for frame-based processing, and evaluating the effects of differing frames sizes. Frames in Simulink are analogous to working with vectors in MATLAB. Vectorized MATLAB code often runs faster than the corresponding code containing loops.
This is because the number of times the MATLAB interpreters called is lowered, reducing the overheads on code execution. Similarly, processing data as frames in Simulink decreases overheads from calling the Simulink scheduler leading to faster simulation. Paired with DSP System Toolbox, Simulink offers a range of blocks to model and simulate signal processing systems. Signal processing blocks can be configured to handle samples or frames of data as specified by their block parameters. In sample-based processing, blocks process signals one sample at a time from either one or more channels.
For example, here, two channels feed into the square block, but only one sample from each channel is processed at every time step. Alternatively, when blocks are enabled for frame-based processing, they process signals in groups of sequential samples called frames. The frame shown here has two channels each with five sequential samples. The number of columns represent the channels per frame, while the number of rows represent the samples per channel. The same multi-channel signal is now processed in a frame-based manner.
In a single time step, multiple samples from one or more channels are processed. To demonstrate the improved performance achievable with frame-based processing, let's take a look at an example of an application in audio signal processing. In the model, a stereo audio file is imported and processed to add a series of sound effects. The stop time of the model is set for 10 seconds. After being read by the From Multimedia File block, the audio signal is passed through a cascaded byquadratic filter with three sections, a flanger effect block, reverberator block, and is finally written to the MATLAB workspace.
Inspecting the byquadratic filter further, we can see that each filter section is set to operate with frame-based processing. The flanger and reverb blocks are configured to inherit the signal sample rate. To confirm that the model will simulate with correctly sized data frames, let's first set the audio frame size parameter of the From Multimedia Block to be 256 samples per frame. Now let's open the Debug menu and enable Signal Dimensions and Sample Time Colors under Information Overlays. As we can see, each block in the model operates on signal inputs of size 256x2 as intended.
We expect to see two columns in the frames as stereo audio signals have two channels for left and right sound. Now we're ready to start simulating. To assess the model's performance, we'll make use of the Simulink Profiler located in the Debug menu. First, let's simulate the example model with a frame size of 256 samples, as said previously. Let's run the model with the Profiler to generate a profiler report containing the performance results.
Now, let's increase the audio frame size parameter of the source block to be 1,024 samples per frame, and run the Profiler a second time. Let's add a second Report Panel so that we can compare the two profiler reports side by side. Compared to the second simulation with 1,024 samples per frame, we can see that the simulation run with 256 samples per frame required a greater amount of time and number of calls to blocks in the model to complete. By plotting simulation time and the number of calls to blocks for each simulation using data from the profiler reports, the relationship between performance and frame size is quickly recognizable. As signals processed with a greater number of samples per frame require fewer block calls, simulations benefit from reduced Simulink scheduler overhead needing to improve performance.
However, a trade-off exists in that larger frames also consume more memory, which can negatively affect the performance of complex models. In general, it's worthwhile to experiment with different frame sizes to find one that maximizes simulation performance for your model. To summarize, introducing frames into a Simulink model reduces overheads and improves simulation performance. Frame-based processing also closely mimics the ways in which real-time systems collect and operate on streams of data. Simulink provides functionality for modeling, designing, and testing signal processing systems with blocks with native support for frame-based signals.
In the example we worked with, we only needed to change the audio frame size parameter of the source block to experiment with the effects of differing frame sizes across the model. And graphical features such as signal dimensions and color-coded sample times can be used to quickly view and inspect signals in your system architecture aiding in design and testing. For examples and more information on frame-based processing in Simulink, please visit our documentation.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.