Main Content

connect

Block diagram interconnections of dynamic systems

    Description

    example

    sysc = connect(sys1,...sysN,inputs,outputs) connects the models and block diagram elements sys1,...sysN based on signal names. The connect command interconnects the block diagram elements by connecting input and output channels with matching names, as specified in the InputName and OutputName properties of sys1,...,sysN. The aggregate model sysc is a dynamic system model with inputs and outputs specified by inputs and outputs, respectively.

    example

    sysc = connect(sys1,...sysN,inputs,outputs,APs) inserts an AnalysisPoint at every signal location specified in APs. Use analysis points to mark locations of interest which are internal signals in the aggregate model. For instance, a location at which you want to extract a loop transfer function or measure the stability margins is a location of interest.

    example

    sysc = connect(blksys,connections,inputs,outputs) uses index-based interconnection to build sysc out of an aggregate, unconnected model blksys. The matrix connections specifies how the outputs and inputs of blksys interconnect. For index-based interconnections, inputs and outputs are index vectors that specify which inputs and outputs of blksys are the external inputs and outputs of sysc. This syntax can be convenient when you do not want to assign names to all inputs and outputs of all models to connect. However, in general, it is easier to keep track of named signals.

    sysc = connect(___,opts) builds the interconnected model using additional options, including retaining unconnected states that do not contribute to the dynamics of sysc. To create opts, use connectOptions. You can use opts with the input arguments of any of the previous syntaxes.

    Examples

    collapse all

    Create an aggregate model of the following block diagram from r to y.

    connect1.png

    This model contains a plant G, a feedback controller C, and a feedforward controller F. Create dynamic system models representing each of these elements.

    C = pid(2,1); 
    G = zpk([],[-1,-1,-5],1);
    F = tf(3,[1 3]);

    In preparation for building the block diagram using signal names, assign to each element the input and output names shown in the block diagram. To do so, set the InputName and OutputName properties of the elements.

    C.InputName = "e";  
    C.OutputName = "uc";
    
    G.InputName = "u";  
    G.OutputName = "y";
    
    F.InputName = "r";
    F.OutputName = "uf";

    The block diagram also contains two summing junctions. One summing junction takes the difference between the reference signal r and the plant output y to compute the error signal e. The other summing junction adds the feedforward controller output uf to the feedback controller output uc to compute the plant input u. Use the sumblk command to create these summing junctions. To use sumblk, write the expression for the summing junction as a string.

    S1 = sumblk("e = r - y");
    S2 = sumblk("u = uc + uf");

    sumblk returns a tf model object representing the sum, with the input names and output names you provide in the expression. For instance, examine the signal names of S1.

    S1
    S1 =
     
      From input "r" to output "e":
      1
     
      From input "y" to output "e":
      -1
     
    Static gain.
    

    You can now combine all the elements to create an aggregate model representing the response of the system in the block diagram from r to y. Provide connect with the list of elements to combine, the desired input signal of the aggregate model r, and the desired output signal y. The connect command automatically joins the elements by connecting inputs and outputs with matching names.

    T = connect(G,C,F,S1,S2,"r","y");
    size(T)
    State-space model with 1 outputs, 1 inputs, and 5 states.
    
    T.InputName
    ans = 1x1 cell array
        {'r'}
    
    
    T.OutputName
    ans = 1x1 cell array
        {'y'}
    
    

    Create the control system of the previous example, where G, C, and F are all two-input, two-output models.

    connect1.png

    In this example, the signals r, y, e, and so on are all vector signals of two elements each. First, create the models and name their inputs and outputs.

    C = [pid(2,1), 0;
         0,pid(5,6)];
    F = [tf(3,[1 3]), 0;
         0, tf(3,[1 3])];
    G = ss(-1,[1,2],[1;-1],0);

    Assign the input and output names.

    C.InputName = "e";  
    C.OutputName = "uc";
    
    G.InputName = "u";  
    G.OutputName = "y";
    
    F.InputName = "r";
    F.OutputName = "uf";

    When you assign single names to vector-valued signals, the software automatically applies vector expansion to give each input and output channel a unique name. For instance, examine the names of the plant inputs.

    G.InputName
    ans = 2x1 cell
        {'u(1)'}
        {'u(2)'}
    
    

    This example uses vector expansion for the signal names of all MIMO components of the block diagram. You can instead name the signals individually, provided that you match the names of signals you want to join. For an example that uses individually named signals for some block-diagram elements, see MIMO Control System with Fixed and Tunable Components.

    Next, create the vector-valued summing junction. sumblk also automatically expands the signal names you provide in the sum expression for the vector signals, as you can verify by examining the input names of S2.

    S1 = sumblk("e = r - y",2);
    S2 = sumblk("u = uc + uf",2);
    S2.InputName
    ans = 4x1 cell
        {'uc(1)'}
        {'uc(2)'}
        {'uf(1)'}
        {'uf(2)'}
    
    

    Combine all the elements to create an aggregate model representing the response r to y, that is, from [r(1),r(2)] to [y(1),y(2)].

    T = connect(G,C,F,S1,S2,"r","y");
    size(T)
    State-space model with 2 outputs, 2 inputs, and 5 states.
    
    T.InputName
    ans = 2x1 cell
        {'r(1)'}
        {'r(2)'}
    
    
    T.OutputName
    ans = 2x1 cell
        {'y(1)'}
        {'y(2)'}
    
    

    Consider the following block diagram.

    analysispoint1.png

    You can create a model of this closed-loop system using feedback and use the model to study the system response from r to y. Suppose that you also want to study the response of the closed-loop system to a disturbance injected at the plant input. To do so, you can use connect to build the system, inserting an analysis point at the location u.

    First create plant and controller models, naming the inputs and outputs as shown in the diagram.

    C = pid(2,1); 
    C.InputName = 'e';  
    C.OutputName = 'u';
    
    G = zpk([],[-1,-1],1);
    G.InputName = 'u';  
    G.OutputName = 'y';

    Create a summing junction that takes the difference between the reference signal r and the plant output y to compute the error signal e.

    Sum = sumblk('e = r - y');

    Combine C, G, and the summing junction to create the aggregate model. Use the APs input argument to connect to insert an analysis point at u.

    input = 'r';
    output = 'y';
    APs = 'u';
    CL = connect(G,C,Sum,input,output,APs)
    Generalized continuous-time state-space model with 1 outputs, 1 inputs, 3 states, and the following blocks:
      AnalysisPoints_: Analysis point, 1 channels, 1 occurrences.
    
    Type "ss(CL)" to see the current value and "CL.Blocks" to interact with the blocks.
    

    This closed-loop model is a generalized state-space (genss) model containing an AnalysisPoint control design block. To see the name of the analysis point channel in CL, use getPoints.

    getPoints(CL)
    ans = 1x1 cell array
        {'u'}
    
    

    Inserting the analysis point creates a model that is equivalent to the following block diagram, where AP_u designates the AnalysisPoint block with channel name u.

    FeedbackLoopWithAnalysisPointExample_02.png

    Use the analysis point to extract system responses. For example, the following commands extract the open-loop transfer at u and the closed-loop response at y to a disturbance injected at u.

    L = getLoopTransfer(CL,'u',-1);
    CLdist = getIOTransfer(CL,'u','y');

    You can use index-based interconnection to connect model elements without naming all their inputs and outputs. To see how, create a model of the following feedback loop from r to y using index-based interconnection.

    First, create the plant and controller, the elements of the closed-loop system.

    C = pid(2,1); 
    G = zpk([],[-1,-1,-5],1);

    Use append to group the elements into a single, unconnected aggregate model.

    blksys = append(C,G);

    append arranges the specified models into a MIMO stacked model, as shown in the following diagram.

    blksys.png

    To make this stacked model equivalent to the feedback loop, connect must make the following connections:

    • The input of G receives the output of C, or w1 feeds into u2.

    • The input of C receives the negative of the output of G, or -w2 feeds into -u1.

    To instruct connect to make these connections, construct a matrix in which each row specifies one connection or summing junction in terms of the input vector u and output vector y of blksys.

    connections = [2  1;  %  w1 feeds into u2
                   1 -2]; % -w2 feeds into u1

    Finally, specify by index which inputs and outputs of blksys to use for the external inputs and outputs of the closed-loop model.

    inputs = 1;  % r drives u1
    outputs = 2; % y is y2

    You can now complete the closed-loop model.

    sysc = connect(blksys,connections,inputs,outputs);
    step(sysc)

    Figure contains an axes object. The axes object contains an object of type line. This object represents sysc.

    Input Arguments

    collapse all

    Dynamic system model or other block-diagram element to interconnect, specified as:

    • Any numeric LTI model object, such as a tf, zpk, ss, frd, or pid model object.

    • A generalized or uncertain LTI model, such as a genss, genfrd, uss (Robust Control Toolbox), and ufrd (Robust Control Toolbox) model.

    • A control design block representing a tunable or uncertain block-diagram element, such as a tunablePID, tunableSS, tunableGain, tunableTF, tunableSurface, ultidyn (Robust Control Toolbox), or umargin (Robust Control Toolbox) block.

    • An AnalysisPoint block representing a location in the block diagram at which you want to extract system responses.

    • A summing junction that you create using sumblk.

    • An identified LTI model, such as an idtf (System Identification Toolbox), idss (System Identification Toolbox), or idproc (System Identification Toolbox) model.

    • A sparse model, represented by a sparss or mechss model object.

    • A time-varying or parameter-varying model, represented by an ltvss or lpvss model object.

    Inputs of the combined model, specified as a character vector, cell array of character vectors, string, string vector, positive integer, or vector of positive integers.

    • For name-based interconnection, provide a character vector, string, cell array of character vectors, or string array listing one or more signals that appear in the InputName or OutputName property of one or more of the block diagram elements sys1,...sysN. For example, {'ref','dist','noise'}.

    • For index-based interconnection, provide a positive integer or vector of positive integers specifying the index or indices of the inputs of blksys that you want to be inputs of the aggregate model.

    Outputs of the combined model, specified as a character vector, cell array of character vectors, string, string vector, positive integer, or vector of positive integers.

    • For name-based interconnection, provide a character vector, string, cell array of character vectors, or string array listing one or more signals that appear in the InputName or OutputName property of one or more of the block diagram elements sys1,...sysN. For example, {'ref','dist','noise'}.

    • For index-based interconnection, provide a positive integer or vector of positive integers specifying the index or indices of the inputs of blksys that you want to be outputs of the aggregate model.

    Locations (internal signals) of interest in the aggregate model, specified as a character vector or cell array of character vectors, such as 'X' or {'AP1','AP2'}, or a string or string vector. The resulting model contains an analysis point at each such location. (See AnalysisPoint). Each location in APs must correspond to an entry in the InputName or OutputName property of one or more of the block diagram elements sys1,...sysN.

    Unconnected aggregate model, specified as a dynamic system model that you create with append. Use blksys for index-based interconnection. The append command stacks the inputs and outputs of the elements of your block diagram without making any interconnections between their inputs and outputs. For example, if your block diagram contains dynamic system models C, G, and S, create blksys with the following command:

    blksys = append(C,G,S)

    Then, specify the interconnections between the inputs and outputs of blksys using the connections argument. For an example, see Index-Based Interconnection.

    Connections and summing junctions of the block diagram, specified as a matrix. Use connection for index-based interconnection. Each row of connections specifies one connection or summing junction in terms of the input vector u and output vector w of the unconnected aggregate model blksys. For example, the row

    [3 2 0 0]

    specifies that w(2), the second output of blksys, connects into u(3), the third input of blksys. The row

    [7 2 -15 6]
    

    indicates that the sum w(2) - w(15) + w(6) feeds into u(7), the seventh input of blksys.

    If you do not specify any connection for a particular input or output, connect omits that input or output from the aggregate model.

    Additional options for interconnection, specified as an options set that you create with connectOptions.

    By default, the connect command discards states that do not contribute to the dynamics in the path between the inputs and outputs of the interconnected system. Use connectOptions to retain these states in the interconnected model. This option can be useful, for example, when you want to compute the interconnected system response from known initial state values of the components.

    Output Arguments

    collapse all

    Interconnected system, returned as either a state-space model or frequency-response model. The type of model returned depends on the input models. For example:

    • Interconnecting numeric LTI models (other than frd models) returns an ss model.

    • Interconnecting a numeric LTI model with a Control Design Block returns a generalized state-space model. For instance, interconnecting a tf model with a tunablePID Control Design Block returns a genss model.

    • Interconnecting a numeric LTI model with a sparse model returns a sparse model.

    • Interconnecting any model with a frequency-response data model returns a frequency response data model.

    By default, connect automatically discards states that do not contribute to the I/O transfer function from the specified inputs to the specified outputs of the interconnected model. To retain the unconnected states, set the Simplify option of connectOptions to false. For example:

    opt = connectOptions('Simplify',false);
    sysc = connect(sys1,sys2,sys3,'r','y',opt);

    Version History

    Introduced before R2006a

    expand all