Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting started with Simulink An introductory tutorial.

Similar presentations


Presentation on theme: "Getting started with Simulink An introductory tutorial."— Presentation transcript:

1 Getting started with Simulink An introductory tutorial

2 Introduction to Simulink Simulink is a graphical, “drag and drop” environment for building simple and complex signal and system dynamic simulations. It allows users to concentrate on the structure of the problem, rather than having to worry (too much) about a programming language. The parameters of each signal and system block is configured by the user (right click on block) Signals and systems are simulated over a particular time.

3 Launch Simulink In the MATLAB command window, at the >> prompt, type simulink and press  Enter

4 Create a new model Click the new-model icon in the upper left corner to start a new Simulink file Select the Simulink icon to obtain elements of the model

5 Your workspace Library of elements Model is created in this window

6 Save your model You might create a new folder, like the one shown below, called simulink_files Use the.mdl suffix when saving

7 Configuration Parameters Simulink is designed to be a front-end tool for integrating ordinary differential equations (ODEs). So, you need to keep sampling issues in mind: Experiment with the ODE “Solver” parameters to make things appear correctly.

8 Setting the Configuration Parameters To start: 1. Click on the Simulink icon to open up Simulink in Matlab. 2. In the new model window, click on the configuration parameters.

9 Starting and Ending Time Parameters Simulation time Start time: 0.0End time: 100 Note that these times come from the “Sources” parameters. Keep in mind that the “Sources” are usually designed for continuous-time (not discrete time) simulations.

10 Solver Configuration Parameters Solver Options Type: Variable-step Solver: discrete (no continuous-states) Max Step Size: 0.5 <- Set lower for better simulations! Or: Type: Fixed-step Solver: discrete (no continuous-states) Fixed Step Size (fundamental sample size): 0.5 Set lower “Fixed Step Size” for better simulations! The rest are not as important …

11 Connecting Things 1. Hold down the Control key down. 2. Click on the “source” icon. 3. Click on the “sink” icon. 4. Press the left mouse key to make the connection.

12 Displaying Things Can use the “scope” attached to any signal. Use the “Autoscale” function that appears as binoculars in order to look at the results of the entire simulations Click on the “X”, the “Y” or the “zoom” functions to look at any specific part of the simulation

13 Example 1: a simple model Build a Simulink model that solves the differential equation Initial condition First, sketch a simulation diagram of this mathematical model (equation) (3 min.)

14 Simulation diagram Input is the forcing function 3sin(2t) Output is the solution of the differential equation x(t) Now build this model in Simulink 3sin(2t) (input) x(t) (output) integrator

15 Select an input block Drag a Sine Wave block from the Sources library to the model window

16 Select an operator block Drag an Integrator block from the Continuous library to the model window

17 Select an output block Drag a Scope block from the Sinks library to the model window

18 Connect blocks with signals Place your cursor on the output port (>) of the Sine Wave block Drag from the Sine Wave output to the Integrator input Drag from the Integrator output to the Scope input Arrows indicate the direction of the signal flow.

19 Select simulation parameters Double-click on the Sine Wave block to set amplitude = 3 and freq = 2. This produces the desired input of 3sin(2t)

20 Select simulation parameters Double-click on the Integrator block to set initial condition = -1. This sets our IC x(0) = -1.

21 Select simulation parameters Double-click on the Scope to view the simulation results

22 Run the simulation In the model window, from the Simulation pull- down menu, select Start View the output x(t) in the Scope window.

23 Simulation results To verify that this plot represents the solution to the problem, solve the equation analytically. The analytical result, matches the plot (the simulation result) exactly.

24 Example 2 Build a Simulink model that solves the following differential equation 2nd-order mass-spring-damper system zero ICs input f(t) is a step with magnitude 3 parameters: m = 0.25, c = 0.5, k = 1

25 Create the simulation diagram On the following slides: The simulation diagram for solving the ODE is created step by step. After each step, elements are added to the Simulink model. Optional exercise: first, sketch the complete diagram (5 min.)

26 (continue) First, solve for the term with highest- order derivative Make the left-hand side of this equation the output of a summing block summing block

27 Drag a Sum block from the Math library Double-click to change the block parameters to rectangular and + - -

28 (continue) Add a gain (multiplier) block to eliminate the coefficient and produce the highest-derivative alone summing block

29 Drag a Gain block from the Math library Double-click to change the block parameters. Add a title. The gain is 4 since 1/m=4.

30 (continue) Add integrators to obtain the desired output variable summing block

31 Drag Integrator blocks from the Continuous library Add a scope from the Sinks library. Connect output ports to input ports. Label the signals by double-clicking on the leader line. ICs on the integrators are zero.

32 (continue) Connect to the integrated signals with gain blocks to create the terms on the right-hand side of the EOM summing block c k

33 Drag new Gain blocks from the Math library  Double-click on gain blocks to set parameters  Connect from the gain block input backwards up to the branch point.  Re-title the gain blocks. To flip the gain block, select it and choose Flip Block in the Format pull-down menu. c=0.5 k=1.0

34 Complete the model Bring all the signals and inputs to the summing block. Check signs on the summer. c k f(t) input + - - x(t) output

35 Double-click on Step block to set parameters. For a step input of magnitude 3, set Final value to 3

36 Final Simulink model

37 Run the simulation

38 Results Underdamped response. Overshoot of 0.5. Final value of 3. Is this expected?

39 Paper-and-pencil analysis based on the equations of motion Standard form Nat’l freq. Damping ratio Static gain

40 Check simulation results Damping ratio of 0.5 is less than 1. Expect the system to be underdamped. Expect to see overshoot. Static gain is 1. Expect output magnitude to equal input magnitude. Input has magnitude 3, so does output. Simulation results conform to expectations.

41 A Simple Example: Displaying a Chirp Signal in Simulink The Model ->

42 Chirp Parameters Thus, the correct display should show a slowly varying sinusoid that is speeding up. From the source parameters: Start time = 0 End time = 100

43 Configuration Parameters Notice the “Fixed-step size” of 0.1.

44 After Running the Simulation After clicking on “Autoscale”, it all appears to be working.

45 Aliasing Due to Insufficient Sampling After changing the “Fixed-step size” to 1... TOO LARGE!

46 System Performance Using MATLAB and Simulink

47

48

49 End of tutorial


Download ppt "Getting started with Simulink An introductory tutorial."

Similar presentations


Ads by Google