??? - PowerPoint PPT Presentation

1 / 83
About This Presentation
Title:

???

Description:

... Mathematics of Simulink Blocks ... Constants Mixed Continuous and Discrete Systems 2.5.3.1 Discrete Blocks Each of the discrete blocks has A built-in sampler at ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 84
Provided by: tongy
Category:

less

Transcript and Presenter's Notes

Title: ???


1
???????,?????????????,??????????????????
  • 1??????,?????????????,???????????????Matlab?Simuli
    nk??????
  • 2??????????????????????????????????????????????

2
? ? ? ? ? ? ?
  • ? ? ?
  • 2003.4

3
???????
  • ????????????????????????????
  • ????????,????????????????????,????????????????????
    ??????
  • ??????????????,??????????,?????????????
  • ??????????????????????
  • ??????????????????????????????????????????

4
?????????
  • ????????????????????
  • ??????????????????????????????????????
  • ???????????????????
  • ?????????????????????????????????????????????????

5
???????????
  • ?????????
  • Matlab?Simulink??
  • ????????
  • ???????
  • ?????????

6
??????????????
  • ??????????????????,??????Matlab????????
  • ??????Matlab??????Simulink????S???Simulink?????
  • ????????????????????????,??????????????????

??????????
7
??????????
  • ????-?????????????????????????
  • ????????600V????Simulink???????????????????IGBT??
    ??????????2500Hz??????5Hz???50Hz???????

8
??? ?????????
  • ????????????
  • ?????????????
  • ??????????
  • ?????????
  • ??????????????
  • ??????????
  • ??????????

9
1.1 ????????????
  • ???????????????,??????????????
  • ????????????????????????
  • ??????????????

10
???????????
  • ?????????????
  • ?????????????
  • ????????????
  • ??????
  • ????????????
  • ?????????,?????????
  • ??????????

11
1.2 ?????????????
  • ?????????
  • ?????
  • ???????
  • ????????????
  • ??????????
  • ???????(Electronic Design Automation)

12
1.3 ??????????
  • ??????
  • ????????????
  • ????????????
  • ???????????
  • ??????????
  • ????????

13
1.4 ?????????
?????????
???????
???????
  • ?????????????????????????????????????????????????
    ??????????

14
1.5 ??????????????
  • EDA?????????
  • -??????
  • -??????
  • -???????
  • EDA???????
  • Protel?Pspice?Saber?Matlab

15
1.6 ??????????
  • ????????????????????
  • ??????????????????????
  • ????????
  • ????????????????????

???????
?????????
????????
???????
16
1.7 ??????????
  • ????????????????????????????????,??????,???????
  • ??????????????????????????????????,??????
  • ????????????????????????

17
??? Matlab?Simulink??
  • Matlab?Simulink??
  • MATLAB Installation
  • MATLAB Desktop
  • Array
  • Scripts and Functions
  • Simulink???????
  • Solver
  • S-Function

18
2.0 Matlab?Simulink??
Battery(s) V0 43 0 DC 15V V1 39 0 DC 15V
DISCHARGE V_0 41 0 PULSE(-15 15 196ms 10us
10us 20ms 200ms) OFFSET V_1 5 0 PULSE(5 -5.7
150ms 10us 10us 50ms 200ms) PIBIAS V_2 1 0
PULSE(10 -10 190ms 2us 2us 10ms 200ms)
Misc .TRAN 10us 210ms 0s 10ms UIC
  • Matlab??????????????????????????????
  • ?????????,Matlab??????????????????
  • Matlab????????,Simulink?????????????

????
????
19
2.1 MATLAB Installation
  • The main Products of Matlab for modeling and
    simulating dynamical systems
  • -Matlab
  • -Symbolic Math
  • -Simulink
  • -Control System

20
2.2 MATLAB Desktop
  • Command Window(???)
  • Command History(?????)
  • Launch Pad(?????????)
  • Help Browser(?????)
  • Current Directory Browser(???????)
  • Workspace Browser(???????)
  • Array Editor(???????)
  • Editor/Debugger(M????/???)

21
Current Directory Browser
Command Window
Launch Pad
22
Matlab???????
? ? ?? ? ?
?? ?????????????????
?? , ????????????????????????????????????
?? . ???
?? ???????????????????????
?? ?????????????(????????????)
??? ??????????
??? ??????
??? ( ) ?????????????????????
??? ????????????????????
??? ???????
??? _ ????????????????
???
?????????????? ?????????????? ??????????????
23
2.3 Array
  • Array(??)?????
  • ???Matlab????????
  • Numeric Array(????)
  • ???????
  • Character Array(?????)
  • Cell Array(????)
  • Structure Array(????)

24
2.3.1 Array(??)?????
  • MATLAB works with only a single object-the
    array(??)?
  • ?????????????
  • Its type
  • Its dimensions
  • Its content
  • The data associated with this array
  • If numeric,whether the variable is real or
    complex
  • If a structure,the number of fields and field
    names

25
????????
  • ????????????????,??????????????
  • ??Matlab?????????????????????????????????????????
    ??
  • Matlab?????????????????????????????

26
2.3.2 ???Matlab????????
  • Matlab??????????????
  • Matlab????????
  • Numeric Array,Character Array,Cell Array,
    Structure Array
  • Character Array??????????????
  • Structure Array????Simulink????,??????????????????
    ?

27
2.3.3 Numeric Array(????)
  • ?????Matlab?????????
  • ??????????????

gtgt A1 2 3 4,5 6 7 8 A 1 2 3
4 5 6 7 8 gtgt A1 2 3 45 6 7
8 A 1 2 3 4 5 6
7 8 gtgt A4 ans 4 8 12 16
20 24 28 32
28
2.3.4 ???????
  • ?????
  • ?????

gtgt A(4) ans 6 gtgt A(1,4) ans 4 gtgt A(2,3)0 gtgt
A A 1 2 3 4 5 6 0
8
???
???
A 1 2 3 4 5 6 7
8
29
?????
  • jk is the same as j,j1,...,k
  • jik is the same as j,ji,j2i, ...,k
  • A(,j) is the j-th column of A
  • A(i,) is the i-th row of A

30
2.3.5 Character Array(?????)
  • ?????-?????????
  • ????????????????????
  • ???????????
  • ?????????????

A The exmaple of the Character Arrays'
gtgt A'1234 ''12345' A 1234 12345
gtgt Achar('1234','12345') A 1234 12345
31
???????????
  • Int2str(??????????)
  • Num2str(???????????)

Arand(2,4) A 0.9501 0.6068 0.8913
0.4565 0.2311 0.4860 0.7621
0.0185 Bnum2str(A,2),Cint2str(A) B 0.95
0.61 0.89 0.46 0.23 0.49
0.76 0.019 C 1 1 1 0 0 0 1
0 class(B),class(C) ans char ans char
32
?????????????????
  • clear ?????????
  • a2,w3
  • t00.0110 ????????
  • yexp(-at).sin(wt) ?????,??????
  • y_max,i_maxmax(y) ???????
  • t_textt,num2str(t(i_max)) ?????????????
  • y_texty,num2str(y_max) ?????????????
  • max_textchar('maximum',t_text,y_text) ????????
    ??
  • tit'yexp(-',num2str(a),'t)sin(',num2str(w),'t)
    '
  • plot(t,zeros(size(t)),k) ?????0????
  • hold on
  • plot(t,y,b) ??????
  • plot(t(i_max),y_max,r.,MarkerSize,20) ?????
    ?
  • text(t(i_max)0.3,y_max0.05,max_text) ????????
    ??
  • title(tit),xlabel(t),ylabel(y),hold
    off ??????????????

33
?????????????????
34
2.3.6 Cell Array(????)
  • The elements of a cell array are cells,
    containers that can hold other MATLAB arrays.

35
2.3.6.1 Creating Cell Arrays
Cell indexing(?????) A(1,1) 1 4 3 0 5 8 7
2 9 A(1,2) 'Anne Smith' A(2,1)
37i A(2,2) -pipi/10pi
Content indexin(?????) A1,1 1 4 3 0 5 8 7
2 9 A1,2 'Anne Smith' A2,1
37i A2,2 -pipi/10pi
A(1,1) 1 4 3 0 5 8 7 2 9 A(1,2) 'Anne
Smith' A(2,1) 37i A(2,2)
-pipi/10pi A 3x3 double 'Anne Smith'
3.0000 7.0000i 1x21 double
36
2.3.6.2 Obtaining Data from Cell Arrays
  • ????????????????????
  • ?????????????????

A1,1 ans 1 4 3 0 5 8
7 2 9 A1,1(1,2) ans 4
A(1,1)1 2 34 5 6 A(1,1)2x3
double A1,11 2 3 4
5 6
37
2.3.7 Structure Array(????)
  • The elements of a Structure Array are Structures.
  • Structures are MATLAB arrays with "data
    containers" called fields.
  • The fields of a structure can contain any kind of
    data.
  • Structure Array????????( Structure)
    ,?Structure??????(Field),??????????????

38
2.3.7.1 Structure Array?????
A Structure Array
A Structure
patient.name 'John Doe' patient.billing
127.00 patient.test 79 75 73 180 178 177.5
220 210 205
39
2.3.7.2 Building Structure Arrays
  • ???????
  • patient(2).name 'Ann Lane'
  • patient(2).billing 28.50
  • patient(2).test 68 70 68 118 118 119 172 170
    169
  • ?????struct??
  • patient(2)struct('name','Ann Lane','billing',28.5
    0,'test',68 70 68 118 118 119 172 170 169)
  • patient
  • 1x2 struct array with fields
  • name
  • billing
  • test

40
2.3.7.3 Accessing Data in Structure Arrays
  • ?????????-gt?-gt??

mypatients patient(12) 1x2 struct array with
fields name billing test
mypatients(1) ans name 'John Doe'
billing 127 test 3x3 double
str patient(2).name str Ann Lane
patient(2).test ans 68 70 68 118
118 119 172 170 169
41
2.4 Scripts and Functions
  • Scripts(????), which do not accept input
    arguments or return output arguments. They
    operate on data in the workspace.
  • Functions(????), which can accept input arguments
    and return output arguments. Internal variables
    are local to the function.

42
2.4.1 Scripts
  • When you invoke a script, Matlab simply executes
    the commands found in the file.
  • Scripts can operate on existing data in the
    workspace, or they can create new data on which
    to operate. Although scripts do not return output
    arguments, any variables that they create remain
    in the workspace, to be used in subsequent
    computations.
  • Scripts???Simulink??????????Simulink????????

43
2.4.2 Flow Control
  • Scripts???????????,????Simulink??????????
  • ?????????
  • -if statements
  • -switch statements
  • -for loops
  • -while loops

44
2.4.2.1 if statements
  • ????

if rem(n,2) 0 M odd_magic(n) elseif
rem(n,4) 0 M single_even_magic(n) else
M double_even_magic(n) end
45
2.4.2.2 switch statements
  • ????

switch (rem(n,4)0) (rem(n,2)0) case 0
M odd_magic(n) case 1 M
single_even_magic(n) case 2 M
double_even_magic(n) otherwise
error('This is impossible') end
46
2.4.2.3 for loops
  • For??

for n 332 r(n) rank(magic(n)) end
47
2.4.2.4 while loops
while b-a gt epsb x (ab)/2 fx
x3-2x-5 if sign(fx) sign(fa) a
x fa fx else b x fb fx
end end
  • While(??)??

48
2.4.3 Functions(??)
  • Create a Function
  • Call a Function

function areacircle(r,s) CIRCUIT this is
keyword of the function next is comment
lines clf clear current
figure window sita0pi/1002pi yrexp(isita)
plot(y,s) areapir2
circle(2,'r') ans 12.5664
xcircle(2,'b') x 12.5664
Function??????S-Function
49
2.5 Simulink???????
  • Simulink,the most widely used software package in
    academia and industry for modeling and simulating
    dynamical systems.
  • Interactive,you can change parameters and see
    what happens immediately.
  • Simulink provides a graphical user interface
    (GUI).
  • Simulink is practical,it is being used by
    thousands of engineers around the world.

50
  • Simulink?????
  • Modeling Dynamic Systems
  • Simulating Dynamic Systems
  • Modeling and Simulating Discrete Systems

51
2.5.1 Modeling Dynamic Systems
  • Blocks(??)
  • States(??)
  • System Functions(??????)
  • Continuous and Discrete Blocks(???????)
  • Sample Time(????)

52
2.5.1.1 Blocks(??)
  • Blocks-Each block represents an elementary
    dynamic system that produces an output.
  • Simulink?????????Block??,????????

?????,?????????? u?? x(??)?? y??
53
2.5.1.2 States(????)
  • A block that has a state must store previous
    values of the state to compute its current state.
  • Examples of the blocks that have STATES
  • Integrator,Unit Delay
  • The Simulink Gain block is an example of a
    stateless block.

54
2.5.1.3 System Functions(??????)
  • ??System Functions?????????????
  • 1?An output function(??)Relates the system's
    outputs to its inputs, states, and
    time,yf(t,x,u)
  • 2?An update function(??????) Relates the future
    values of the systems discrete states to the
    current time,inputs, and states,xdk1 f(t,x,u)
  • 3?A derivative function(??????)Relates the
    derivatives of the continuous states to time and
    the present values of the states and inputs,xc
    f(t,x,u)

55
2.5.1.4 Continuous and Discrete Blocks
  • Continuous blocks respond continuously to
    continuously changing input.
  • Discrete blocks respond to changes in input only
    at the block's sample time. Discrete blocks hold
    their output constant between successive sample
    time hits.
  • Some blocks can be either continuous or
    discrete,depending on whether they are driven by
    continuous or discrete blocks.

56
2.5.2 Simulating Dynamic Systems
  • Model Initialization Phase
  • Model Execution Phase
  • Processing at Each Time Step

57
2.5.2.1 Model Initialization Phase
  • During the initialization phase, Simulink
  • 1?Evaluates the model's block parameter
    expressions to determine their values.
  • 2?Flattens the model hierarchy by replacing
    virtual subsystems with the blocks that they
    contain.
  • 3?Sorts the blocks into the order in which they
    need to be executed during the execution phase.
  • 4?Determines signal attributes.
  • 5?Determines the sample times.
  • 6?Allocates and initializes memory used to store
    the current values of each block's states and
    outputs.

58
2.5.2.2 Model Execution Phase
  • Simulink successively computes the states and
    outputs of the system at intervals from the
    simulation start time to the finish time, using
    information provided by the model.
  • The successive time points at which the states
    and outputs are computed are called time steps.
  • The length of time between steps is called the
    step size.
  • Simulink???????????????????????????????????

59
2.5.2.3 Processing at Each Time Step
  • At each time step, Simulink
  • 1?Updates the outputs of the models' blocks in
    sorted order.
  • 2?Updates the states of the model's blocks in
    sorted order.
  • 3?Optionally checks for discontinuities in the
    continuous states of blocks.
  • 4?Computes the time for the next time step.

60
2.5.3 Modeling and Simulating Discrete Systems
  • Discrete Blocks
  • Sample Time
  • Purely Discrete Systems
  • Multirate Systems
  • Determining Step Size for Discrete Systems
  • Sample Time Propagation
  • Invariant Constants
  • Mixed Continuous and Discrete Systems

61
2.5.3.1 Discrete Blocks
  • Each of the discrete blocks has
  • A built-in sampler at its input
  • A zero-order hold at its output

62
2.5.3.2 Sample Time
  • The Sample time parameter sets the sample time at
    which a discrete block's states are updated.
  • Specify an offset time (or skew) by specifying a
    two-element vector in this field.
  • Cannot change the sample time of a block while a
    simulation is running.

63
2.5.3.3 Purely Discrete Systems Multirate
Systems
  • Purely Discrete Systems???????????????????.
  • Multirate Systems??????????????????.

64
2.5.3.4 Determining Step Size for Discrete
Systems
  • The fundamental sample time of a discrete system
    is the greatest integral divisor of the system's
    actual sample times.
  • You can direct Simulink to use either a
    fixed-step or a variable-step discrete solver to
    solve a discrete system.

65
2.5.3.5 Mixed Continuous and Discrete Systems
  • Mixed continuous and discrete systems are
    composed of both sampled and continuous blocks.
  • For most mixed continuous and discrete systems,
    the Runge-Kutta variable step methods, ode23 and
    ode45, are superior to the other methods in terms
    of efficiency and accuracy. Due to
    discontinuities associated with the sample and
    hold of the discrete blocks, the ode15s and
    ode113 methods are not recommended for mixed
    continuous and discrete systems.

66
2.6 Solver(????)
  • The Solver pane allows you to
  • -Set the simulation start and stop times
  • -Choose the solver and specify its parameters
  • -Select output options

67
2.7 Data Exchange Within Simulink and Workspace
  • Workspace I/O Pane-You can direct simulation
    output to workspace variables and get input and
    initial states from the workspace.

68
From Workspace Block To Workspace Block
69
2.8 S-Function
  • What Is an S-Function?
  • -An S-function is a computer language
    description of a Simulink block.
  • When to Use an S-Function?
  • -Adding new general purpose blocks to Simulink
  • -Adding blocks that represent hardware device
    drivers
  • -Incorporating existing C code into a simulation
  • -Describing a system as a mathematical set of
    equations
  • -Using graphical animations (see the inverted
    pendulum demo, penddemo)

70
Mathematics of Simulink Blocks
  • S-Function??????Matlab????????????????
  • S-Function????????????output,derivative,update

71
The stages of a simulation.
  • S-Function????????????????

72
Implementing S-Functions
  • An M-file S-function sys,x0,str,tsf(t,x,u,flag
    ,p1,p2,...)
  • f-S-function's name
  • t-the current time
  • x-the state vector of the S-function block
  • u-the block's inputs
  • flag-indicates a task to be performed
  • p1, p2, -the block's parameters.

73
S-Function????????
74
??? ????????
  • ???????????????
  • Simulink?????
  • Simulink???????

75
3.1 ???????????????
  • ????,?????????????????????????????????
  • ???????????
  • ?????????????,????????
  • Simulink??????????????

76
3.2 Simulink?????
  • ??????Simulink???????????????????????

77
3.3 Simulink???????
  • ?????????????????????????????????????????????????

78
(No Transcript)
79
??? ???????
80
??? ?????????
  • ????1S-Function???
  • ????2Simulink??
  • ????3 Simulink?Workspace?????

81
????1S-Function???
  • ????
  • 1???Timetwo??S-Function???
  • 2???sfcndemo_timestwo.mdl??S-Function????????

82
????2Simulink??
  • ????
  • 1???psbbridges.mdl??Simulink?????
  • 2?????????????
  • 3???Simulink??????????
  • 4??????????????????

83
????3Simulink?Workspace?????
  • ????
  • ??Compare_of_derivative_test.m?compare_of_derivat
    ive.mdl?????????????????
Write a Comment
User Comments (0)
About PowerShow.com