Simulink and an Algebraic Loop

By Joel Benway, DISTek Integration, Inc.

Model-based design can shift many design tasks from the lab and field to a computer monitor, increasing the ease and speed of development; however, this shift can also present challenges that do not exist in the real world. Algebraic loops are an example of these challenges. In a mathematical model created in Mathworks Simulink®, an algebraic loop occurs when an input and output have a circular dependency, i.e., they are dependent on each other at the exact same time which introduces something of a “chicken or the egg” dilemma for Simulink to solve (see fig. 1).

                                  a simple algebraic loop
                                                                Figure 1: A simple algebraic loop

Simulink detects these situations and can compute the correct result by using more computing cycles on the problem iteratively. The pictured example is simple enough for Simulink to resolve that y(t) = u(t) – y(t), but not all algebraic loops can be solved. Those that can be solved not only take an unacceptable amount of time, but also cause errors while generating code. It would be difficult to describe a loop like this in C code. This method is not a recommended way of modeling, and the algebraic loops should be removed.

One way to clean the algebraic loops out of a model is to drop a discrete delay (see fig. 2), like a unit delay, in the loop such that the feedback is decoupled from the output using the last value as the new value during computation, i.e., y(t)=u(t)-y(t-1). This process is an intuitive way to solve an algebraic loop and is usually the intent of the user.

                                   removing an algebraic loop
                                                    Figure 2: A unit delay removing an algebraic loop

For a more complex model, say one with both global and local feedback that causes multiple algebraic loops, a single unit delay can get the job done if it is placed in the signal path where it will break up both loops at once. One issue with using a unit delay to solve an algebraic loop is that the time loop is no longer continuous, instead, it uses discrete time steps. This solution is not acceptable for all systems so a different approach may be more appropriate.

 rate transition remove loop

                                                                 Figure 3: Using a rate transition as a unit delay to remove an algebraic loop


The model shown above (see fig. 3) uses a unit delay block to act as a motor or actuator, decoupling the output of the control subsystem from the input of the plant model as with the unit delay to prevent an algebraic loop. A better option here is a transfer function block to model the actuator, which would keep the signal continuous for low latency (see fig. 4).

transfer function remove loop

                                                           Figure 4: Improved model using a transfer function to remove an algebraic loop

The difference can be visualized by plotting these two actuator outputs on the same scope (see fig. 5). Both can remove the algebraic loop in this model but a transfer function creates a continuous output to the plant model. This change could be important for some systems. For example, a plant model may require that the derivative of an input is continuous. Every model is a simplification of the real world but the presence of an algebraic loop is a sign that a model requires additional dynamics. Each algebraic loop should be approached with a thoughtful solution tailored to preserve the correct fidelity of the model.

                                continuous and discreet signal loop
                                 Figure 5: Comparison of a continuous time signal loop and discrete time signal loop

For more information, see our white paper titled: Modeling & Simulation in Embedded Systems for Off-Highway Vehicles.

Joel Benway
MBSD Engineer
6612 Chancellor Drive, Ste. 600
Cedar Falls, IA 50613
Tel: 319-859-3639
Joel.Benway@DISTek.com

 

 

Featured DISTek Expert

Name:

Ed

Technical Strengths:

Avionics mechanics, systems engineering

Specialty Application Area

BS-Software Engineering, AA-Electronics Engineering, Certified LabVIEW Architect, Certified Professional Instructor, LabVIEW Champion

Past Experience

Avionics mechanics, systems engineering.

DISTek Employee Since:

2001

What I love about my job:

At DISTek, I am part of a variety of different projects, which keeps me constantly learning and applying different practices to new challenges. In addition, I am part of complete processes, from architecting a new test system to implementing it and training customers on their new interface.

Click HERE to become a DISTek EXPERT!