Simulink Bus Block Demonstration

This interactive demonstration introduces you to the following Simulink concepts.

If you haven't already, open the Simulink model busdemo.mdl.


Model description

The left side of this model contains five source blocks, for example the Chirp Signal block, from the Simulink Sources library.  Each block generates a scalar output signal that is appropriately labeled on the diagram. These five signals are then bundled together through the Mux block (found in the Simulink Signal & Systems library) to create a bus of signals. This bus of signals is then fed into the Bus Selector block.

The Bus Selector block pulls out the Pulse and Chirp signals from the original bundle of signals. These two signals are then displayed on a Simulink Scope with two axes.  The Pulse signal will be shown on the top axes and the Chirp signal on the bottom axes.

You can run the simulation to see the output of the Chirp and Pulse blocks on the Scope.


Bus signals and line formats in Simulink

After running the simulation, look at the lines in busdemo.mdl.  Notice that the signal going into the Bus Selector block is drawn with three lines, as shown below.

sldemo1_fig1.gif (1347 bytes)

This line format indicates a signal bus. A signal bus represents a set of signals, analogous to a bundle of wires tied together.

If you display the signal dimensions, by checking the Signal dimensions command in the model's Format menu, you should notice that a "5" appears on the bus signal, as shown below.

sldemo1_fig4.gif (1234 bytes)

This tells you that there are five signals bundled in that bus signal, one from each Source block.


Vector signals in Simulink

You can change the Sine Wave block to output a vector of signals, instead of a scalar. To do this, first open the Sine Wave block by double clicking on the block in the diagram. This opens the Block Parameters dialog associated with the Sine Wave block.

The first field in the Block Parameters dialog is Amplitude. You can change the value in this field to a vector, using the following commands.

  1. Enter [1 2] into the Amplitude field.
  2. Apply the changes and close the dialog by clicking the OK button.
  3. Update the Simulink diagram by selecting the Update diagram command from the model's Edit menu.

The line coming out of the Sine Wave block now has a "2" above it, indicating that it carries a vector, or 1-dimensional, signal with two elements. Notice that the input signal to the Bus Selector block is still labeled with a width of 5. That is because, conceptually, there are still five wires contained in this bus, or bundle. The fifth wire just happens to contain a vector signal.


Line formats in Simulink

You can instruct the Simulink model to display vector and matrix signals with a different line format by checking the Wide nonscalar lines command in the model's Format menu.)

With this option checked, scalar and vector/matrix signals are drawn with different line formats, as explained below.

sldemo1_fig3.gif (1124 bytes)

The example above provides you with two pieces of information.

  1. The wide line indicates that the signal is not a scalar.
  2. The number above the line indicates that the signal is a vector, or 1-dimensional array, containing two elements.

Matrix signals in Simulink

By default, the signals in your Simulink diagram are 1-dimensional vectors. You can, however, introduce 2-dimensional matrices into your diagram. To demonstrate this, change the Sine Wave block so it outputs a matrix signals instead of the vector you previously entered.

To do this, open Sine Wave block by double clicking on the block. At the bottom of the dialog (and on the bottom of all Source block dialogs) you'll see the Interpret vector parameters as 1-D check box.

To illustrate this, make the output of the Sine Wave 2-dimensional using the following steps.

  1. Uncheck the Interpret vector parameters as1-D check box (If you haven't already, make sure to change the Amplitude to the vector [1 2].)
  2. Apply the changes and close the dialog by clicking the OK button.
  3. Update the Simulink diagram to see the changes take effect in the signal dimension labels.

Notice that the output signal of the Sine Wave block is now labeled "[1x2]". Simulink is actually carrying a 2-D matrix signal along that line!  Again, the input signal to the Bus Selector block still has a width of 5, but the fifth wire contains a matrix signal.

You can enter any 2-dimensional matrix into the Source blocks. To enter a 2x2 matrix, for example, open the Sine Wave block dialog, enter [1 2; 3 4] in the Amplitude parameter, and update the diagram, the signal coming out of the block now has the dimensions [2x2].

Note: When you enter an m-by-n matrix where neither m nor n is one, the block's output will always be a matrix regardless of the current state of the Interpret vector parameters as 1-D check box. The check box only applies to vector parameters, where either m or n is one.


Using the Bus Selector Block

The output of the Mux block still has a width of five, where the last element is the matrix signal you previously entered. To illustrate this, you can configure the Bus Selector block to output the matrix signal from the Sine Wave block. To do this, first  open the Bus Selector block by double clicking on the block.

Use the following steps to change the contents of the signal list to the Pulse and Sine signals.

  1. Highlight the Chirp signal in the Selected signals list and remove it by pressing the Remove button to the left of the list.
  2. Highlight the Sine signal in the Signals in the bus list and add it to the Selected signals by pressing the Select>> button underneath the Signals in the bus list.
  3. Apply the changes and close the dialog by clicking the OK button.

Now, run the simulation. The bottom axes on the Scope displays the four signals from the Sine Wave block.

Note: The labels for the signal name and signal dimension may overlap on the bottom line feeding into the Scope block. If this is the case, just hold the left mouse button down on the signal name while dragging it to another location on the line. Then, you should see that a [2x2] signal feeds into the second input.


Interesting feature: hilite_system

Various blocks in the Simulink diagram highlighted when you clicked some of the links in this demonstration. This was done using the new hilite_system function. The syntax is hilite_system(sys) where sys is the name of the block you want to highlight. There are a variety of different highlighting schemes, which you can find by looking at the help text for this command. Here are a few samples that highlight the Sine Wave block.

Close the Bus block demonstration Simulink Model