Skip to content
EC-406 · Simulation Lab/Quick Revision Short Notes

Simulation Lab (EC-406) - Unit 3 Short Notes

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, Kd via the mask.
  • Model Referencing: A top model references and runs a separate .slx file. 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 Selector population.

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 (Step block), Impulse (Pulse Generator with 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 Workspace block (exports data as timeseries), Scope block (visualizes). Use MATLAB's stepinfo(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 Delay block to implement difference equations: y[k] = a1*y[k-1] + b0*u[k] + b1*u[k-1].

  • Zero-Order Hold (ZOH): Zero-Order Hold block holds the input constant between sampling instants. Models the effect of a DAC.

  • Discretization: Convert continuous TF to discrete using c2d in MATLAB or Discrete Transfer Fcn block with specified Sample 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 trim function or by simulating to steady-state.

3.3.2 Bode Plot & Frequency Response

  • From Linear Model: Use MATLAB bode(sys) on the linearized sys.

  • From Simulink Model: Use Bode Plot block (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 K varies from 0 to ∞. Generated by rlocus(sys).

  • Pole-Zero Map: Plot of open-loop poles (x) and zeros (o) on the complex s-plane. Use pzmap(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 Controller block (continuous) or Discrete PID Controller. Tuning via simulation (e.g., Ziegler-Nichols: find ultimate gain Ku and period Pu).

  • Closed-Loop Analysis: Simulate with Step reference, add Disturbance (e.g., Step block at plant input) and Noise (e.g., Band-Limited White Noise) at sensor. Observe performance via Scope.

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 (using For subsystem or MATLAB script), simulate many bits, compute BER using Error Rate Calculation block. Plot using semilogy.

  • 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 Designer app or fdesign/design functions to get coefficients. Implement with Discrete Transfer Fcn or DFilt block.

  • FFT Analysis: Use FFT block (DSP System Toolbox) or Spectrum Analyzer block 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. Enable Log data to workspace for 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 (as timeseries): plot(data.time, data.signals.values).

    • For frequency response: [mag, phase, w] = bode(sys); semilogx(w, 20*log10(squeeze(mag))).

  • Programmatic Metrics: stepinfo(sys) returns RiseTime, 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 Delay or Memory block.

  • Solver Failure (Singularity): Often from uninitialized states or stiff systems. Fix: Check initial conditions, try a different solver (ode15s for 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)

  1. PID-Controlled DC Motor:

    • Model: Motor (TF K/(Js+b)) + PID + Step reference.

    • Task: Tune Kp, Ki, Kd to meet specs (e.g., $$\displaystyle t_s < 0.5s $$, $$\displaystyle M_p < 5\% $$). Compare with/without integral windup protection.

  2. Linearization of Pendulum:

    • Model: Nonlinear pendulum (sin(θ)). Linearize around θ=0 (upright) and θ=π (inverted). Compare step responses.
  3. BPSK over AWGN:

    • Model: Random bits → BPSK mod → AWGN (Eb/N0 sweep) → BPSK demod → Error Rate Calculation.

    • Task: Simulate for Eb/N0 = 0:2:10 dB. Plot simulated BER vs. theoretical curve.

  4. 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 Scope and Spectrum Analyzer. Note harmonic attenuation.

  5. 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.

Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in