Skip to Main Content Skip to Search
Product Documentation

Working with Frame-Based Signals

About Frame-Based Signals

MATLAB Function blocks can input and output frame-based signals in Simulink models. A frame of data is a collection of sequential samples from a single channel or multiple channels. To generate frame-based signals, you must have an available DSP System Toolbox license. For more information about using frame-based signals, see What Is Frame-Based Processing? in the DSP System Toolbox documentation.

MATLAB Function blocks automatically convert incoming frame-based signals as follows:

An M-by-N frame-based signal represents M consecutive samples from each of N independent channels. N-Dimensional signals are not supported for frames.

To convert matrix or vector data to a frame-based output, use the data property called Sampling mode to specify that your output is a frame-based signal for downstream processing.

Supported Types for Frame-Based Data

MATLAB Function blocks accept frame-based signals of any data type except bus objects. For a list of supported types, see Supported Variable Types in the Code Generation from MATLAB documentation.

Adding Frame-Based Data in MATLAB Function Blocks

To add frame-based data to a MATLAB Function block, follow these steps:

  1. Add an input or output, as described in Adding Data to a MATLAB Function Block.

  2. If your data is an output, set Sampling mode to Frame based.

      Note   If your data is an input, Sampling mode is not an option.

Examples of Frame-Based Signals in MATLAB Function Blocks

This topic presents examples of how to work with frame-based signals in MATLAB Function blocks.

Multiplying a Frame-Based Signal by a Constant Value

In the following example, a MATLAB Function block multiplies all the signal values in a frame-based single-channel input by a constant value and outputs the result as a frame. The input signal is a sine wave that contains 5 samples per frame.

The MATLAB Function block contains the following code:

function y  = fcn(u)
y = u*3;

Input u and output y inherit size, complexity, and data type from the input sine wave signal, a 5-by-1 vector of signed, generalized fixed-point values. For y to output a frame of data, you must explicitly set Sampling mode to Frame based (see Adding Frame-Based Data in MATLAB Function Blocks). When you simulate this model, the MATLAB Function block multiplies each input signal by 3 and outputs the result as a frame.

Adding a Channel to a Frame-Based Signal

In the following example, a MATLAB Function block adds a channel to a frame-based single-channel input and outputs the multichannel result. The input signal is a sine wave that contains 8 samples per frame.

The MATLAB Function block contains the following code:

function y = fcn(u)
a = [0;4;0;-4;0;4;0;-4];
y = [u a];

Input u and output y inherit size, complexity, and data type from the input sine wave signal, an 8-by-1 vector of signed, generalized fixed-point values. For y to output a frame of data, you must explicitly set Sampling mode to Frame based (see Adding Frame-Based Data in MATLAB Function Blocks). Local variable a defines a second column on the matrix which will be output as a frame and interpreted as a second channel by downstream blocks. When you simulate this model, the MATLAB Function block outputs the new multichannel signal.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS