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?.

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

Converts single-channel frame-based signals to MATLAB

^{®}column vectorsConverts multichannel frame-based signals to two-dimensional MATLAB matrices

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.

MATLAB Function blocks accept frame-based signals
of any data type *except* bus objects. For a list
of supported types, see Supported Variable Types.

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

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

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.**Note:**For more information on how to set data properties, see Defining Data in the Ports and Data Manager.

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

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.

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.

Was this topic helpful?