matlab基础教程Simulink基础.doc_第1页
matlab基础教程Simulink基础.doc_第2页
matlab基础教程Simulink基础.doc_第3页
matlab基础教程Simulink基础.doc_第4页
matlab基础教程Simulink基础.doc_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

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

文档简介

第八章 Simulink 基础Chapter 8: 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. imget - Get SIM Options structure Linearization and trimming. linmod - Extract linear model from continuous-time system. linmo - Extract linear model, advanced method. dlinm - 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. 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的三大步骤(procedure of Simulink):1、模型创建与定义、( Model creating and definition)2、模型的分析、(Model analyzing)3、模型的修正。(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模块。利用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. 模块修饰的一个简单示例三 模型中的子系统 把模型中的某些模块组合在一起形成独立的子系统,在主系统 中以子系统模块加入,其作用相当于MATLAB指令运行中的M函数文件。 建立子系统的好处: a, 减少主系统显示在窗口中的模块数目; b, 将功能相关的模块组合在一起,实现进一步模块化的要求; c, 构成一个层次分明的大系统。一)子系统的建立1)、在模型窗口中添加一个subsystem子块,然后把该模块包含的模块添加 进去即可;2)若组成一个子系统的模块已经添加进去,就将这些模块归入一个子系统中。1、在subsystem模块建立子系统*在Simulink Library Browser中打开 Simulingk库,从其中的 Ports$Subsystems 库中选取合适的Subsystem拖至模型窗口中。*双击Subsystem模块,打开Subsystem窗口 ;*将要组合的模块拖至 Subsysytem窗口中,然后在该窗口中加入Input模块表示从子系统外部到内部的输入,加入 Output模块表示从子系统内部到外部的输出,将这些模块按顺序连接起来,子系统便建立成功了。 例:2、组合已有的模块建立子系统如欲将已有的模块群变成子系统,操作较简单,步骤为:*用鼠标划定方框同时选中待组合的模块或按住shift键逐个选中;*选择EditCreate -Subsystem菜单或单击鼠标右键,在弹出菜单中选择CreateSubsystem ,子系统就建成了。例:3、条件执行子系统由某个外部的决定条件确定是否执行的子系统,由输入的控制信号来控制。常用的条件执行子系统为: 1)使能子系统(Enable Subsystem) 使能子系统在控制信号从负数朝正向穿过零时开始执行,直到控制信号变为负数时停止。 使能子系统在外观上有一个“使能”控制信号输入口。当且仅当“使能”信号输入口信号为正时,该模块开始接受In输入口端的信号。 使能子系统包括任何连续和离散的模块。例:建立图示的系统,并保存为test2, 运行观察结果。2) 触发子系统 (Trigger Subsystem) 触发子系统是指当触发事件发生时开始执行的子系统。在它的外观上有一个“触发”控制信号输入口,仅当触发输入信号所定义的某个事件恰巧发生时,该模块才开始接受In输入端的信号。子系统一旦触发,其输出端口的值就保持不变,直到下次再触发才可能改变。“触发事件”由子系统内触发模块对话框定义,有4种触发事件可供选择:*rising 上升沿触发*falling 下降沿触发*either 任意沿触发*function-call 函数调用触发注:一般的连续时间模块不能置于触发子系统中。例:利用触发子系统获取零阶保持的采样信号实例 (1)构造一个仿真模型,保存为test2 (2) 设置模块参数:Pulse Generator: Amplitude 为1,Period 为 1,Pulse Width为50, Phase delay为0;Sine Wave: Amplitude为1,Frequency为1, Phase为0, Start time为0 (3)在MATLAB命令窗口中运行Simulink模型, 该模型被保存在MATLAB搜索路径上,在命令窗口中运行如下命令:t,x,y=sim(jk,10); %调用模型test2,产生时间向量t、状态矩clf, %阵x和输出矩阵yhold onplot(t,y(:,1),b) stairs(t,y(:,2),r)stairs(t,y(:,3),g)hold offaxis(0 10 -1.1 1.1),box onlegend(正弦波,输出,三角形,4)运行后即可输出结果.Sim 命令能使用户在 MATLAB命令窗口或M中运行由Simulink建立的模型。其格式为:t,x,y=sim(modlelname,timespan,options,ut)t:返回仿真的时间向量x:仿真的状态矩阵y:仿真的输出矩阵modelname:被运行的模型名timespan:时间带宽options:一种特定的用于指定仿真参数的结构数据;ut:向顶层输入端口模块输入的外部数据。l SIM: Simulate a Simulink model SimOut = SIM(MODEL, PARAMETERS) simulates your Simulink model, where PARAMETERS represents a list of parameter name-value pairs, a structure containing parameter settings, or a configuration set. The SimOut returned by the SIM command is an object that contains all of the logged simulation results. Optional PARAMETERS can be used to override existing block diagram configuration parameters for the duration of the simulation. This syntax is referred to as the Single-Output Format. SINGLE-OUTPUT FORMAT SimOut = SIM(MODEL,PARAMETER_NAME1,VALUE1,PARAMETER_NAME2,VALUE2, .) SimOut = SIM(MODEL, PARAM_NAME_VAL_STRUCT) SimOut = SIM(MODEL, CONFIGSET) All simulation outputs (logged time, states, and signals) are returned in asingle Simulink.SimulationOutput object. Using the models Configuration Parameters Data Import/Export dialog, you define the model time, states, andoutput to be logged. You can log signals using blocks such as the To Workspace and Scope blocks. The Signal & Scope Manager can directly log signals. Where:SimOut : Returned Simulink.SimulationOutput object containing all of the simulation output. MODEL : Name of a block diagram model. PARAMETER_NAMEk: Name of the Configuration or Block Diagram parameter. VALUEk : Value of the corresponding Configuration or Block Diagram parameter. PARAM_NAME_VAL_STRUCT : This is a structure whose fields are the names of the block diagram or the configuration parameters that are being changed for the simulation. The corresponding values are the corresponding parameter values. CONFIGSET : The set of configuration parameters for a model. The single-output format makes the SIM command compatible with PARFOR by eliminating any transparency issues. See Running Parallel Simulations in the Simulink documentation for further details. Example 1: simOut = sim(vdp,SimulationMode,rapid,AbsTol,1e-5,. SaveState,on,StateSaveName,xoutNew,. SaveOutput,on,OutputSaveName,youtNew); simOutVars = simOut.who; yout = simOut.find(youtNew); Example 2: paramNameValStruct.SimulationMode = rapid; paramNameValStruct.AbsTol = 1e-5; paramNameValStruct.SaveState = on; paramNameValStruct.StateSaveName = xoutNew; paramNameValStruct.SaveOutput = on; paramNameValStruct.OutputSaveName = youtNew; simOut = sim(vdp,paramNameValStruct); Example 3: mdl = vdp; load_system(mdl); simMode = get_param(mdl, SimulationMode); set_param(mdl, SimulationMode, rapid); cs = getActiveConfigSet(mdl); mdl_cs = cs.copy; set_param(mdl_cs,AbsTol,1e-5,. SaveState,on,StateSaveName,xoutNew,. SaveOutput,on,OutputSaveName,youtNew); simOut = sim(mdl, mdl_cs); set_param(mdl, SimulationMode, simMode); DEFAULTS: 1. R = SIM(MODEL) returns the result R as either a Simulink.SimulationOutput object or a time vector that is compatible with a Simulink version prior to 7.4 (R2009b). * To make SIM(MODEL) return in the single-output format, use the ReturnWorkspaceOutputs option: * SimOut = SIM(MODEL, ReturnWorkspaceOutputs, on) 2. To set the single-output format as the default format, select the Return as single output option on the Data Import/Export pane of the Configuration Parameters dialog box and save the model. BACKWARDS COMPATIBLE FORMAT: Simulink Version 7.3 AND PRIOR RELEASES - | T,X,Y = SIM(MODEL,TIMESPAN,OPTIONS,UT) | T,X,Y1,.,Yn = SIM(MODEL,TIMESPAN,OPTIONS,UT) | T,X,Y1,.,Yn = SIM(MODEL,TIMESPAN,OPTIONS,UT) | | The following syntax is now obsolete but will be maintained for backwards | compatibility. If only one right-hand side argument exists, then | Simulink automatically saves the time, the state, and the output to the | specified left-hand side arguments. You can explicity switch to the | single-output format by changing the defaults as described above. | If you do not specify any left-hand side arguments, then Simulink | determines what data to log based on the Workspace I/O settings | of the Simulation Parameters dialog box. | DESCRIPTION OF BACKWARDS COMPATIBLE SIM ARGUMENTS: | T : Returned time vector. | X : Returned state in matrix or structure format. | The state matrix contains continuous states followed by discrete states. | Y : Returned output in matrix or structure format. | For block diagram mod

温馨提示

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

评论

0/150

提交评论