Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

This section explains how to send data from a Simulink^{®} model
to the MATLAB^{®} workspace so you can analyze the results of simulations
in greater detail.

You can use a Signal To Workspace block, from the Sinks library of the DSP System Toolbox™ product to send data to the MATLAB workspace as a vector. For example, you can send the error rate data from the Hamming code model, described in the section Reduce the Error Rate Using a Hamming Code. To insert a Signal to Workspace block into the model, follow these steps:

To open the model, at the MATLAB prompt, enter

`doc_hamming`

.Drag a Signal To Workspace block, from the Sinks library in the DSP System Toolbox product, into the model window and connect it as shown in the following figure.

**Hamming Code Model with a Signal To Workspace Block**

To configure the Signal to Workspace block, follow these steps:

Double-click the block to display its dialog box.

Type

`hammcode_BER`

in the**Variable name**field.Type

`1`

in the**Limit data points to last**field. This limits the output vector to the values at the final time step of the simulation.Click

**OK**.

When you run a simulation, the model sends the output of the
Error Rate Calculation block to the workspace as a vector of size
3, called `hamming_BER`

. The entries of this vector
are the same as those shown by the Error Rate Display block.

After running a simulation, you can view the output of the Signal to Workspace block by typing the following commands at the MATLAB prompt:

format short e hammcode_BER

The vector output is the following:

```
hammcode_BER =
```

5.4066e-003 1.0000e+002 1.8496e+004

The command `format short e`

displays the entries
of the vector in exponential form. The entries are as follows:

The first entry is the error rate.

The second entry is the total number of errors.

The third entry is the total number of comparisons made.

To analyze the error-correction performance of the Hamming code, send the transmitted signal, the received signal, and the error vectors, created by the Binary Symmetric Channel block, to the workspace. An example of this is shown in the following figure.

**Send Signal and Error Data to the Workspace**

To

`open the model`

shown in the previous figure, type`doc_channel`

at the MATLAB command line.Double-click the Binary Symmetric Channel block to open its dialog box, and select

**Output error vector**. This creates an output port for the error data.Drag three Signal To Workspace blocks, from the Sinks library in the DSP System Toolbox product, into the model window and connect them as shown in the preceding figure.

Double-click the left Signal To Workspace block.

Type

`Tx`

in the**Variable name**field in the block's dialog box. The block sends the transmitted signal to the workspace as an array called`Tx`

.In the

**Frames**field, select`Log frames separately (3-D array)`

. This preserves each frame as a separate column of the array`Tx`

.Click

**OK**.

Double-click the middle Signal To Workspace block:

Type

`errors`

in the**Variable name**field.In the

**Frames**field, select`Log frames separately (3-D array)`

.Click

**OK**.

Double-click the right Signal To Workspace block:

Type

`Rx`

in the**Variable name**field.In the

**Frames**field, select`Log frames separately (3-D array)`

.Click

**OK**.

After running a simulation, you can display individual frames
of data. For example, to display the tenth frame of `Tx`

,
at the MATLAB prompt type

Tx(:,:,10)

This returns a column vector of length 4, corresponding to the
length of a message word. Usually, you should not type `Tx`

by
itself, because this displays the entire transmitted signal, which
is very large.

To display the corresponding frame of errors, type

errors(:,:,10)

This returns a column vector of length 7, corresponding to the length of a codeword.

To display frames 1 through 5 of the transmitted signal, type

Tx(:,:,1:5)

You can use MATLAB to analyze the data from a simulation. For example, to identify the differences between the transmitted and received signals, type

`diffs = Tx`

~`=Rx`

;

The vector `diffs`

is the XOR of the vectors `Tx`

and `Rx`

.
A 1 in `diffs`

indicates that `Tx`

and `Rx`

differ
at that position.

You can determine the indices of frames corresponding to message words that are incorrectly decoded with the following MATLAB command:

error_indices = find(diffs);

A 1 in the vector `not_equal`

indicates that
there is at least one difference between the corresponding frame of `Tx`

and `Rx`

.
The vector `error_indices`

records the indices where `Tx`

and `Rx`

differ.
To view the first incorrectly decoded word, type

Tx(:,:,error_indices(1))

To view the corresponding frame of errors, type

errors(:,:,error_indices(1))

Analyze this data to determine the error patterns that lead to incorrect decoding.

Was this topic helpful?