matlab教学教案课件第八章+simulink+基础_第1页
matlab教学教案课件第八章+simulink+基础_第2页
matlab教学教案课件第八章+simulink+基础_第3页
matlab教学教案课件第八章+simulink+基础_第4页
matlab教学教案课件第八章+simulink+基础_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第七章 Simulink 基础Chapter 7: Introduction to Simulink一 Simulink 初步(Primer of Simulink)MATLAB Simulink是一个动态仿真系统,用于对动态系统进行仿真和分析,预先模拟实际系统的特性和响应,根据设计和使用要求,对系统进行修改和优化。Simulink提供了图形化用户界面,只须点击鼠标就可以轻易的完成模型的创建、调试和仿真工作,用户不须专门掌握一种程序设计语言。Simulink可将系统分为从高级到低级的几个层次,每层又可以细分为几个部分,每层系统构建完成后,将各层连接起来构成一个完整系统。模型创建完成后,可以启动系统的仿真功能分析系统的动态特性,其内置的分析工具包括各种仿真算法、系统线性化、寻求平衡点等。仿真结果可以以图形方式在示波器窗口显示,也可将输出结果以变量形式保存起来,并输入到MATLAB中以完成进一步的分析。Simulink可以仿真线性和非线性系统,并能创建连续时间、离散时间或二者混合的系统。支持多采样频率系统。Simulink Version 6.0 (R14) 05-May-2004 Model analysis and construction functions.Simulation sim - Simulate a Simulink model. sldebug - Debug a Simulink model. simset - Define options to SIM Options structure. simget - Get SIM Options structure Linearization and trimming. linmod - Extract linear model from continuous-time system. linmod2 - Extract linear model, advanced method. dlinmod - Extract linear model from discrete-time system. trim - Find steady-state operating point. Model Construction. close_system - Close open model or block. new_system - Create new empty model window. open_system - Open existing model or block. load_system - Load existing model without making model visible. save_system - Save an open model. add_block - Add new block. add_line - Add new line. delete_block - Remove block. delete_line - Remove line. find_system - Search a model. hilite_system - Hilite objects within a model. replace_block - Replace existing blocks with a new block. set_param - Set parameter values for model or block. get_param - Get simulation parameter values from model. add_param - Add a user-defined string parameter to a model. delete_param - Delete a user-defined parameter from a model. bdclose - Close a Simulink window. bdroot - Root level model name. gcb - Get the name of the current block. gcbh - Get the handle of the current block. gcs - Get the name of the current system. getfullname - get the full path name of a block slupdate - Update older 1.x models to 3.x. addterms - Add terminators to unconnected ports. boolean - Convert numeric array to boolean. slhelp - Simulink users guide or block help. Masking. hasmask - Check for mask. hasmaskdlg - Check for mask dialog. hasmaskicon - Check for mask icon. iconedit - Design block icons using ginput function. maskpopups - Return and change masked blocks popup menu items. movemask - Restructure masked built-in blocks as masked subsystems. Library. libinfo - Get library information for a system. Diagnostics. sllastdiagnostic - Last diagnostic array. sllasterror - Last error array. sllastwarning - Last warning array. sldiagnostics - Get block count and compile stats for a model. Hardcopy and printing. frameedit - Edit print frames for annotated model printouts. print - Print graph or Simulink system; or save graph to M-file. printopt - Printer defaults. orient - Set paper orientation. simulink is both a directory and a function.Copyright 1990-2004 The MathWorks, Inc. Simulink的三大步骤(procedure of Simulink):模型创建与定义、( Model creating and definition)模型的分析、(Model analyzing)模型的修正。(Model modifying)Simulink的运行:(Running of Simulink)1、运行Simulink:命令窗口下点击Simulink图标(或键入Simulink命令)Simulink Library Browser(浏览器)simulink树状列表形式的模块库(包含simulink模块库中的各种模块及其它Toolbox和 Blockset中的模块)2、选择建模模块:展开树状列表,用鼠标点击所需类别的模块项, 所选模块类的具体模块库就在右侧的列表框中显示出来,提供建模使用。也可以在在输入栏中键入模块名并点击Find按钮进行查询。3、打开模型创建窗口:(open the window of mode creating)。在工具栏中选择“建立新模型”的图标,弹出名为Untitled的空白窗口,选择Open窗口可以打开存于硬盘中已建的模型,完成模型的运行或修改。二 Simulink 的常用基本模块(basic module)simulink浏览器窗口左侧的simulink项上单击鼠标右键,弹出菜单“Open the SimulinkLabrary”选项,将打开simulink模块库窗口。1信号源模块:source,模块及功能见(表 81)2输出模块:Sinks, 模块及功能见(表 82)3. 连续系统模块: Continuous, 模块及功能见(表 83)4. 离散系统模块:Discrete, 模块及功能见(表 84)5. 数学运算模块:Math, 模块及功能见(表 85)6函数和表模块: Function & Tables, 模块及功能见(表 86)7. 非线性系统模块:Nonlinear, 模块及功能见(表 87)8. 信号与系统模块:Signal & Systems, 模块及功能见(表 88)还有:Commonly used blocks 常用模块Discontinuous 非连续模块Logical and bit operation 逻辑运算和二进制数位模块Lookup tables 插值表Model Verification 模式识别Ports and subsystems 端口及子系统User defined functions 用户自定义函数Additional math and discrete 辅助数学和离散系统表 81信号源模块及功能模 块功 能模 块功 能In1创建输入端Ground接地Constant常数Clock当前时间SignalGeneratur信号发生器Digital Clock数字时钟Ramp斜波From File从文件读数据SineWave正弦波FromWorkspace从工作空间读数据Step阶跃信号Random Number随机信号Repeating Sequence重复系列UniformRandomNumber均匀随机信号Pulse Generator脉冲发生器Band-LimitedWhileNoise带限白噪音Chirp Signal 快速正弦扫描 表 82输出模块及功能模块功能模块功能Scope示波器To file输出到文件Floating Scope可选示波器To Workspace 输出到工作空间XY GraphXY显示器Terminator通用终端Out1创建输出端Stop Simulation输入不为0时停止仿真Display实时数据显示 表 83连续系统模块及功能模块功能模块功能Integrator积分Zero-Pole 零极点Derivative微分Memory延时输出Statae-Space状态方程Transport Delay传输延时Transfer Fcn传递函数VariableTransport Delay可变传输延时 表 84离散系统模块及功能模块功能模块功能Zero-Order-Hold零阶保持器Discrete Filter离散滤波器Unit Delay单位延时采样保持Discrete Transfer Fcn离散传递函数Descrete-Time Integrator离散时间积分Discrete Zero-pole离散零极点Discrete-State-Space离散状态方程First-Order Hold一阶保持器 表 85数学运算模块及功能模块功能模块功能Sum求和Rounding Function取整函数Product积或商Combinatorial Logic逻辑真值表Dot Product点积Logical Operator逻辑算子Gain常数增益Bitwise Logical Operator位逻辑算子Slider Gain可变增益Relational Operator关系算子Matrix Gain矩阵增益Complex to Magnitude-Angle复数的模和辅角Math Function数学运算函数Magnitude-Angle to Complex模和辅角合成复数Trigonometric Function三角函数Complex to Real-Imag复数的实部和虚部NinMax求最大值Real-Imag to Complex实部和虚部合成复数Abs求绝对值Algebraic Constant强迫输入信号为零Sign符号函数 表 86函数和表模块及功能模块功能模块功能Look-Up Table线性插值查表FcnC语言形式的表达式Look-Up Table (2-D)二维线性插值MATLAB Fcn MATLAB形式的表达式Look-Up Table (n-D)N维线性插值S-Function调用S-函数Prelook-Up Index Search预查下标Polynomial多项式InterPolation (n-D) Using PreLook-UpN维插值S-Function Builder用C代码创建S-函数Direct Look-Up Table(n-D)直接查表 表 87非线性系统模块及功能模块功能模块功能Rate Limiter速率限制器Relay继电器Saturation饱和元件Switch开关Quantizer量化元件Maunal Switch手动开关Backlash间隙元件Multiport Switch多选开关Dead Zone死区元件Coulomb & Viscous Friction库仑和粘性摩擦 表 88信号与系统模块及功能模块功能模块功能Bus Creator创建信号总线Data Store Memory为存储器定义内存Bus Selector从信号总线中选择信号Data Store Write向存储器写数据Mux多路传输器Function-Call Generator 函数调用发生器Demux多路分离器Reshape改变信号尺寸Selector选择输入信号Data Type Conversion数据类型转换Assignment赋值Hit Crossing检测零交叉点Matrix Concatenation矩阵串联IC信号的初始值Merge信号合并Width信号的宽度From从GOTO模块接收信号Model Info显示模型信息Goto Tag Visibility定义GOTO模块的范围Signal Specification检查信号参数Goto把信号送到From模块Probe探测连线Data Store Read从存储器读数据可选示波器(Floating scope):可将普通示波器转变为Floating scope,也可在模型库中直接选择Floating scope模块。利用Floating scope模块可选择显示一或多个线程上的信号,模块不必与模型中的信号线连接,可以在signal selection 快捷键打开的菜单中选择要显示的信号。*Floating scope: This option appears only on the General parameters pane for the Scope block. Selecting this option turns a Scope block into a floating scope. A floating scope is a Scope block that can display the signals carried on one or more lines. You can create a Floating Scope block in a model either by copying a Scope block from the Simulink Sinks library into a model and selecting this option or, more simply, by copying the Floating Scope block from the Sinks library into the model window. The Floating Scope block has the Floating scope parameter selected by default. To use a floating scope during a simulation, first open the scope. To display the signals carried on a line, select the line. Hold down the Shift key while clicking another line to select multiple lines. It might be necessary to click the Autoscale data button on the floating scopes toolbar to find the signal and adjust the axes to the signal values. Or you can use the floating scopes Signal Selector (see The Signal Selector in the online Simulink documentation) to select signals for display. To display a floating scopes Signal Selector, first start simulation of your model with the floating scope open. Then right-click your mouse in the floating scope and select Signal Selection from the pop-up menu that appears. You can have more than one floating scope in a model, but only one set of axes in one scope can be active at a given time. Active floating scopes show the active axes by making them blue. Selecting or deselecting lines affects the active floating scope only. Other floating scopes continue to display the signals that you selected when they were active. In other words, inactive floating scopes are locked, in that their signal displays cannot change. To specify display of a signal on one of the axes of a multiaxis floating scope, click the axis. Simulink draws a blue border around the axis. Then click the signal you want to display in the block diagram or the Signal Selector. When you run the model, the selected signal appears in the selected axis. If you plan to use a floating scope during a simulation, you should disable signal storage reuse. See Signal storage reuse in Optimizations for more information三. Simulink 建模(Simulinc module creating)1 模块的创建与操作(Creating and operation of Simulink)(1) 创建模块:(module creating)()在浏览器列表中点击需要的模块,按住鼠标左键并拖曳至模型窗口即可。()双击模块可在弹出的对话框中修改相应的模块参数()在模块下方名称处双击可改变模块名称。(2)模块操作(module operation)(a)模块的选择(module selection)(b)移动模块 (module moving)(c)模块的缩放(modulee scaling)(d) 复制模块:(module copy)四种方法: 在选定模块处,按下鼠标右键并拖动至适当位置; 选定模块,在工具栏中(或Edit菜单中)选中Copy与Paste按钮; 在选定的模块处点击鼠标右键,在弹出的菜单中选择Copy与Paste选项; 按住”Ctrl”键,按下鼠标左键,将选定的模块拖至适当的位置。(e)模块的旋转与翻转:(Rotating and turnover of module)旋转:(rotate)将鼠标指向要翻转的模块并按下鼠标右键,选择弹出菜单中的Format栏中的Rotate项,模块顺时针旋转o。翻转:将鼠标指向要翻转的模块并按下鼠标右键,选择弹出菜单中的Format栏中的Flip Block项,模块顺时针旋转180o。(f) 模块的连接 (h)连接分支线 (i)改变连线的形状 (j)连线的标识:在连线的上或下方(或窗口内任何位置)双击鼠标左键,可出现一个文本框用于输入说明文字。(3)简单模型(Simple mode) 信号发生器发生幅值为,频率为0.2HZ的正弦波信号,信号分别按倍和倍送入两个示波器。2 模型的修饰(Mode modifying) 1. 模块加阴影:Format菜单中的Show drop shadow菜单项用于给模块加阴影。2. 调整颜色:Format菜单中的Foreground color菜单项用于调整模块的前景颜色。Background color菜单项用于选择模块的背景颜色。Screen color菜单项用于调整屏幕颜色。3. 变换模块名的显示位置:Format 菜单中的Flip name可将模块名换到对称的位置,Hide name可将模块名隐藏起来。 4. 模块修饰的一个简单示例三 仿真计算与分析方法(simulink calculation and the method of analyzing)1连续系统建模(Module creating of continuous system)(1)用积分模块创建微分方程求解的模型(creating the solve mode of differential equation with integral modules): 有二阶微分方程x+0.2x+0.4x=0.2u(t), u(t)是单位阶跃函数,演示如何用积分器直接创建求解该微分方程的模型。(a) 改写微分方程为(reforming differential equation): x=0.2u(t)-0.2x-0.4x(b) 利用Simulink库中的标准模块建模(Creating mode with modules in the library of Simulink) :基本思路是x经积分后得 x,再积分得 x,再将 x和 x经代数运算得到 x。结果送入示波器,也可同时存储在工作空间变量simy中。(2)用传递函数模块求解(Solving by transfer function module):以二阶微分方程x+0.2x+0.4x=0.2u(t)为例, 初始状态为0,u(t)是单位阶跃函数。对方程两边进行Laplace变换,得到: s2X(s)+0.2sX(s)+0.4X(s)=0.2U(s)整理后得传递函数:(Transfer function) G(s)=X(s)/U(s)=0.2/(s2+0.2s+0.4)利用上式采用传递函数模块可建立求解微分方程的模型。2、将MATLAB工作空间中信号矩阵作为模型输入:利用From Workspace模块实现例:模拟下述方程表达的结果 t2 (0tT)U(t)= (2T-t)2 (Tt2T) 0 (其他)(1)首先编写一个信号矩阵的M函数文件:function TU=source(TO,NO,K)t=linspace(0,K*TO,K*NO+1);N=length(t);u1=t(1:(NO+1).2;u2=(t(NO+2):(2*NO+1)-2*TO).2;u3(1:(N-(2*NO+2)+1)=0;u=u1,u2,u3;TU=t,u;(2)以source文件名保存,(3)然后建立一个简单的具有接收workspace信号并显示结果的模型。(4)在命令窗口运行TU=source(2,200,6),便在Workspace中产生一个TU信号矩阵。(5)再运行所创建的simulink模型就可得到输出结果。执行simulink后检查输出结果并做进一步的分析与判断。(1) 输出信号的观察(output signal observation)(a) 将信号输出到显示模块(Export signal to display module)* Scope(示波器):将信号显示在示波器的独立窗口中,通过双击模块即可打开示波器模块。* XY Graph 显示器模块:在MATLAB图形窗口绘制二维图形, * Display模块:将结果以数字形式显示出来,在模块中直接滚动显示。标量、矢量和矩阵形式得结果输出窗口结构略有不同。(b)将仿真结果存储到工作空间,再用绘图命令在命令窗口绘制图形,(save the result of simulink to workspace and plotting figure on window by using plot command) 有三种方法可供选择:* 通过示波器模块向工作空间存储数据;* 通过选择Sinks函数库中的To workspace模块,将数据保存到工作空间的simout变量中,同时还可以产生一个存放时间数据的变量(缺省tout);*通过Simulation菜单选择Simulation Paremeter菜单项中的WorkspaceI/O页,根据各个参数的选择来确定存储的数据内容的类型。(c). 将仿真结果通过输出端口返回到MATLAB命令窗口,再利用绘图命令绘出输出图形 (return the result of simulink from export to MATLAB window and then drawing the plot on window by using plot command) :在Sinks函数库中有一个名为Out1的模块,将数据输入到这个模块,该模块就会将数据输出到 MATLAB 命令窗口,并用名为 yout的变量保存,同时还将时间数据用 tout变量保存。 存储在工作空间的结果可以进行进一步的分析。2使用一般的分析工具(the using of General analysis tool) (a). 线性化:将状态空间所描述的线性系统输入输出关系由下式表示:x=Ax+Buy=Cx+Du其中:x 代表状态矢量y代表输出矢量u代表输入矢量A,B,C,D为系统线性化的状态空间矩阵 如创建用于线性化的系统模型名为lmod,并保存为”lmod.mdl”.在命令窗口输入命令 A B C D=linmod(lmod)就可以获得系统的常微分方程 lmod的状态空间线性模型,返回系统线性化的状态空间矩阵。A B C D=linmod(lmod)(A,B,C,D=LINMOD(SYS) obtains the state-space linear model of the system of ordinary differential equations described in the block diagram SYS when the state variables and inputs are set to the defaults specified in the block diagram.)(b)由状态方程转成LTI对象(transfer state equations to LTI object):一旦数据形成了状态空间形式或者转变成了LTI对象,就可以使用Control System Toolbox函数进行进一步的分析。利用ss函数可将上面线性化的系统转成LTI对象,命令格式为: sys=ss(A,B,C,D)(c) 绘制波德图:(Bode plot drawing) 用bode 函数可绘制波德图,(相位、幅值与频率的关系图)bode(A,B,C,D) 或 bode(sys) BODE(SYS) draws the Bode plot of the LTI model SYS (created with either TF, ZPK, SS, or FRD). The frequency range and number of points are chosen automatically.(d)线性时间响应(Linear time response):给一个阶跃信号(step signal):step(A,B,C,D) 或 step(sys) 线性化阶响应或给一个脉冲信号(impulse):impulse(A,B,C,D) 或 impulse(sys)线性化脉冲响应(e)求系统平衡点(find the balance point of system):在非线性系统中,分析评估系统稳定性或稳定状态时大多需要用到平衡点。平衡点是指所有状态导数等于零的点。若仅有部分状态导数等于零,则称为偏平衡点。要使输出为1,并找出输入以及状态值时,可用”trim”函数来实现。以前面创建的”lmod”模型为例:%第一步:对状态变量x以及输入u做初步设定,并设定想要的输出值。 x=0;0;0;u=0;y=1;1;%第二步:使用索引变量确定那些值可变,那些是固定不变的。 ix= ; %任何状态值可变 iu= ; %任何输入可变 iy=1,2; %两个输出不能变%第三步:调用trim函数,求出系统平衡点。 x,u,y,dx=trim(lmod,x,u,y,ix,iu,iy)A,B,C,D=LINMOD(lmod) %系统线性化的状态空间矩阵sys=ss(A,B,C,D) %由状态方程转成LTI对象figure(1)bode(sys) %绘制波德图,(相位、幅值与频率的关系图)figure(2)step(A,B,C,D) %线性时间响应x=0;0;0; %设定状态变量u=0; %设定输入值y=1;1; %设定想要的输出值ix=; %表示状态不固定iu=; %表示输入不固定iy=1,2; %固定第一个输出及第二个输出x,u,y,dx=trim(lmod,x,u,y,ix,iu,iy) %求系统平衡点A = -1 0 -2 -2 1 1 0 1 0B = 0 1 0C = -2 0 0 0 0 -2D = 1 0a = x1 x2 x3 x1 -1 0 -2 x2 -2 1 1 x3 0 1 0b = u1 x1 0 x2 1 x3 0c = x1 x2 x3 y1 -2 0 0 y2 0 0 -2 d = u1 y1 1 y2 0x = 1.3333 0.0000 -0.6667u = 3.3333y = 0.6667 1.3333dx = 1.0e-015 * 0 -0.1110 0.0000Simulink命令集仿真命令sim仿真运行一个simulink模块sldebug调试一个simulink模块simset设置仿真参数simget获取仿真参数线性化和整理命令linmod从连续时间系统中获取线性模型linmod2也是获取线性模型,采用高级方法dinmod从离散时间系统中获取线性模型trim为一个仿真系统寻找稳定的状态参数构建模型命令open_system打开已有的模型close_system关闭打开的模型或模块new_system创建一个新的空模型窗口load_system加载已有的模型并使模型不可见save_system保存一个打开的模型add_block添加一个新的模块add_line添加一条线(两个模块之间的连线)delete_block删除一个模块delete_line删除一根线find_system查找一个模块hilite_system使一个模块醒目显示replace_block用一个新模块代替已有的模块set_param为模型或模块设置参数get_param获取模块或模型的参数add_param为一个模型添加用户自定义的字符串参数delete_param从一个模型中删除一个用户自定义的参数bdclose关闭一个simulink窗口bdroot根层次下的模块名字gcb获取当前模块的名字gcbh获取当前模块的句柄gcs获取当前系统的名字getfullname获取一个模块的完全路径名slupdate将1.x的模块升级为3.x的模块addterms为未连接的端口添加terminators模块boolean将数值数组转化为布尔值slhelpsimulink的用户向导或者模块帮助封装命令hasmask检查已有模块是否封装hasmaskdlg检查已有模块是否有封装的对话框hasmaskicon检查已有模块是否有封装的图标iconedit使用ginput函数来设计模块图标maskpopups返回并改变封装模块的弹出菜单项movemask重建内置封装模块为封装的子模块库命令libinfo从系统中得到库信息诊断命令sllastdiagnostic上一次诊断信息sllasterror上一次错误信息sllastwarning上一次警告信息sldiagnostics为一个模型获取模块的数目和编译状态硬拷贝和打印命令frameedit编辑打印画面print将simulink系统打印成图片,或将图片保存为m文件printopt打印机默认设置orient设置纸张的方向常用Simulink模块简介Sources库中模块Band-LimitedwhiteNoise给连续系统引入白噪声ChirpSignal产生一个频率递增的正弦波(线性调频信号)Clock显示并提供仿真时间Constant生成一个常量值CounterFree-Running自运行计数器,计数溢出时自动清零CounterLimited有限计数器,可自定义计数上限DigitalClock生成有给定采样间隔的仿真时间FromFile从文件读取数据FromWorkspace从工作空间中定义的矩阵中读取数据Ground地线,提供零电平PulseGenerator生成有规则间隔的脉冲In1提供一个输入端口Ramp生成一连续递增或递减的信号Rand

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论