Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Blockset   

Creating Sample-Based Signals

Using the Constant Block

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

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 Signal Processing Sources library, click-and-drag a Constant block into the model.

  3. From the Signal Processing 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. See Linear Algebra in the MATLAB documentation for a thorough introduction to constructing and indexing matrices.

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

  7. From the Format menu, point to Port/ Signal Displays 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.

Creating a 1-D Vector Signal

You can create a 1-D vector signal 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 doc_usingcnstblksb at the MATLAB command line.

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

Using the 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 Signal Processing Sources library, click-and-drag a Signal From Workspace block into the model.

  3. From the Signal Processing Sinks library, click-and-drag a Signal 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 Format menu, point to Port/Signal Displays, 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 doc_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.

  


Related Products & Applications

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

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