0
0
SimulinkHow-ToBeginner · 4 min read

How to Use Mux and Demux Blocks in Simulink

In Simulink, use the Mux block to combine multiple signals into a single vector signal, and use the Demux block to split a vector signal back into individual signals. Connect these blocks by dragging lines between ports to organize signal flow in your model.
📐

Syntax

The Mux block syntax involves connecting multiple input signals to its input ports, which outputs a single vector signal combining all inputs. The Demux block takes a vector input signal and splits it into multiple output signals, each corresponding to an element of the vector.

Key parts:

  • Mux block: Multiple inputs → One vector output
  • Demux block: One vector input → Multiple outputs
💻

Example

This example shows how to use a Mux block to combine two sine wave signals and then use a Demux block to split them back into separate signals for display.

simulink
1. Open Simulink and create a new model.
2. Add two <code>Sine Wave</code> blocks from the Sources library.
3. Add a <code>Mux</code> block from the Signal Routing library.
4. Connect the outputs of the two <code>Sine Wave</code> blocks to the inputs of the <code>Mux</code> block.
5. Add a <code>Demux</code> block from the Signal Routing library.
6. Connect the output of the <code>Mux</code> block to the input of the <code>Demux</code> block.
7. Add two <code>Scope</code> blocks from the Sinks library.
8. Connect each output of the <code>Demux</code> block to a separate <code>Scope</code> block.
9. Run the simulation to see the two sine waves displayed separately after muxing and demuxing.
Output
Two separate sine wave signals displayed on two scopes, identical to the original signals before muxing.
⚠️

Common Pitfalls

  • Mismatch in number of signals: The Demux block must be configured to output the same number of signals as were combined by the Mux block.
  • Signal dimensions: All inputs to the Mux block must be scalar or vectors of compatible sizes; mixing incompatible sizes causes errors.
  • Incorrect connections: Forgetting to connect all inputs or outputs properly can cause simulation errors or unexpected results.
simulink
/* Wrong way: Demux block outputs fewer signals than Mux inputs */
Mux inputs: 3 signals
Demux outputs: 2 signals

/* Right way: Match outputs to inputs */
Mux inputs: 3 signals
Demux outputs: 3 signals
📊

Quick Reference

BlockPurposeInputOutput
MuxCombine multiple signals into one vectorMultiple signalsSingle vector signal
DemuxSplit vector signal into multiple signalsSingle vector signalMultiple signals

Key Takeaways

Use the Mux block to combine multiple signals into one vector signal.
Use the Demux block to split a vector signal back into individual signals.
Ensure the number of Demux outputs matches the number of Mux inputs.
All signals combined by Mux must have compatible dimensions.
Connect all inputs and outputs properly to avoid simulation errors.