Accelerating the pace of engineering and science

# Documentation

## Create Sample-Based Signals

 Note:   Starting in R2010b, many DSP System Toolbox™ blocks received a new parameter to control whether they perform sample- or frame-based processing. The following content has not been updated to reflect this change. For more information, see the Frame-Based Processing section of the Release Notes.

### Create Signals Using Constant Block

A constant sample-based signal has identical successive samples. The Sources library provides the following blocks for creating constant sample-based signals:

• Constant Diagonal Matrix

• Constant

• Identity Matrix

The most versatile of the blocks listed above is the Constant block. This topic discusses how to create a constant sample-based signal using the Constant block:

1. Create a new Simulink® model.

2. From the Sources library, click-and-drag a Constant block into the model.

3. From the Sinks library, click-and-drag a Display block into the model.

4. Connect the two blocks.

5. Double-click the Constant block, and set the block parameters as follows:

• Constant value = [1 2 3; 4 5 6]

• Interpret vector parameters as 1–D = Clear this check box

• Sampling Mode = Sample based

• Sample time = 1

Based on these parameters, the Constant block outputs a constant, discrete-valued, sample-based matrix signal with a sample period of 1 second.

The Constant block's Constant value parameter can be any valid MATLAB® variable or expression that evaluates to a matrix.

6. Save these parameters and close the dialog box by clicking OK.

7. From the Display menu, point to Signals & Ports and select Signal Dimensions.

8. Run the model and expand the Display block so you can view the entire signal.

You have now successfully created a six-channel, constant sample-based signal with a sample period of 1 second.

To view the model you just created, and to learn how to create a 1–D vector signal from the block diagram you just constructed, continue to the next section.

#### Create an Unoriented Vector Signal

You can create an unoriented vector by modifying the block diagram you constructed in the previous section:

1. To add another sample-based signal to your model, copy the block diagram you created in the previous section and paste it below the existing sample-based signal in your model.

2. Double-click the Constant1 block, and set the block parameters as follows:

• Constant value = [1 2 3 4 5 6]

• Interpret vector parameters as 1–D = Check this box

• Sample time = 1

3. Save these parameters and close the dialog box by clicking OK.

4. Run the model and expand the Display1 block so you can view the entire signal.

Your model should now look similar to the following figure. You can also open this model by typing ex_usingcnstblksbex_usingcnstblksb at the MATLAB command line.

The Constant1 block generates a length-6 unoriented vector signal. This means that the output is not a matrix. However, most nonsource signal processing blocks interpret a length-M unoriented vector as an M-by-1 matrix (column vector).

### Create Signals Using Signal from Workspace Block

This topic discusses how to create a four-channel sample-based signal with a sample period of 1 second using the Signal From Workspace block:

1. Create a new Simulink model.

2. From the Sources library, click-and-drag a Signal From Workspace block into the model.

3. From the Simulink Sinks library, click-and-drag a To Workspace block into the model.

4. Connect the two blocks.

5. Double-click the Signal From Workspace block, and set the block parameters as follows:

• Signal = cat(3,[1 -1;0 5],[2 -2;0 5],[3 -3;0 5])

• Sample time = 1

• Samples per frame = 1

• Form output after final data value by = Setting to zero

Based on these parameters, the Signal From Workspace block outputs a four-channel sample-based signal with a sample period of 1 second. After the block has output the signal, all subsequent outputs have a value of zero. The four channels contain the following values:

• Channel 1: 1, 2, 3, 0, 0,...

• Channel 2: -1, -2, -3, 0, 0,...

• Channel 3: 0, 0, 0, 0, 0,...

• Channel 4: 5, 5, 5, 0, 0,...

6. Save these parameters and close the dialog box by clicking OK.

7. From the Display menu, point to Signals & Ports, and select Signal Dimensions.

8. Run the model.

The following figure is a graphical representation of the model's behavior during simulation. You can also open the model by typing ex_usingsfwblksbex_usingsfwblksb at the MATLAB command line.

9. At the MATLAB command line, type yout.

The following is a portion of the output:

```yout(:,:,1) =

1    -1
0     5

yout(:,:,2) =

2    -2
0     5

yout(:,:,3) =

3    -3
0     5

yout(:,:,4) =

0     0
0     0
```

You have now successfully created a four-channel sample-based signal with sample period of 1 second using the Signal From Workspace block.