bab13 - the signal routing library

Upload: cakmad69

Post on 01-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 BAB13 - The Signal Routing Library

    1/19

    Introduction to Simulink with Engineering Applications 13−1Copyright © Orchard Publications

    Chapter 13

    The Signal Routing Library

    his chapter is an introduction to the Signal Routing library. This is the twelfth library inthe Simulink group of libraries and consists of two sub-libraries, the Signal Routing GroupSub−Library, and the Signal Storage & Access Group Sub−Library blocks shown below.

    We will describe the function of each block included in this library and we will perform simula-tion examples to illustrate their application.

     

  • 8/9/2019 BAB13 - The Signal Routing Library

    2/19

    Chapter 13 The Signal Routing Library

    13−2  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    13.1 Signal Routing Group Sub−Library

    The Signal Routing Group Sub-Library contains the fifteen blocks described in Subsections13.1.1 through 13.1.15 below.

    13.1.1 The Bus Creator Block

    The Bus Creator block combines a set of signals into a group of signals represented by a singleline. This block is described in Section 2.6, Chapter 2, Page 2−7.

    13.1.2 The Bus Selector Block

    The Bus Selector block outputs a specified subset of the elements of the bus at its input. Thisblock is described in Section 2.6, Chapter 2, Page 2−7.

    13.1.3 The Bus Assignment Block

    The Bus Assignment block assigns values, specified by signals connected to its assignment (:=)input ports, to specified elements of the bus connected to its Bus input port. We use the block'sdialog box to specify the bus elements to be assigned values. The block displays an assignmentinput port for each bus element to be assigned a signal.

    In the Function Block Parameters dialog box, the Signals in the bus displays the names of the sig-

    nals contained by the bus at the block's Bus input port. We can click any item in the list to selectit. To find the source of the selected signal, we click the adjacent Find button. Simulink opens thesubsystem containing the signal source, if necessary, and highlights the source's icon. We use theSelect button to move the currently selected signal into the adjacent list of signals to be assignedvalues (see Signals that are being assigned below). To refresh the display (e.g., to reflect modifica-tions to the bus connected to the block), we click the adjacent Refresh button.

  • 8/9/2019 BAB13 - The Signal Routing Library

    3/19

    Introduction to Simulink with Engineering Applications 13−3Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    In the Function Block Parameters dialog box, the Signals that are being assigned lists the namesof bus elements to be assigned values. This block displays an assignment input port for each buselement in this list. The label of the corresponding input port contains the name of the element.We can re-order the signals by using the Up, Down, and Remove buttons. Port connectivity ismaintained when the signal order is changed.

    Occasionally, we may see three question marks (???) before the name of a bus element. This indi-cates that the input bus no longer contains an element of that name, for example, because the bushas changed since the last time we refreshed the Bus Assignment block's input and bus elementassignment lists. We can fix the problem either by modifying the bus to include a signal of thespecified name, or by removing the name from the list of bus elements to be assigned values.

     Example 13.1

    We begin with the model 13.1. Initially, the Bus Assignment 1 block appears with two inputs, one

    for the block's Bus input port, and the other which serves as the assignment input port for eachbus element to be assigned a signal. We double−click on this block and we configure the FunctionBlock Parameters as shown in Figure 13.2. We output waveforms are shown in Figure 13.3.

    Figure 13.1. Model for Example 13.1

    Next, suppose that we wish to replace the Square Wave Generator 1 block and the SawtoothWave Generator 1 block with a Random Wave Generator block and a Band-Limited White Noiseblock. Instead of replacing the blocks, we add the Random Wave Generator block and the Band-

    Limited White Noise block as shown in Figure 13.4, we double−

    click on the Bus Assignmentblock, and we use the Select button to move the currently selected signal into the adjacent list of signals to be assigned values. To refresh the display, we click the adjacent Refresh button, and theFunction Block Parameters dialog box now appears as shown in Figure 13.5. When this is done,the output waveforms appear as shown in Figure 13.6.

  • 8/9/2019 BAB13 - The Signal Routing Library

    4/19

    Chapter 13 The Signal Routing Library

    13−4  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 13.2. Configuration of the Function Block Parameters for the Bus Assignment Block in Figure 13.1

    Figure 13.3. Output waveforms for the model of Figure 13.1

    Figure 13.4. Modified model for Example 13.1

  • 8/9/2019 BAB13 - The Signal Routing Library

    5/19

    Introduction to Simulink with Engineering Applications 13−5Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    Figure 13.5. Configuration of the Function Block Parameters for the Bus Assignment Block in Figure 13.4

    Figure 13.6. Output waveforms for the model of Figure 13.4

    13.1.4 The Mux Block

    The Mux block combines its inputs into a single output. An input can be a scalar, vector, ormatrix signal. This block is described in Section 2.7, Chapter 2, Page 2−11.

    13.1.5 The Demux Block

    The Demux block extracts the components of an input signal and outputs the components asseparate signals. This block is described in Section 2.7, Chapter 2, Page 2−11.

  • 8/9/2019 BAB13 - The Signal Routing Library

    6/19

    Chapter 13 The Signal Routing Library

    13−6  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    13.1.6 The Selector Block

    The Selector block generates as output selected elements of an input vector or matrix. If theinput type is vector, the block outputs a vector of selected elements specified by element indices.The meaning of the indices depends on the setting of the Index mode parameter. If the setting isOne−based (the default), the index of the first input element is 1, the second 2, and so on. If thesetting is Zero−based, the index of the first element is 0, the second element 1, and so on.

    If the input type is matrix, the Selector block outputs a matrix of elements selected from the inputmatrix. The block determines the row and column indices of the elements to select either from itsRows and Columns parameters or from external signals. We set the block's Source of row indices

    and Source of column indices to the source that we choose (internal or external). If we set eithersource to external, the block adds an input port for the external indices signal. If we set bothsources to external, the block adds two input ports.

     Example 13.2

    For the model of Figure 13.7, the elements of the matrix in the Constant

    block are specified in MATLAB’s Command Window as:

    a11=2; a12=−1; a13=0; a14=−3;...

    a21=−1; a22=1; a23=0; a24=−1;...a31=4; a32=0; a33=3; a34=−2;...

    a41=−3; a42=0; a43=0; a44=1;

    Figure 13.7. Model for Example 13.2

    The Display block shows the cofactor of defined as , where the index denotes

    the row, the index denotes the column, and is the minor of the element .

    In the Selector block Function Block Parameters dialog box we specified the parameters as fol-lows:

    Input type: Matrix

    a11 a12   …a44,,   4 4×

    a11   1–( )i j+ Mij[ ]   i

    ith jth   M    aij

  • 8/9/2019 BAB13 - The Signal Routing Library

    7/19

    Introduction to Simulink with Engineering Applications 13−7Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    Index mode: One−based

    Source of row indices: Internal

    Rows: [2 3 4]

    Source of column indices: Internal

    Columns: [2 3 4]

    13.1.7 The Index Vector Block

    The Index Vector block switches the output between different inputs based on the value of the

    first input, referred to as the Control Input. This block is an implementation of the MultiportSwitch block which is described in Subsection 13.1.11, this chapter, Page 13−10.

     Example 13.3

    For the Index Vector block in Figure 13.8, the parameters are specified as Number of inputs 2,and the Use zero−based indexing box is unchecked. All other parameters are left in their defaultstate. Since the Control Input is specified as 2, the Index Vector block outputs the value of DataInput 2.

    Figure 13.8. Model for Example 13.3

  • 8/9/2019 BAB13 - The Signal Routing Library

    8/19

    Chapter 13 The Signal Routing Library

    13−8  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    13.1.8 The Merge Block

    The Merge block combines its inputs into a single output line whose value at any time is equal tothe most recently computed output of its driving blocks. We can specify any number of inputs bysetting the block's Number of inputs parameter. This block is useful in creating alternately execut-ing subsystems as illustrated by the example below.

     Example 13.4

    The Enable Subsystem 1 and 2 blocks in the model of Figure 13.9 are specified as shown in Figure

    13.10. This model outputs the half −wave rectification* waveform shown in Figure 13.11.

    Figure 13.9. Model for Example 13.4

    Figure 13.10. Configuration of the Enabled Subsystem 1 and 2 blocks in Figure 13.9

    * For the creation of a full−wave rectification waveform, please refer to the Help menus for the Merge block andclick on the “Creating Alternately Executing Subsystems” link. Full

    -wave rectifiers are used in the conversion

     from AC to DC signals. For a detailed discussion, please refer to Signals & Systems with MATLAB Applica-tions, ISBN 0−9709511−6−7.

  • 8/9/2019 BAB13 - The Signal Routing Library

    9/19

    Introduction to Simulink with Engineering Applications 13−9Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    Figure 13.11. Waveforms for the model of Figure 13.9

    13.1.9 The Environmental Controller Block

    The Environmental Controller block outputs the signal at its Sim port only if the model that

    contains it is being simulated. It outputs the signal at its Real−Time Workshop* (RTW) port onlyif code is being generated from the model.

    13.1.10 The Manual Switch Block

    The Manual Switch block is a toggle switch that selects one of its two inputs to pass through tothe output. There is no dialog box for this block; to toggle between inputs, we double-click theblock. The block retains its current state when the model is saved.

     Example 13.5In Figure 13.12, the matrix is defined in MATLAB’s Command Window as

    A=[1 2 −3; 2 −4 2; −1 2 −6];

    * Real−Time Workshop is an extension of MATLAB and Simulink capabilities that generates source code fromSimulink models to create real−time software applications. We will not discuss source code generation in thistext. Examples are provided in the “Real−Time Workshop For Use with Simulink” documentation.

    A

  • 8/9/2019 BAB13 - The Signal Routing Library

    10/19

    Chapter 13 The Signal Routing Library

    13−10  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 13.12. Model for Example 13.5

    The MATLAB function in the block’s parameters dialog box is specified as inv (for matrix inver-sion), and when the Switch block is as shown in the upper model of Figure 13.5, we execute thesimulation command, Display 1 block shows the elements of the matrix. When we double−clickon the Switch block, it changes to the position shown in the lower model of Figure 13.5, andwhen we issue the simulation command, Display 2 block shows the elements of the invertedmatrix.

    13.1.11 The Multiport Switch Block

    The Multiport Switch block chooses between a number of inputs. The first (top) input is calledthe control input, while the rest of the inputs are called data inputs. The value of the controlinput determines which data input is passed through to the output port. If the control input is aninteger value, the specified data input is passed through to the output. For example, if the one−

    based indexing parameter is selected and the control input is 1, the first data input is passedthrough to the output. If the control input is 2, the second data input is passed through to theoutput, and so on.

     Example 13.6

    The model of Figure 13.3 outputs the value corresponding to the control input value .64 4

  • 8/9/2019 BAB13 - The Signal Routing Library

    11/19

    Introduction to Simulink with Engineering Applications 13−11Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    Figure 13.13. Model for Example 13.6

    13.1.12 The Switch Block

    The Switch block outputs the first (top) input or the third (bottom) input depending on the valueof the second (middle) input. The first and third inputs are the data inputs. The second input isthe control input. This block is described in Section 2.8, Chapter 2, Page 2−14.

    13.1.13 The From Block

    The From block accepts a signal from a corresponding Goto block which is described in Subsec-tion 13.1.15, this chapter, Page 13−13, and passes it as output. The visibility of a Goto block tagdetermines the From blocks that can receive its signal.

     Example 13.7

    In Figure 13.14, the matrix is defined in MATLAB’s Command Window as

    A=[1 2 −3; 2 −4 2; −1 2 −6];

    In the upper model of Figure 13.14, the Display 1 block shows the elements of matrix . In the

    lower model of Figure 13.14, the Constant 2 block sends the elements of matrix to the Goto

    block, it is accepted by the From block, and outputs it to the Display 1 block.

    The upper and lower models in Figure 13.14 are equivalent. As we can see, the From and Gotoblocks allow us to pass a signal from one block to another without a physical connection.

    A

    A

    A

  • 8/9/2019 BAB13 - The Signal Routing Library

    12/19

    Chapter 13 The Signal Routing Library

    13−12  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 13.14. Models for Example 13.7

    To associate a Goto block with a From block, we enter the Goto block's tag in the Goto Tagparameter. A From block can receive its signal from only one Goto block, although a Goto block

    can pass its signal to more than one From block.13.1.14 The Goto Tag Visibility Block

    The Goto Tag Visibility block defines the accessibility of Goto block tags that have scoped visi-bility. The tag specified as the Goto tag parameter is accessible by From blocks in the same sub-system that contains the Goto Tag Visibility block and in subsystems below it in the model hierar-

    chy. A Goto Tag Visibility block is required for Goto blocks whose Tag visibility parameter valueis specified as scoped. No Goto Tag Visibility block is needed if the tag visibility is either local orglobal. When scoped, the block shows the tag name enclosed in braces ({}).

     Example 13.8

    The model in Figure 13.15, is the same as that of in Figure 13.14, except that it includes the GotoTag Visibility Tag block.

    Figure 13.15. Model for Example 13.8

  • 8/9/2019 BAB13 - The Signal Routing Library

    13/19

    Introduction to Simulink with Engineering Applications 13−13Copyright © Orchard Publications

    Signal Routing Group Sub−Library

    As indicated, in Figure 13.15, the Goto Tag Visibility block has no input and no output but itmust be included whenever the visibility is specified as scoped. Since the tag visibility is specifiedas scoped, the Goto Tag Visibility block is shown in the model with the tag name enclosed inbraces ({}).

    13.1.15 The Goto Block

    The Goto block passes its input to its corresponding From blocks. From and Goto blocks allow usto pass a signal from one block to another without actually connecting them. A Goto block canpass its input signal to more than one From block, although a From block can receive a signalfrom only one Goto block. The input to that Goto block is passed to the From blocks associated

    with it as though the blocks were physically connected. Goto blocks and From blocks are matchedby the use of Goto tags, defined in the Tag parameter. The Tag visibility parameter determineswhether the location of From blocks that access the signal is limited. The three options are:

    1.   Local, the default, means that From and Goto blocks using the same tag must be in the samesubsystem. A local tag name is enclosed in brackets ([]).

    2.   Global means that From and Goto blocks using the same tag can be anywhere in the modelexcept in locations that span nonvirtual subsystem boundaries. The rule that From-Goto blockconnections cannot cross nonvirtual subsystem boundaries has the following exception. AGoto block connected to a state port in one conditionally executed subsystem is visible to aFrom block inside another conditionally executed subsystem. A global tag name is notenclosed.

    3.   Scoped means that From and Goto blocks using the same tag must be in the same subsystemor at any level in the model hierarchy below the Goto Tag Visibility block that does not entailcrossing a nonvirtual subsystem boundary, i.e., the boundary of an atomic, conditionally exe-cuted, or function-call subsystem or a model reference. A scoped tag name is enclosed inbraces ({}).

     Example 13.9

    The upper and lower models in Figure 13.16, are equivalent and thus both Scope 1 and Scope 2blocks display the same waveform shown in Figure 13.17.

  • 8/9/2019 BAB13 - The Signal Routing Library

    14/19

    Chapter 13 The Signal Routing Library

    13−14  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 13.16. Model for Example 13.9

    Figure 13.17. Waveform displayed in Scope 1 and Scope 2 blocks in Figure 13.16

    13.2 The Signal Storage and Access Group Sub−Library

    Data stores are signals that are accessible at any point in a model hierarchy at or below the levelin which they are defined. Because they are accessible across model levels, data stores allow sub-systems and model references to share data without having to use I/O ports to pass the data fromlevel to level. The Signal Storage and Access Group Sub−Library contains the three blocksdescribed in Subsections 13.2.1 through 13.2.3 below.

    13.2.1 The Data Store Read Block

    The Data Store Read block copies data from the named data store to its output. The data storefrom which the data is read is determined by the location of the Data Store Memory block or sig-nal object that defines the data store. More than one Data Store Read block can read from thesame data store. For more information, please refer to Working with Data Stores and Data StoreMemory in Help menu for this block. An example is presented in Subsection 13.2.3, this chapter,Page 13−15.

  • 8/9/2019 BAB13 - The Signal Routing Library

    15/19

    Introduction to Simulink with Engineering Applications 13−15Copyright © Orchard Publications

    The Signal Storage and Access Group Sub−Library

    13.2.2 The Data Store Memory Block

    The Data Store Memory block defines and initializes a named shared data store, which is a mem-ory region usable by Data Store Read and Data Store Write blocks with the same data store name.The location of the Data Store Memory block that defines a data store determines the Data StoreRead and Data Store Write blocks that can access the data store:

    1. If the Data Store Memory block is in the top-level system, the data store can be accessed byData Store Read and Data Store Write blocks located anywhere in the model.

    2. If the Data Store Memory block is in a subsystem, the data store can be accessed by Data StoreRead and Data Store Write blocks located in the same subsystem or in any subsystem below itin the model hierarchy.

    An example is presented in Subsection 13.2.3 below.

    13.2.3 The Data Store Write Block

    The Data Store Write block copies the value at its input to the named data store. Each write

    operation performed by a Data Store Write block writes over the data store, replacing the previ-ous contents. The data store to which this block writes is determined by the location of the DataStore Memory or signal object that defines the data store. More than one Data Store Write blockcan write to the same data store.

     Example 13.10

    In this example, we will create a model that will alternately will display the outputs of a low−pass

    filter and a high−pass filter whose transfer functions are , and respectively,

    when the input is the step function.

    We begin with a new model, we drag two Data Store Memory blocks into it, and for the first wedefine the name lpfilter, and for the second the name hpfilter as shown in Figure 13.18. Then, wedrag two Step blocks, two Transfer Fcn blocks, two Gain blocks, two Data Store Write blocks,and two Scope blocks into the same model, we connect them as shown, and to the first Data StoreWrite block we assign the name lpfilter, and to the second the name hpfilter as shown in Figure13.18.

    1 s 1+( ) ⁄    s s 1+( ) ⁄ 

  • 8/9/2019 BAB13 - The Signal Routing Library

    16/19

    Chapter 13 The Signal Routing Library

    13−16  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    Figure 13.18. Initial model for Example 13.10

    Next, we select the Transfer Fcn 1, Gain 1, and Data Store 1 blocks by enclosing them in abounding box around them, we choose Create Subsystem from the Edit menu. We label this sub-

    system as Subsystem 1. We repeat for the Transfer Fcn 2, Gain 2, and Data Store 2 blocks, and welabel this subsystem as Subsystem 2. The model is now as shown in Figure 13.19, after reshapingand renaming the subsystem blocks.

    Figure 13.19. Modified model for Example 13.10

    Now, we revise the model of Figure 13.19 by adding the Manual Switch block as shown in Figure13.20 so that we can switch between Subsystem 1 for the low−pass filter, and Subsystem 2 for thehigh−pass filter to observe their waveforms shown in Figures 13.21 and 13.22 respectively.

    Figure 13.20. The model of Example 13.10 in its final form

  • 8/9/2019 BAB13 - The Signal Routing Library

    17/19

    Introduction to Simulink with Engineering Applications 13−17Copyright © Orchard Publications

    The Signal Storage and Access Group Sub−Library

    Figure 13.21. Waveform of the output of Subsystem 1 (Low-pass filter with Gain = 1.5)

    Figure 13.22. Waveform of the output of Subsystem 2 (High-pass filter with Gain = 1.5)

    In Example 13.10 we illustrated the use of the Data Store Memory block and the Data StoreWrite block. The use of the Data Store Read block is illustrated in Figure 13.23.

     Figure 13.23. Models to illustrate the use of the Data Store Read block

    The Scope 1 and Scope 2 blocks in Figure 13.23 display the same waveforms as those in Figure13.21 and Figure 13.22.

  • 8/9/2019 BAB13 - The Signal Routing Library

    18/19

    Chapter 13 The Signal Routing Library

    13−18  Introduction to Simulink with Engineering Applications  Copyright © Orchard Publications

    13.3 Summary

    • The Bus Creator block combines a set of signals into a group of signals represented by a singleline.

    • The Bus Selector block outputs a specified subset of the elements of the bus at its input.

    • The  Bus Assignment block assigns values, specified by signals connected to its assignment(:=) input ports, to specified elements of the bus connected to its Bus input port.

    • The Mux block combines its inputs into a single output. An input can be a scalar, vector, ormatrix signal.

    • The Demux block extracts the components of an input signal and outputs the components asseparate signals.

    • The Selector block generates as output selected elements of an input vector or matrix. If the

    input type is vector, the block outputs a vector of selected elements specified by element indi-ces. If the input type is matrix, the Selector block outputs a matrix of elements selected fromthe input matrix.

    • The Index Vector block switches the output between different inputs based on the value of the first input, referred to as the Control Input. This block is an implementation of the Multi-port Switch block.

    • The Merge block combines its inputs into a single output line whose value at any time is equalto the most recently computed output of its driving blocks. We can specify any number of inputs by setting the block's Number of inputs parameter.

    • The Environmental Controller block outputs the signal at its Sim port only if the model thatcontains it is being simulated. It outputs the signal at its Real−Time Workshop (RTW) portonly if code is being generated from the model.

    • The Manual Switch block is a toggle switch that selects one of its two inputs to pass throughto the output. There is no dialog box for this block; to toggle between inputs, we double-clickthe block. The block retains its current state when the model is saved.

    • The Multiport Switch  block chooses between a number of inputs. The first (top) input iscalled the control input, while the rest of the inputs are called data inputs. The value of the

    control input determines which data input is passed through to the output port.• The Switch block outputs the first (top) input or the third (bottom) input depending on the

    value of the second (middle) input. The first and third inputs are the data inputs. The secondinput is the control input.

    • The From block accepts a signal from a corresponding Goto block, then passes it as output.

  • 8/9/2019 BAB13 - The Signal Routing Library

    19/19

    Introduction to Simulink with Engineering Applications 13 19

    Summary

    • The Goto Tag Visibility block defines the accessibility of Goto block tags that have scopedvisibility.

    • The Goto block passes its input to its corresponding From blocks.

    • The Data Store Read block copies data from the named data store to its output. The data

    store from which the data is read is determined by the location of the Data Store Memoryblock or signal object that defines the data store.

    • The Data Store Memory block defines and initializes a named shared data store, which is amemory region usable by Data Store Read and Data Store Write blocks with the same datastore name.

    • The Data Store Write block copies the value at its input to the named data store. Each writeoperation performed by a Data Store Write block writes over the data store, replacing the pre-vious contents.