Main Content

Signal From Workspace

Import signal from MATLAB workspace

  • Signal From Workspace block

Libraries:
DSP System Toolbox / Sources

Description

The Signal From Workspace block imports a signal from the MATLAB® workspace into the Simulink® model. The Signal parameter specifies the name of a MATLAB workspace variable containing the signal to import, or any valid MATLAB expression defining a matrix or 3-D array.

Unlike the Simulink From Workspace (Simulink) block, the Signal From Workspace block holds the output value constant between successive output frames (that is, no linear interpolation takes place). Also, the initial signal values are always produced immediately at t=0.

Examples

expand all

Import a two-channel signal, A, from the MATLAB® workspace into the Simulink® model using the Signal From Workspace block. Use the To Workspace block to write the imported data to the MATLAB workspace. In this model, the To Workspace block writes slightly modified data to the MATLAB workspace.

The parameters in the Signal From Workspace block are configured as follows:

  • Sample time set to 1: This parameter determines, Ts , the sample period of the output.

  • Samples per frame set to 4: Number of samples, Mo , to buffer into each output frame. The output frame period is MoTs.

  • Form output after final value by set to Setting to zero: The block generates zero-valued outputs for the duration of the simulation after generating the last frame of the signal.

Open and simulate the ex_signal_from_workspace_frames.slx model.

The Signal From Workspace block imports the signal from the variable A, which is a 10-by-2 matrix. When you simulate the model, the data output has a frame size of 4 and a frame period, MoTs , of 4 seconds. All outputs after the third frame (at t = 8) are zero because the Form output after final data value by parameter is set to Setting to zero in this model. The To Workspace block writes this modified output to the variable dsp_ex_yout in the MATLAB workspace.

This figure shows the signal in the input variable A and how this data is written to the output array dsp_ex_yout.

Import a 3-D array A from the MATLAB® workspace into the Simulink® model using the Signal From Workspace block. Use the To Workspace block to write the imported data to the MATLAB workspace. In this model, the To Workspace block slightly modifies data.

The parameters in the Signal From Workspace block are configured as follows:

  • Sample time set to 1: This parameter determines, Ts , the sample period of the output.

  • Samples per frame set to 1: Number of samples, Mo , to buffer into each output frame. The output frame period is MoTs.

  • Form output after final data value by set to Setting to zero: The block generates zero-valued outputs for the duration of the simulation after generating the last frame of the signal.

Open and simulate the ex_signal_from_workspace_3d.slx model.

The Signal From Workspace block imports the signal from the variable A, which is a 2-by-2-by-3 array. When you simulate the model, each of the three pages (a 2-by-2 matrix) is output in sequence with period Ts. The third page is a matrix of zeros because the Form output after final data value by parameter is set to Setting to zero in this model. The To Workspace block writes the sequence of these matrices to the MATLAB workspace in the variable dsp_ex_yout.

This figure shows the signal in the input variable A and how this data is written to the output array dsp_ex_yout.

Ports

Output

expand all

Signal imported from workspace, as a scalar, vector, matrix, or 3-D array.

When the Signal parameter specifies an M-by-N matrix (M≠1), each of the N columns is treated as a distinct channel. You specify the frame size in the Samples per frame parameter, Mo. The output is an Mo-by-N matrix containing Mo consecutive samples from each signal channel. You specify the output sample period in the Sample time parameter, Ts, and the output frame period is MoTs. For convenience, an imported row vector (M=1) is treated as a single channel, so the output dimension is Mo-by-1.

When the Signal parameter specifies an M-by-N-by-P array, each of the P pages (an M-by-N matrix) is output in sequence with period Ts. The Samples per frame parameter must be set to 1.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

The name of the MATLAB workspace variable from which to import the signal, or a valid MATLAB expression specifying the signal.

The sample period, Ts, of the output, specified as a scalar. The output frame period is MoTs.

The number of samples, Mo, to buffer into each output frame, specified as a positive integer scalar. This value must be 1 when you specify a 3-D array in the Signal parameter.

Specifies the output after all of the specified signal samples have been generated.

  • When you specify Setting To Zero, the block generates zero-valued outputs for the duration of the simulation after generating the last frame of the signal.

  • When you specify Holding Final Value, the block repeats the final sample for the duration of the simulation after generating the last frame of the signal.

  • When you specify Cyclic Repetition, the block repeats the signal from the beginning after it reaches the last sample in the signal. If the frame size you specify in the Samples per frame parameter does not evenly divide the input length, a buffer block is inserted into the Signal From Workspace subsystem, and the model becomes multirate. If you do not want your model to become multirate, make sure that the frame size evenly divides the input signal length.

The block does not extrapolate the imported signal beyond the last sample.

Select the Warn when frame size does not evenly divide input length parameter to be alerted when the input length is not an integer multiple of the frame size. When the input length is not an integer multiple of the frame size, the model becomes multirate. Use the Model Explorer to turn these warnings on or off model-wide:

  1. In the Modeling tab, click Model Explorer.

  2. In the Search bar of the Model Explorer, search by Property Name for the ignoreOrWarnInputAndFrameLengths property. Each block with the Warn when frame size does not evenly divide input length check box appears in the list in the Contents pane.

  3. Select each of the blocks for which you want to toggle the warning parameter, and select or clear the check box in the ignoreOrWarnInputAndFrameLengths column.

Dependencies

To enable this parameter set Form output after final data value by to Cyclic Repetition.

Block Characteristics

Data Types

double | fixed point | integer | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a