Top Banner
HossamTalaat - MATLAB Course - KSU HossamTalaat - MATLAB Course - KSU - 21/1/24 - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU IEEE Student Branch - College of Engineering - KSU Getting started with Getting started with Simulink Simulink By By Prof. Hossam Talaat Prof. Hossam Talaat
29

HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

11

IEEE Student Branch - College of Engineering - KSUIEEE Student Branch - College of Engineering - KSU

Getting started with SimulinkGetting started with Simulink

ByBy

Prof. Hossam TalaatProf. Hossam Talaat

Page 2: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

22

What is Simulink?What is Simulink? It becomes a standard in many It becomes a standard in many

universities.universities. Simulink is an interactive environment Simulink is an interactive environment

for modeling, simulating and analyzing for modeling, simulating and analyzing dynamic systems.dynamic systems.

It uses graphical user interface of block It uses graphical user interface of block diagram representation instead of diagram representation instead of differential and difference equations.differential and difference equations.

A Simulink model consists of A Simulink model consists of blocks blocks (representing elementary dynamic systems) (representing elementary dynamic systems) interconnected by interconnected by lines lines (time-domain (time-domain signals).signals).

Page 3: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

33

Capabilities of SimulinkCapabilities of Simulink

It Simulates Linear and nonlinear It Simulates Linear and nonlinear systems.systems.

It Simulates continuous, discrete and It Simulates continuous, discrete and hybrid systems.hybrid systems.

It has a powerful “What if” It has a powerful “What if” exploration capability.exploration capability.

Page 4: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

44

How to Simulate a Dynamic How to Simulate a Dynamic SystemSystem

Phase I: Create a model of the system to Phase I: Create a model of the system to be simulated using Simulink’s model be simulated using Simulink’s model editor, blocks library and click and drag editor, blocks library and click and drag mouse operations. mouse operations.

Phase II: Use Simulink’s ODE solvers to Phase II: Use Simulink’s ODE solvers to simulate the behavior of the system for a simulate the behavior of the system for a specified time span.specified time span.

Page 5: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

55

Phase I: Creating a modelPhase I: Creating a model To open Simulink click on the Simulink icon on the To open Simulink click on the Simulink icon on the

MATLAB toolbar.MATLAB toolbar. To open a new model click on the corresponding To open a new model click on the corresponding

icon on the Simulink toolbar.icon on the Simulink toolbar. To introduce blocks in your model, choose the To introduce blocks in your model, choose the

block from the library, click on it and drag it in block from the library, click on it and drag it in your model.your model.

Interconnect the output of a block to the input of Interconnect the output of a block to the input of the required block by a line using mouse.the required block by a line using mouse.

Double-click each block to set its parameters.Double-click each block to set its parameters.

Page 6: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

66

Model 0: How to Build a New ModelModel 0: How to Build a New Model

ProcedureProcedure How to insert a Block?How to insert a Block? How to set the block parameters?How to set the block parameters? How to interconnect between blocks?How to interconnect between blocks? How to add text?How to add text?

Page 7: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

77

Page 8: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

88

Simulink block libraries Simulink block libraries

Simulink provides a library browser that allows Simulink provides a library browser that allows you to select blocks from libraries of standard you to select blocks from libraries of standard blocks:blocks:

SourcesSources - blocks that generate signals - blocks that generate signals SinksSinks - display or output blocks. - display or output blocks. DiscreteDiscrete - discrete-time components blocks. - discrete-time components blocks. ContinuousContinuous - linear continuous-time blocks. - linear continuous-time blocks. MathMath - general mathematical functions blocks. - general mathematical functions blocks.

Page 9: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

99

Simulink block libraries (cont.)Simulink block libraries (cont.)

Functions & TablesFunctions & Tables - general functions and look-up - general functions and look-up table operations.table operations.

NonlinearNonlinear - blocks that describe nonlinear functions. - blocks that describe nonlinear functions. Signal & SystemsSignal & Systems - blocks that allow multiplexing, - blocks that allow multiplexing,

demultiplexing, create subsystems and perform demultiplexing, create subsystems and perform similar functions.similar functions.

Blocksets and ToolboxesBlocksets and Toolboxes - the Extras block library - the Extras block library of specialized blocks.of specialized blocks.

DemosDemos - useful MATLAB and Simulink demos. - useful MATLAB and Simulink demos.

Page 10: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1010

Model 1: Sources and SinksModel 1: Sources and Sinks

ProcedureProcedure Run the model using different Run the model using different

waveforms.waveforms. Open/close the manual switch to Open/close the manual switch to

check the effect of noise.check the effect of noise. Check the workspace for y1.Check the workspace for y1. Check the file model1.mat under Check the file model1.mat under

matlab/simulink folder.matlab/simulink folder.

Page 11: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1111

New Blocks in Model 1New Blocks in Model 1

BlockBlock GroupGroup DescriptionDescriptionSignal generatorSignal generator

Uniform random Uniform random numbernumber

To workspaceTo workspace

ScopeScope

To fileTo file

SumSum

Manual switchManual switch

SourcesSources

SourcesSources

SinkSink

SinkSink

SinkSink

MathMath

NonlinearNonlinear

Generate various waveformsGenerate various waveforms

Generate uniformly distributed Generate uniformly distributed random numbersrandom numbers

Write data to a variable in the Write data to a variable in the workspaceworkspace

Display signals generated Display signals generated during a simulationduring a simulation

Write data to a fileWrite data to a file

Generate the sum of the inputsGenerate the sum of the inputs

Switch between two inputsSwitch between two inputs

Page 12: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1212

Model 2: Scopes and GraphsModel 2: Scopes and Graphs

ProcedureProcedure Run the model using different values Run the model using different values

of w (freq. of y in rad/s), put w= 50, of w (freq. of y in rad/s), put w= 50, 100, 150, and 250.100, 150, and 250.

For each value sketch the graphs For each value sketch the graphs obtained in the 4 fixed scopes.obtained in the 4 fixed scopes.

How to use a floating scope?How to use a floating scope? How to control the graph settings?How to control the graph settings?

Page 13: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1313

New Blocks in Model 2New Blocks in Model 2

BlockBlock GroupGroup DescriptionDescription

Sine waveSine wave

XY GraphXY Graph

MuxMux

SourcesSources

SinkSink

SignalsSignals

Generate a sine waveGenerate a sine wave

Display an x-y plot of Display an x-y plot of signals using a MATLAB signals using a MATLAB figure windowfigure window

Combine several input Combine several input lines into a vector line.lines into a vector line.

Page 14: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1414

Phase II: Solving the Dynamic Model Phase II: Solving the Dynamic Model (Simulation)(Simulation)

The Simulink block diagram model depicts a The Simulink block diagram model depicts a time-dependent mathematical relationship time-dependent mathematical relationship between Inputs, States, and Outputs in the form between Inputs, States, and Outputs in the form of a set of Ordinary Differential Equations of a set of Ordinary Differential Equations “ODE”.“ODE”.

In this phase Simulink successively solves the In this phase Simulink successively solves the ODE to compute the states and the outputs of ODE to compute the states and the outputs of the system at intervals from the simulation the system at intervals from the simulation start start timetime to the to the stop timestop time..

To set the parameters of the simulation select To set the parameters of the simulation select simulationsimulation from Simulink’s toolbar, then select from Simulink’s toolbar, then select simulation parameterssimulation parameters. .

Ir. Mihaela BUTUNOIU Ghent University MATLAB and Simulink Tutorial 2002

Page 15: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1515

Solver PaneSolver Pane

In the solver tab you have to set: In the solver tab you have to set: Start TimeStart Time (default is zero) and (default is zero) and Stop timeStop time.. Solver optionsSolver options : fixed/variable step, discrete/continuous. : fixed/variable step, discrete/continuous. Step size: Step size: it isit is the length of time between successive the length of time between successive

calculation. If you select calculation. If you select variable stepvariable step this may produce this may produce more accurate results without sacrificing execution more accurate results without sacrificing execution speed. You have to select:speed. You have to select: Max, min and initial step size (the default is auto).Max, min and initial step size (the default is auto). Relative and absolute tolerance to control the accuracy of the Relative and absolute tolerance to control the accuracy of the

solution (the default is auto).solution (the default is auto). Output options: Output options: to control the simulation output. If you to control the simulation output. If you

need more points use need more points use Refine output Refine output withwith refine factor>1. refine factor>1.

Page 16: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1616

Model 3: Continuous BlocksModel 3: Continuous Blocks

ProcedureProcedure How to set the transfer function?How to set the transfer function? Run the model.Run the model. Verify the output of each block in the Verify the output of each block in the

combined graph.combined graph.

Page 17: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1717

New Blocks in Model 3New Blocks in Model 3

BlockBlock GroupGroup DescriptionDescriptionRampRamp

DerivativeDerivative

IntegratorIntegrator

Transfer Transfer FcnFcn

Transport Transport delaydelay

SourcesSources

ContinuousContinuous

ContinuousContinuous

ContinuousContinuous

ContinuousContinuous

Generate a ramp signalGenerate a ramp signal

Output the time Output the time derivative of the input.derivative of the input.

Integrate the input.Integrate the input.

Implement a linear Implement a linear transfer function.transfer function.

Delay the input by a Delay the input by a given amount of time.given amount of time.

Page 18: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1818

Model 4: Transient response of a Model 4: Transient response of a second order systemsecond order system

ProcedureProcedure Set the damping coefficient “zeta” by Set the damping coefficient “zeta” by

double clicking the transfer function, double clicking the transfer function, let zeta=0.2, 0.4, 0.6, 1,5.let zeta=0.2, 0.4, 0.6, 1,5.

For each value specify if the For each value specify if the response is underdamped, critical response is underdamped, critical damped, or overdamped.damped, or overdamped.

Page 19: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

1919

Step-by-Step Model ConstructionStep-by-Step Model ConstructionDesign of a First order L.P.F.Design of a First order L.P.F.

Theoretical Theoretical BackgroundBackground R

1/SC

+

Vi

-

+

Vo

-

RCTwhere

TsRCssCR

sC

sVi

sVo

1

1

1

1

/1

/1

)(

)(

Page 20: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2020

RequiredRequired

Construct a Simulink Model that Construct a Simulink Model that describes the dynamic performance describes the dynamic performance of a L.P.F.of a L.P.F.

Use an original low frequency signal Use an original low frequency signal x with a noise high frequency signal x with a noise high frequency signal y:y:

x=100 sin(120x=100 sin(120 t) t)

y= 10 sin(4000y= 10 sin(4000 t). t).

Page 21: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2121

Step IStep I

Insert a “sine wave” input Insert a “sine wave” input from Sources. from Sources.

Copy it to have another one.Copy it to have another one. Double click each one to Double click each one to

adjust its parameters adjust its parameters (Amplitude and Freq.).(Amplitude and Freq.).

Edit the Block name.Edit the Block name. Right-click to adjust Right-click to adjust

foreground color.foreground color.

Page 22: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2222

Step IIStep II

Insert a “scope” from Sinks. Insert a “scope” from Sinks. Double click it then select Double click it then select

parameters icon to set “no. of parameters icon to set “no. of axes” = 2.axes” = 2.

Use mouse to connect each Use mouse to connect each of the sine wave outputs to of the sine wave outputs to one of the scope inputs.one of the scope inputs.

Name the two signals.Name the two signals.

Page 23: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2323

Step IIIStep III

Use the icon on toolbar to start simulation. Use the icon on toolbar to start simulation. Double-click the scope to check the Double-click the scope to check the

signals.signals. If the obtained plots are not as expected If the obtained plots are not as expected

select simulation parameters and adjust select simulation parameters and adjust the stop time (say 0.05), the max step (say the stop time (say 0.05), the max step (say 0.00001), the min and initial steps (say 0.00001), the min and initial steps (say 0.000001) and relative accurracy (say 1e-0.000001) and relative accurracy (say 1e-6).6).

Page 24: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2424

Step IVStep IV

Insert a “sum” from Insert a “sum” from Math. Math.

Connect the output of Connect the output of each sine to on of the each sine to on of the sum inputs.sum inputs.

Connect the output of Connect the output of sum to a scope.sum to a scope.

Start simulation and Start simulation and verify if the plot is as verify if the plot is as expected..expected..

Page 25: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2525

Step VStep V

Insert a transfer function Insert a transfer function ”T.F.” from continuous. ”T.F.” from continuous.

Set its parameters such Set its parameters such that the numerator =1 that the numerator =1 and denominator = and denominator = 0.00001 s +1.0.00001 s +1.

Name it L.P.FName it L.P.F Connect the output of Connect the output of

sum to the input of the sum to the input of the T.F.T.F.

Page 26: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2626

Step VIStep VI

Insert a scope and Insert a scope and name it “filtered signal”. name it “filtered signal”.

Connect the output of Connect the output of T.F. to the scope input.T.F. to the scope input.

Start simulation then Start simulation then verify the obtained plot.verify the obtained plot.

Change the time Change the time constant to 0.0001, .001 constant to 0.0001, .001 and .01 and comment.and .01 and comment.

Page 27: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2727

Step VIIStep VII

Insert a scope and Insert a scope and name it “filtered signal”. name it “filtered signal”.

Connect the output of Connect the output of T.F. to the scope input.T.F. to the scope input.

Start simulation then Start simulation then verify the obtained plot.verify the obtained plot.

Change the time Change the time constant to 0.0001, .001 constant to 0.0001, .001 and .01 and comment.and .01 and comment.

Page 28: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2828

Step VIIIStep VIII

Insert a scope Insert a scope with 2 inputs with 2 inputs to compare to compare the filtered the filtered and unfiltered and unfiltered signals . signals .

Page 29: HossamTalaat - MATLAB Course - KSU - 21/1/24 1 IEEE Student Branch - College of Engineering - KSU Getting started with Simulink By Prof. Hossam Talaat.

HossamTalaat - MATLAB Course - KSU - 21/HossamTalaat - MATLAB Course - KSU - 21/1/241/24

2929

End of tutorialEnd of tutorial