Main Content

Manage Signal Lines

As a model grows, model components help functionally and visually organize blocks in the model. To similarly organize signal lines in the model, you can apply a variety of strategies, such as grouping signals into buses.

To demonstrate how to reduce signal line clutter, this example implements a plant with multiple sensors and actuators. The plant contains two identical mass-spring-damper systems. A beam connects the two masses.

Diagram of two identical mass, spring, damper systems with the masses connected

Sensors read the displacement of the masses. The controller regulates the height at the center of the beam x and levels the beam by computing the force the actuators must apply to the masses. The controller uses the height difference between the beam ends, delta, to level the beam.

The model named BasicModelingSignals represents the plant and its environment, operator, and controller.

mdl0 = "BasicModelingSignals";
open_system(mdl0);

Model with many signal lines

To display signals after simulation, the model uses two Scope blocks. One Scope block shows the goal and actual beam levelness. The other Scope block shows the goal and actual position of the beam at its center, along with the actual beam position at both ends.

sim(mdl0);

Simulation results for delta and delta_goal

Simulation results for x, x1, x2, and x_goal

Mark Signals for Logging

To reduce the number of signal lines, you can connect a viewer directly to signal lines or enable data logging for signal lines. By choosing a way to visualize simulation data without using a sink block, you can avoid extra signal lines.

The model named BasicModelingLogging removes the Scope blocks and related signal lines then enables data logging for those signals.

mdl1 = "BasicModelingLogging";
open_system(mdl1);

Model without Scope blocks and related lines

In the Operator subsystem, the signals labeled x_goal and delta_goal are marked for logging, as indicated by the icon that appears above each signal.

Operator subsystem with logging icons above x_goal and delta_goal

In the Controller subsystem, the signals labeled x and delta are marked for logging.

Controller subsystem with logging icons above x and delta

In the Plant subsystem, the signals labeled x1 and x2 are marked for logging.

Plant subsystem with logging icons above x1 and x2

The Simulation Data Inspector lets you view the logged signal data after simulation.

sim(mdl1);

Simulation results in the Simulation Data Inspector with one plot for x, x1, x2, and x_goal and another plot for delta and delta_goal

Group Signals in Buses

To further reduce the number of signal lines, you can group signal lines into a bus by using a Bus Creator or Out Bus Element block. All signal lines retain their identities when grouped in a bus and can be separated downstream from the bus.

By creating buses, the model named BasicModelingBuses provides an even more readable system representation. To view the bus line style, compile the model.

mdl2 = "BasicModelingBuses";
open_system(mdl2);
set_param(mdl2,SimulationCommand="Update");

Model with bus input and output for each subsystem

This model enables data logging for the signal lines associated with the buses named sensor and goal instead of logging data individually for each of the signals in these buses.

The simulation results remain the same after the signals are grouped in buses.

sim(mdl2);

Simulation results in the Simulation Data Inspector with signals grouped by bus but individually selected

Related Topics