EC-406: Simulation Lab - UNIT 3 SHORT NOTES
3.0 UNIT OVERVIEW & LEARNING OBJECTIVES
-
Purpose: Move beyond basic modeling to advanced hierarchical system design, multi-domain analysis (time/frequency), and performance validation.
-
Key Skills:
-
Building reusable, modular models with subsystems and buses.
-
Configuring solvers for accuracy vs. speed trade-offs.
-
Extracting linear models from complex simulations.
-
Simulating and analyzing control and communication systems.
-
Interpreting results using advanced visualization tools.
-
3.1 ADVANCED SIMULINK MODELING TECHNIQUES
3.1.1 Model Hierarchy & Subsystems
-
Subsystem: A group of blocks represented as a single block. Promotes modularity and readability.
-
Masked Subsystem: A subsystem with a custom icon and dialog box. Allows user to parameterize internal blocks without opening the subsystem.
- Use Case: Creating a reusable "PID Controller" block where user sets
Kp,Ki,Kdvia the mask.
- Use Case: Creating a reusable "PID Controller" block where user sets
-
Model Referencing: A top model references and runs a separate
.slxfile. Changes to the referenced model propagate automatically. Better for large projects than copying subsystems. -
Custom Library: A collection of frequently used masked subsystems/blocks. Drag-and-drop from library browser ensures consistency.
3.1.2 Signal Routing & Bus Management
-
Bus Creator: Combines multiple signals into a bus object (a single composite signal).
-
Bus Selector: Extracts specific signals from a bus.
-
Bus Assignment: Modifies or adds elements to a bus signal.
-
Mux/Demux: Combines/splits signals into vector signals (elements must be of the same data type).
-
Best Practice: Use buses for heterogeneous signals (different types) and mux for homogeneous vectors. Name bus elements clearly for automatic
Bus Selectorpopulation.
3.1.3 Solver Configuration & Simulation Settings
-
Solver Types:
-
Variable-step: Adjusts step size for accuracy (e.g.,
ode45- non-stiff,ode15s- stiff). Good for transient analysis. -
Fixed-step: Constant step size. Required for real-time simulation and discrete systems.
-
-
Key Parameters:
-
Start/Stop time: Simulation window. -
Max step size: Upper bound on solver step (controls detail/speed). -
Relative/absolute tolerance: Error tolerances for variable-step solvers.
-
-
[!TIP] Common Pitfall: Using a variable-step solver for a model with discrete (sampled) components can cause missed sample hits. Use a fixed-step solver for discrete/hybrid systems.
3.2 TIME-DOMAIN ANALYSIS OF SYSTEMS
3.2.1 Transient Response Analysis
-
Standard Inputs: Step (
Stepblock), Impulse (Pulse Generatorwith very small width), Ramp. -
Key Performance Metrics (for a step response):
-
Rise Time ($$\displaystyle t_r $$): Time to go from 10% to 90% of final value.
-
Settling Time ($$\displaystyle t_s $$): Time to enter and remain within a tolerance band (e.g., ±2%) around steady-state.
-
Overshoot ($$\displaystyle M_p $$): Maximum peak value minus steady-state value, as a percentage.
-
Steady-State Error ($$\displaystyle e_{ss} $$): Final value minus desired input.
-
-
Tools:
To Workspaceblock (exports data astimeseries),Scopeblock (visualizes). Use MATLAB'sstepinfo(sys)for automatic calculation.
3.2.2 Analysis of Linear & Nonlinear Systems
-
Nonlinearities: Implement using blocks like
Saturation,Dead Zone,Relay,Piecewise Linear. -
Approach: Simulate nonlinear model. For small-signal analysis around an operating point, use linearization (see 3.3.1).
-
[!TIP] Exam Insight: Be prepared to compare the step response of a linear model (e.g., transfer function) with its nonlinear counterpart (e.g., motor with saturation) and explain differences (e.g., reduced overshoot due to saturation).
3.2.3 Discrete-Time System Simulation
-
Implementation: Use
Unit Delayblock to implement difference equations:y[k] = a1*y[k-1] + b0*u[k] + b1*u[k-1]. -
Zero-Order Hold (ZOH):
Zero-Order Holdblock holds the input constant between sampling instants. Models the effect of a DAC. -
Discretization: Convert continuous TF to discrete using
c2din MATLAB orDiscrete Transfer Fcnblock with specifiedSample time.
3.3 FREQUENCY-DOMAIN ANALYSIS IN SIMULINK
3.3.1 Linearization of Models
-
Purpose: Obtain a linear time-invariant (LTI) model (state-space
(A,B,C,D)or transfer function) of a nonlinear or complex model at a specific operating point. -
Tools:
-
Simulink Control Design™:
Linear Analysis Tool(right-click on model). -
Functions:
linmod(for continuous models),dlinmod(for models with discrete blocks).
-
-
Operating Point: Must be a steady-state condition where derivatives are zero. Can be found using
trimfunction or by simulating to steady-state.
3.3.2 Bode Plot & Frequency Response
-
From Linear Model: Use MATLAB
bode(sys)on the linearizedsys. -
From Simulink Model: Use
Bode Plotblock (from Simulink Control Design) which linearizes the model internally at each frequency. -
Key Metrics from Bode:
-
Gain Crossover Frequency ($$\displaystyle \omega_{gc} $$): Freq. where |G(jω)| = 1 (0 dB).
-
Phase Crossover Frequency ($$\displaystyle \omega_{pc} $$): Freq. where ∠G(jω) = -180°.
-
Gain Margin (GM): $$\displaystyle GM = \frac{1}{|G(j\omega_{pc})|} $$ (in dB: $$\displaystyle 20\log_{10}(GM) $$).
-
Phase Margin (PM): $$\displaystyle PM = \angle G(j\omega_{gc}) + 180° $$.
-
Bandwidth: Freq. where |G(jω)| drops to -3 dB of DC gain.
-
-
\boxed{PM > 0^\circ \text{ and } GM > 1 \text{ (0 dB)} \text{ indicates stability for minimum-phase systems.}}
3.3.3 Root Locus & Pole-Zero Maps
-
Root Locus: Plot of closed-loop pole locations as a scalar gain
Kvaries from 0 to ∞. Generated byrlocus(sys). -
Pole-Zero Map: Plot of open-loop poles (
x) and zeros (o) on the complex s-plane. Usepzmap(sys). -
Design Insight: Poles in Left Half Plane (LHP) → stable. Poles on imaginary axis → marginally stable (oscillations). Poles in Right Half Plane (RHP) → unstable. Distance from imaginary axis relates to settling time.
3.4 APPLICATION-SPECIFIC SIMULATION CASE STUDIES
3.4.1 Control Systems
-
PID Controller: Implement using
PID Controllerblock (continuous) orDiscrete PID Controller. Tuning via simulation (e.g., Ziegler-Nichols: find ultimate gainKuand periodPu). -
Closed-Loop Analysis: Simulate with
Stepreference, addDisturbance(e.g.,Stepblock at plant input) andNoise(e.g.,Band-Limited White Noise) at sensor. Observe performance viaScope.
3.4.2 Communication Systems (Baseband & Passband)
-
Typical Chain:
Random Integer(Source) →Modulator(e.g.,BPSK Modulator Baseband) →AWGN Channel→Demodulator→Error Rate Calculation. -
BER vs. Eb/N0: Sweep
Eb/N0(usingForsubsystem or MATLAB script), simulate many bits, computeBERusingError Rate Calculationblock. Plot usingsemilogy. -
Theoretical BER for BPSK in AWGN: $$\displaystyle P_b = Q\left(\sqrt{\frac{2E_b}{N_0}}\right) $$ where $$\displaystyle Q(x) = \frac{1}{\sqrt{2\pi}}\int_x^\infty e^{-t^2/2} dt $$.
-
[!TIP] Common Mistake: Forgetting to account for pulse shaping (e.g., raised cosine) in passband simulations, leading to incorrect bandwidth/ISI.
3.4.3 Signal Processing Systems
-
Filter Design: Use
Filter Designerapp orfdesign/designfunctions to get coefficients. Implement withDiscrete Transfer FcnorDFiltblock. -
FFT Analysis: Use
FFTblock (DSP System Toolbox) orSpectrum Analyzerblock to visualize frequency content. Input: multi-tone signal or noisy signal. -
Key Test: Apply a square wave to a low-pass filter. Observe fundamental attenuation and harmonic suppression in time and frequency domains.
3.5 ADVANCED VISUALIZATION & RESULT INTERPRETATION
-
Scope Block: Configure
Number of axes,Time range,Y-limits. EnableLog data to workspacefor post-processing. -
Spectrum Analyzer: Real-time spectral view. Configure
FFT length,Window type(e.g., Hamming),Frequency scale(Hz/rad/s). -
MATLAB Workspace Plotting:
-
Data from
To Workspace(astimeseries):plot(data.time, data.signals.values). -
For frequency response:
[mag, phase, w] = bode(sys); semilogx(w, 20*log10(squeeze(mag))).
-
-
Programmatic Metrics:
stepinfo(sys)returnsRiseTime,SettlingTime,Overshoot, etc.bandwidth(sys)returns 3-dB bandwidth.
3.6 TROUBLESHOOTING & BEST PRACTICES
-
Algebraic Loop: Occurs when a signal's value depends on itself directly (no unit delay). Fix: Introduce
Unit DelayorMemoryblock. -
Solver Failure (Singularity): Often from uninitialized states or stiff systems. Fix: Check initial conditions, try a different solver (
ode15sfor stiff), or adjust tolerances. -
Diagnostic Viewer: Primary tool. Read warnings (e.g., "Signal dimension mismatch")—they often indicate root cause.
-
Best Practices:
-
Use meaningful signal names (right-click signal →
Properties). -
Add annotations (
Ctrl+I) to explain subsystems. -
Disable logging for signals not needed for analysis to reduce memory/speed overhead.
-
Use model advisor (
Analysis → Model Advisor) to check for common issues.
-
3.7 PRACTICAL LAB EXPERIMENT THEMES (Typical for Unit 3)
-
PID-Controlled DC Motor:
-
Model: Motor (TF
K/(Js+b)) + PID +Stepreference. -
Task: Tune
Kp, Ki, Kdto meet specs (e.g., $$\displaystyle t_s < 0.5s $$, $$\displaystyle M_p < 5\% $$). Compare with/without integral windup protection.
-
-
Linearization of Pendulum:
- Model: Nonlinear pendulum (
sin(θ)). Linearize aroundθ=0(upright) andθ=π(inverted). Compare step responses.
- Model: Nonlinear pendulum (
-
BPSK over AWGN:
-
Model: Random bits → BPSK mod → AWGN (
Eb/N0sweep) → BPSK demod →Error Rate Calculation. -
Task: Simulate for
Eb/N0 = 0:2:10 dB. Plot simulated BER vs. theoretical curve.
-
-
Butterworth Low-Pass Filter:
-
Design:
[b,a] = butter(4, 0.2)(4th order, fc=0.2*fs/2). Implement. -
Task: Input square wave (fs=100 Hz). Observe output in
ScopeandSpectrum Analyzer. Note harmonic attenuation.
-
-
Hierarchical Digital Comm System:
-
Build top-level:
Source → Channel Coder → Modulator → Channel → Demodulator → Channel Decoder → Sink. -
Use masked subsystems for "Modulator" (select BPSK/QPSK) and "Channel" (set
SNR). Reuse across experiments.
-
3.8 KEY MATLAB/SIMULINK FUNCTIONS & BLOCKS (Quick Reference)
| Category | Items |
|---|---|
| Functions | linmod, dlinmod, trim, bode, stepinfo, bandwidth, rlocus, pzmap, c2d, fft, qfunc (for Q-function) |
| Blocks | Solver Configuration, Subsystem (masked), Bus Creator/Selector, PID Controller, Discrete Transfer Fcn, Bode Plot, Spectrum Analyzer, Error Rate Calculation, From Workspace |
| Toolboxes | Simulink Control Design, DSP System Toolbox, Communications Toolbox |
Final Exam Reminder: Always state your assumptions (e.g., "Assuming linearization around zero operating point..."). For simulation results, include screenshots of the model and key outputs (Scope/Bode plot) in your answer.