How to Use Simulink

ECE743
Jin-Woo Jung, Ph. D. Student and GTA Advisor: Prof. Ali Keyhani

January 21, 2005 Department of Electrical and Computer Engineering The Ohio State University
1 /36 ECE743

Features of Matlab and Simulink
Matlab (*.m):
Only text code (Not easy to model complicated systems) Easy to edit figures

Simulink (*.mdl):
Schematic (Easy to model complicated systems) Not easy to change parameters Can not edit figures

Matlab (*.m) + Simulink (*.mdl): Best choice
Schematic: Simulink Easy to change parameters: Matlab (m file for parameter initialization) Edit figures: Simulink (“To Workspace”) ⇒ Matlab (m file for plot)
2 /36 ECE743

Available Simulink Toolboxes (version. 6.5)
Simulink Aerospace Blockset CDMA Reference Blockset Communications Blockset Control System Toolbox DSP Blockset Gauges Blockset Embedded Target for Motorola MCP555 Embedded Target for TI C6000 DSP Fixed-Point Blockset Fuzzy Logic Toolbox MPC Blocks NCD Blockset

Neural Network Blockset Real-Time Windows Target Real-Time Workshop Report Generator S-function demos SimMechanics SimPowerSystems Simulink Extras Stateflow System ID Toolbox Virtual Reality Toolbox xPC Target
: Available toolboxes at ECE Computer Lab. ECE743 3 /36

Change “Current directory” Click “Browser for folder” 4 /36 ECE743 .1. Current Directory 1).

Click “Simulink” Then.2. Starting “Simulink” 1). Simulink Library Browser 5 /36 ECE743 .

3. Click “Create a new model” Then. Open “A new file” 1). a new Simulink file 6 /36 ECE743 .

Type block’s name and then drag it to a new file “Press a right button on a mouse” “Double click your model” 7 /36 Click “Help” to set up parameters ECE743 .4. Building “System” (1) Find ‘’Block‘’ when you know “block’s name” 1).

type the text for model search This is model name 8 /36 ECE743 . Click “Simulink Help” Then. Building “System” (2) Find ‘’Block‘’ when you don’t know “block’s name” 1).4.

Set up “Model properties” Set up m files for parameter initialization and plot (later) 1).m and Plot.m 9 /36 ECE743 . type file names: Initialization.5. Click “Model properties” Then.

6. Click “Simulation parameters” Then. change “Stop time” 10/36 ECE743 . Start “Simulation” (1) Set up “Simulation parameters” 1).

Click “Start simulation” 11/36 ECE743 .6. Start “Simulation” (2) Start Simulation 1).

C = 1 µF.1 H.2 H. Rp = 1 Ω.1 H. 12/36 ECE743 . Ls = 0.7. and V = 10 V (Step Input) Simulate the dynamic response of i1. R1 = 1 Ω. and Vc and plot the results on the same page. Example for Matlab/Simulink Example 1: where: Lp = 0. Mi = 0. i2. Rs = 2 Ω.

S-function: “asglpr3b. Parameter initialization: “Para_Initial. Plot: Plot_1.m” 2.m Case 4: Matlab + Simulink: “SimPowerSystems” 1.mdl” 3. Parameter initialization: “Initialization.7.mdl” 3. Plot: Plot_1.mdl” 3.m” 2.m Case 3: Matlab + Simulink: Not S-Function 1. Simulink: “Case_4. Simulink: “Case_3. Example 1 Four different Methods Case 1: Only Matlab Case 2: Matlab + Simulink: S-Function 1.m ♦ “Note that all files should be under current directory” 13/36 ECE743 . Plot: Plot_1.m” 2. Simulink: “Example_1.

1. V = 10.1. X = [0. C = 1e-6. Mi = 0.1. 14/36 ECE743 . A = Linv*R. 0 -(Rs+R1) -1. alpha = 0. Rs = 2.0] L = [(Lp+Mi) -Mi 0. R = [-Rp 0 0. U = V.Case 1 clear all Lp = 0. 0 0 C] Linv = inv(L).0]. Rp = 1.2.7. -Mi (Ls+Mi) 0.Example 1 . 0 1 0] D = [1.0. Ls = 0. B = Linv*D.0. Example 1 − Case 1 – (1) Case 1: Only Matlab – (1) % Only Matlab code . R1 = 1.

% time step for n = 1:10000 % Trapezoidal Integration n1(n) = n. termint = A*X + B*U. alpha2 = 1 . i2(n) = X(2). Example 1 − Case 1 – (2) Case 1: Only Matlab – Matlab code continued . end 15/36 ECE743 . Vc(n) = X(3).0001. alpha1 = 1 + alpha.7. Xest = X + T*(A*X + B*U). term1 = alpha1*Xdotest. X = X + (T/2)*(term1 + term2). i1(n) = X(1). Xdotest = A*Xest + B*U.alpha.(2) T = 0. term2 = alpha2 + termint.

01 0.i1) grid ylabel('i_1 [A]') title('i_1 vs time') subplot(3.Vc) grid axis([0 1 -5 10]) xlabel('Time') ylabel('V_c [V]') title('V_c vs time') 16/36 ECE743 .1.1.i2) grid axis([0 1 -0.1) plot(n1*T.2) plot(n1*T.7.(3) figure (1) subplot(3. Example 1 − Case 1 – (3) Case 1: Only Matlab – Matlab code continued .3) plot(n1*T.01]) ylabel('i_2 [A]') title('i_2 vs time') subplot(3.1.

7 0.7 0.5 Vc vs time 0.4 0. Example 1 − Case 1 – (4) Results i1 vs time 10 i1 [A] 5 0 0 0.005 -0.9 1 17/36 ECE743 .7 0.2 0.01 0.5 Time 0.6 0.01 0 10 5 0 -5 0 0.7.6 0.2 0.2 0.8 0.4 0.3 0.5 i2 vs time 0.1 0.1 0.3 0.005 i2 [A] 0 -0.8 0.8 0.1 0.3 0.6 0.9 1 Vc [V] 0.4 0.9 1 0.

alpha = 0. 0 1 0] D = [1. -Mi (Ls+Mi) 0.(1) function [sys. x0]=prob1(t.1. B = Linv*D. 0 -(Rs+Rl) -1.u.1. Rl = 1.2. R = [-Rp 0 0. C = 1e-6. Example 1 − Case 2 – (1) Case 2: Matlab + Simulink: S-function S-function code: “asglpr3b.0.1. Mi = 0. 18/36 ECE743 . 0 0 C] Linv = inv(L). Rs = 2. Rp = 1.x. Ls = 0.flag) Lp = 0.0] L = [(Lp+Mi) -Mi 0. A = Linv*R.m” --. V = 10.7.

elseif abs(flag)==3 sys(1:3)= x(1:3). sys(4)=1. end.m” --. sys(2)=0.Matlab code continued . sys(3)=3. sys(6)=0. 0. 0]. else sys=[]. ECE743 19/36 . sys(5)=0. Example 1 − Case 2 – (2) S-function code: “asglpr3b.(2) if abs(flag)==1 sys(1:3)=A*x(1:3)+B*u. x0= [0. elseif flag==0 sys(1)=3.7.

7.(1) 20/36 ECE743 .mdl” --. Example 1 − Case 2 – (3) Simulink code: “Example_1.

“To Workspace” “Type a variable name” Click “Array” 21/36 ECE743 .mdl” --. Example 1 − Case 2 – (4) Simulink code: “Example_1.(2) 1.7.

Example 1 − Case 2 – (5) Simulink code: “Example_1.mdl” --.7.(3) 2. “S-Function” “Type S-function name” “Blank” 22/36 ECE743 .

Example 1 − Case 2 – (6) Simulink code: “Example_1. “Scope” “Type the number of axes” “Click Parameters” Release “Limit data points to last” 23/36 ECE743 .(4) 3.mdl” --.7.

(Method1 for plot) “Select the texts” and then “Press a right button on a mouse” Click “Evaluate Selection” 24/36 ECE743 .m” --.7. Example 1 − Case 2 – (7) Plot Matlab code: “Plot_1.

Example 1 − Case 2 – (8) Plot Matlab code: “Plot_1.(Method 2 for plot) Type “a file name for plot” 25/36 ECE743 .7.m” --.

Example 1 − Case 2 – (9) Results i1 vs time 10 i1 [A] 5 0 0 0.7 0.9 1 0.5 i2 vs time 0.9 1 Vc [V] 0.9 1 26/36 ECE743 .8 0.5 Vc vs time 0.7 0.7.2 0.4 0.01 0.2 0.005 i2 [A] 0 -0.5 Time 0.7 0.01 0 10 5 0 -5 0 0.1 0.005 -0.3 0.2 0.4 0.1 0.3 0.8 0.1 0.6 0.4 0.3 0.6 0.6 0.8 0.

m” . R = [-Rp 0 0. 27/36 ECE743 . Rp = 1. B = Linv*D. C = eye(3).Case 3 clear all Lp = 0. C = 1e-6. A = Linv*R.0] L = [(Lp+Mi) -Mi 0. Mi = 0.1. V = 10.1).2. D = zeros(3. 0 0 C] Linv = inv(L). 0 1 0] D = [1.1. Example 1 − Case 3 – (1) Case 3: Matlab + Simulink: Not S-Function Parameter Initialization: “Initialization.(1) % Parameters Initialization .0. R1 = 1. alpha = 0. Rs = 2.7. Ls = 0. 0 -(Rs+R1) -1.1.Example 1 . -Mi (Ls+Mi) 0.

(1) 28/36 ECE743 .7. Example 1 − Case 3 – (2) Simulink code: “Case_3.mdl” --.

7.mdl” --. “State-space” 29/36 ECE743 .(2) 1. Example 1 − Case 3 – (3) Simulink code: “Case_3.

type file names: Initialization. Example 1 − Case 3 – (4) Set up m files for parameter initialization and plot 1).m 30/36 ECE743 .7. Click “Model properties” Then.m and Plot_1.

01 0 10 5 Vc 0 -5 0 i2 0. Example 1 − Case 3 – (5) Results i1 vs time 10 5 i1 0 0 0.1 0.4 0.3 0.2 0.8 0.6 0.9 1 0.5 i2 vs time 0.1 0.2 0.01 0.9 1 0.5 Vc vs time 0.7 0.1 0.3 0.6 0.005 -0.3 0.005 0 -0.8 0.9 1 31/36 ECE743 .7 0.2 0.4 0.4 0.7 0.8 0.6 0.7.5 0.

Ls = 0. Rs = 2. Example 1 − Case 4 – (1) Case 4: Matlab + Simulink (SimPower Systems) Parameter Initialization: “Para_Initial. Mi = 0.m” % Parameters Initialization . 32/36 ECE743 .2.Example 1 .1.7. R1 = 1. Lp = 0. Rp = 1.Case 4 clear all V = 10.1. C = 1e-6.

7. Example 1 − Case 4 – (2) Simulink code: “Case_4.mdl” 33/36 ECE743 .

Click “Model properties” Then. type file names: Para_Initial.7. Example 1 − Case 4 – (3) Set up m files for parameter initialization and plot 1).m 34/36 ECE743 .m and Plot_1.

Click “Simulation parameters” Then. Example 1 − Case 4 – (4) Set up “Simulation parameters” 1). reduce “Max step size” 35/36 ECE743 . change “Stop time” and “Solver options” Then.7.

3 0.8 0.7.5 Vc vs time 0.9 1 0.01 0.7 0.005 0 -0.9 1 36/36 ECE743 .4 0. Example 1 − Case 4 – (5) Results i1 vs time 10 5 i1 0 0 0.7 0.7 0.1 0.9 1 Vc 5 0 0 0.005 -0.6 0.2 0.2 0.8 0.4 0.1 0.01 0 10 i2 0.5 0.1 0.3 0.4 0.8 0.3 0.6 0.6 0.2 0.5 i2 vs time 0.

Sign up to vote on this title
UsefulNot useful