📖 Scenario: You are working on a Simulink model for a simple control system. You want to create a clean and user-friendly interface for a subsystem by using a mask. This will help you hide the internal details and only show the important parameters to the user.
🎯 Goal: Create a masked subsystem in Simulink that takes two inputs, adds them, and allows the user to set a gain parameter through the mask. The output should be the sum of the inputs multiplied by the gain.
📋 What You'll Learn
Create a subsystem block named AdderSubsystem with two input ports and one output port.
Add an Add block inside the subsystem to sum the two inputs.
Add a Gain block inside the subsystem to multiply the sum by a gain.
Create a mask for the subsystem with a parameter named GainValue.
Link the GainValue mask parameter to the gain block's gain parameter.
Test the subsystem with inputs 3 and 5 and GainValue set to 2.
💡 Why This Matters
🌍 Real World
Masked subsystems help engineers create reusable and user-friendly components in complex Simulink models, hiding complexity and exposing only necessary controls.
💼 Career
Understanding subsystem masking is essential for control system engineers and model-based designers to build clean, maintainable, and scalable Simulink models.
Progress0 / 4 steps
1
Create the Subsystem with Inputs and Output
In Simulink, create a new subsystem block named AdderSubsystem. Inside it, add two input ports named In1 and In2, and one output port named Out1. Connect the input ports to the output port directly for now.
Simulink
Hint
Use the Simulink library to add Inport and Outport blocks inside the subsystem. Name them exactly as In1, In2, and Out1.
2
Add Add and Gain Blocks Inside the Subsystem
Inside the AdderSubsystem, add an Add block to sum the two inputs In1 and In2. Then add a Gain block to multiply the sum. Connect the Add block output to the Gain block input, and connect the Gain block output to the Out1 port.
Simulink
Hint
Use the Add block to sum inputs and the Gain block to multiply the sum. Connect them properly inside the subsystem.
3
Create a Mask with Gain Parameter
Create a mask for the AdderSubsystem. Add a mask parameter named GainValue of type edit. Link this GainValue parameter to the Gain block's gain parameter inside the subsystem.
Simulink
Hint
Right-click the subsystem and select Mask > Create Mask. Add a parameter named GainValue and set its type to edit. Then, in the mask editor, link this parameter to the Gain block's gain parameter.
4
Test the Masked Subsystem Output
Set the GainValue parameter of the AdderSubsystem mask to 2. Provide inputs 3 and 5 to the subsystem. Run the simulation and print the output value.
Simulink
Hint
Calculate the output as (3 + 5) * 2 = 16 and print it.
Practice
(1/5)
1. What is the main purpose of masking a subsystem in Simulink?
easy
A. To automatically generate code
B. To hide the internal details and provide a simple interface
C. To increase the simulation speed
D. To change the solver settings
Solution
Step 1: Understand what masking does
Masking a subsystem hides its internal blocks and connections from the user.
Step 2: Identify the main benefit
This makes the subsystem easier to use by showing only relevant parameters and controls.
Final Answer:
To hide the internal details and provide a simple interface -> Option B
Quick Check:
Masking = Hide complexity [OK]
Hint: Masking simplifies subsystems by hiding details [OK]
Common Mistakes:
Thinking masking speeds up simulation
Confusing masking with code generation
Assuming masking changes solver settings
2. Which of the following is the correct way to add a mask parameter in Simulink?
easy
A. Drag parameter block inside subsystem
B. Double-click subsystem > Add block > Parameter
C. Right-click subsystem > Properties > Add parameter
But the internal Compare block's threshold does not update. What is the likely error?
medium
A. The Compare block does not have a 'Threshold' parameter
B. The internal block parameter name is incorrect; it should be 'RelationalOperator'
C. The initialization code is missing a conversion from string to number
D. The mask parameter name 'Threshold' is misspelled in the code
Solution
Step 1: Check internal block parameter names
The Compare block in Simulink does not have a parameter named 'Threshold'; it uses 'RelationalOperator' and inputs for comparison.
Step 2: Identify why setting 'Threshold' fails
Since 'Threshold' is not a valid parameter, set_param silently fails or has no effect.
Final Answer:
The Compare block does not have a 'Threshold' parameter -> Option A
Quick Check:
Block parameters must match internal block's actual names [OK]
Hint: Verify internal block parameter names before setting [OK]
Common Mistakes:
Assuming all mask parameters map directly to internal block parameters
Not checking block documentation for parameter names
Ignoring type conversions when needed
5. You want to create a masked subsystem that lets users select a filter type ('Lowpass', 'Highpass') and set a cutoff frequency. Which approach correctly connects mask parameters to internal blocks?
hard
A. Create separate subsystems for each filter type without masking
B. Add only numeric mask parameters and manually change internal blocks after simulation
C. Add popup mask parameter for filter type, numeric parameter for cutoff, then in init code set internal blocks' parameters accordingly
D. Use mask initialization code to change the mask parameters dynamically during simulation
Solution
Step 1: Design mask parameters for user input
Use a popup parameter for filter type and a numeric parameter for cutoff frequency to simplify user choices.
Step 2: Use initialization code to update internal blocks
In the mask initialization code, read these parameters and set the internal filter blocks' types and cutoff frequencies accordingly.
Final Answer:
Add popup mask parameter for filter type, numeric parameter for cutoff, then in init code set internal blocks' parameters accordingly -> Option C