Simulink入门指南

合集下载

simulink 入门

simulink 入门
模型操作
打开与关闭模型 保存模型 打印与拷贝模型 模型属性与注释
实时系统与硬件设计
Simulink Fixed Point Real-Time Windows Target xPC Target xPC Target Embedded Option Simulink HDL Coder Simulink PLC Coder Instrument Control Toolbox Video and Image Processing Blockset
2. Simulink建模的基础知识
Math Operations (数学模块库)
Abs & Sign :绝对值与符号函数 add & Sum:加减 Product & Divide:乘除 MinMax:最值运算 Gain:增益 Slider Gain:滑动增益 Math Function:数学函数 Trigonometric Function:三角函数 复数运算 取整运算 …
2. Simulink建模的基础知识
Discrete (离散模块库)
Discrete-time Integrator:离散积分 Discrete Derivative:离散微分 Discrete Filter:离散滤波器 Discrete PID Controller:离散PID控制器 Discrete Transfer Fcn:离散传递函数模型 Discrete Zero-Pole:离散零极点传递函数模型 Discrete State-Space:离散状态空间模型 First-Order Hold:一阶采样保持器 Zero-Order Hold:零阶采样保持器 Unit Delay:一个采样周期的延时 Memory:存储器 …

SIMULINK基础详解

SIMULINK基础详解

表10-6
通用模块及功能 模块名 功能 提供一个输入端口 地线,提供零电平 地线, 模块名 功能 提供一个输出端口 终止没有连接的输出 端口 示波器
生成一个常量值
选择开关
乘运算
比例运算 关系运算 饱和输出,让输出超 饱和输出, 过某一值时能够饱和
逻辑运算 积分器 数据类型转换
7、 信号路径模块库(signal routing) 、 信号路径模块库( ) 信号路径模块库提供了信号在模型中流动的各种路径通道 的选择,包括信号的分离、汇合以及通道选择等模块, 的选择,包括信号的分离、汇合以及通道选择等模块,如表 10-7所示: 所示: 所示
Simulink提供了大量的系统模功能模块,包括信号发生、 提供了大量的系统模功能模块,包括信号发生、 提供了大量的系统模功能模块 控制运算、显示等通用模块和很多专业性极强的专业模块, 控制运算、显示等通用模块和很多专业性极强的专业模块, 应用这些模块可以轻松实现各个学科的工程仿真和研发工作。 应用这些模块可以轻松实现各个学科的工程仿真和研发工作。 Simulink提供的系统功能模块的另一个大的特点是开放性强, 提供的系统功能模块的另一个大的特点是开放性强, 提供的系统功能模块的另一个大的特点是开放性强 可以将几个相关的模块组合成一个具体的子系统, 可以将几个相关的模块组合成一个具体的子系统,也可以自 己创建模块并将创建的新模块加入到系统模块库中供建模使 用。
6、 通用模块库(Commonly Used Blocks) 、 通用模块库( ) 通用模块库中提供了一般建模常用的模块,这些模块在 通用模块库中提供了一般建模常用的模块, 各自的分类模块库中均能找到,但为了使用方便, 各自的分类模块库中均能找到,但为了使用方便,特将一些 常用的模块集中起来组成了该库如表10-6所示: 所示: 常用的模块集中起来组成了该库如表 所示

Simulink动态系统仿真入门

Simulink动态系统仿真入门

Simulink动态系统仿真入门Simulink是基于MA TLAB的图形化仿真设计环境,是MATLAB 提供的进行动态系统建模、仿真和综合分析的集成软件包。

它使用图形化的系统模块对动态系统进行描述,并在此基础上采用MATLAB 的计算引擎对动态系统在时域内进行求解。

它可以处理的系统包括:线性、非线性、离散、连续及混合、单任务、多任务离散事件等。

在MATLAB7.X版本中,可以直接在Simulink环境中运作的工具箱和模型库很多,已经覆盖了航天、航空、通信、控制、信号处理等等诸多领域,涉及内容专业性很强。

1、Simulink系统的启动由于Simulink和MATLAB是高度集成在一起的,因此启动Simulink必须先启动MA TLAB。

在MA TLAB启动Simulink可以通过在命令窗口输入Simulink,或者点击MATLAB工具栏的Simulink 快速启动图标。

启动Simulink后,出现Simulink的主窗口,选择主菜单File中的New\model,即可以打开系统模型编辑器。

下图依次是MATLAB 主窗口、Simulink主窗口和系统模型编辑窗口,图中的箭头表示了操作顺序。

在打开一个新的系统模型文件以后,用户可以从Simulink模块库中选择适合的系统模块或自定义模块来建立系统模型。

我们通过一个简单的例子来分步说明Simulink建模和仿真的能力。

1)在MATLAB 窗口运行Simulink。

打开Simulink模块库浏览器。

2)点击Source子库前的“+”展开库,可以看到各种信源模块。

3)点击新建图标,打开一个空白型的模型窗口。

4)用鼠标选中需要的信源模块,把它拖入新建的空白模型编辑窗口,生成一个正弦波的复制品。

5)同样将信宿库Sinks中的示波器Scope拷贝到模型窗口。

6)利用鼠标完成两个模块的连线操作,完成一个简单的模型。

7)为进行仿真,双击示波器模块,打开示波器显示屏。

matlab-simulink初级教程

matlab-simulink初级教程

Simulink仿真环境基础学习Simulink是面向框图的仿真软件。

7.1演示一个Simulink的简单程序【例7.1】创建一个正弦信号的仿真模型。

步骤如下:(1) 在MATLAB的命令窗口运行simulink命令,或单击工具栏中的图标,就可以打开Simulink模块库浏览器(Simulink Library Browser) 窗口,如图7.1所示。

图7.1 Simulink界面(2) 单击工具栏上的图标或选择菜单“File”——“New”——“Model”,新建一个名为“untitled”的空白模型窗口。

(3) 在上图的右侧子模块窗口中,单击“Source”子模块库前的“+”(或双击Source),或者直接在左侧模块和工具箱栏单击Simulink下的Source子模块库,便可看到各种输入源模块。

(4) 用鼠标单击所需要的输入信号源模块“Sine Wave”(正弦信号),将其拖放到的空白模型窗口“untitled”,则“Sine Wave”模块就被添加到untitled窗口;也可以用鼠标选中“Sine Wave”模块,单击鼠标右键,在快捷菜单中选择“add to 'untitled'”命令,就可以将“Sine Wave”模块添加到untitled窗口,如图7.2所示。

(5) 用同样的方法打开接收模块库“Sinks”,选择其中的“Scope”模块(示波器)拖放到“untitled”窗口中。

(6) 在“untitled”窗口中,用鼠标指向“Sine Wave”右侧的输出端,当光标变为十字符时,按住鼠标拖向“Scope”模块的输入端,松开鼠标按键,就完成了两个模块间的信号线连接,一个简单模型已经建成。

如图7.3所示。

(7) 开始仿真,单击“untitled”模型窗口中“开始仿真”图标,或者选择菜单“Simulink”——“Start”,则仿真开始。

双击“Scope”模块出现示波器显示屏,可以看到黄色的正弦波形。

Simulink入门

Simulink入门

Slider Gain Sum Trigonometric Function
:以滑动形式改变增益 :对输入信号进行求和 :三角函数
7.Signals & Systems 连接和接口器件 . Systems的连接和接口器件库中有25个元件 的连接和接口器件库中有 个元件: 在Signals & Systems的连接和接口器件库中有 个元件: Subsystem :表示一个系统在另外一个系统中 In1 In1 :子系统或模块的一个输入端口 激活子系统, Enable :激活子系统,只能在子系统中用 触发子系统, Trigger :触发子系统,只能在子系统中用 Bus Selector :总线选择 Configurable Subsystem :设定系统 Data Store Memory :定义数据寄存器 Data Store Read :读寄存器 Data Store Write :写寄存器 Data Type Conversion :转换输入数据的类型 Demux :把向量信号分开输出
Band—Limited Band Limited White Noise Chirp Signal Clock Constant Digital Clock Discrete Pulse Generator From File From Workspace Pulse Generator Ramp Random Number Repeating Sequence Signal Generator Sine Wave Step Uniform Random Number
第六章 Simulink仿真软件及应用 仿真软件及应用
6.1 SIMULINK简介环境 简介环境 SIMULINK是 MATLAB众多工具箱中的一个 , 是用来对动态系 众多工具箱中的一个, 是 众多工具箱中的一个 统进行建模、仿真和分析的软件包,它支持连续、离散及两者混合 统进行建模、仿真和分析的软件包,它支持连续、 的线性和非线性系统,也支持具有多种采样速率的多速率系统; 的线性和非线性系统,也支持具有多种采样速率的多速率系统;主 要用于控制系统、信号处理、数据分析、金融系统、通信系统、 要用于控制系统、信号处理、数据分析、金融系统、通信系统、土 木工程、图形可视化等领域。在我们的课程中, 木工程、图形可视化等领域。在我们的课程中,主要是用它来进行 动态系统的仿真所以也可称为系统仿真工具箱。 动态系统的仿真所以也可称为系统仿真工具箱。 SIMULINK与用户交互接口是基于 与用户交互接口是基于windows的图形界面,控制系 的图形界面, 与用户交互接口是基于 的图形界面 统的模型是以方块图形式建立的,只要懂流程图, 统的模型是以方块图形式建立的,只要懂流程图,就可以用方框图 进行建模,采用这种结构画模型就像你用笔和纸来画一样容易。 进行建模,采用这种结构画模型就像你用笔和纸来画一样容易。它 与传统的仿真软件包用微分方程和差分方程建模相比, 与传统的仿真软件包用微分方程和差分方程建模相比,具有更直观 方便、灵活的优点。因此SIMULINK有越来越受重视的倾向。此 有越来越受重视的倾向。 、方便、灵活的优点。因此 有越来越受重视的倾向 外由于SIMULINK采用开放式的结构,因此可非常方便地用来开发 采用开放式的结构, 外由于 采用开放式的结构 子程序供MATLAB使用或是转成 或 Fortran语言。 截至当前可提 使用或是转成C或 语言。 子程序供 使用或是转成 语言 供给SIMULINK的工具,有非线性工具集,数字信号处理工具集。 的工具, 供给 的工具 有非线性工具集,数字信号处理工具集。 下面将简要介绍其基本内容、 下面将简要介绍其基本内容、基本概念与在仿真过程中常用的一些 操作过程。 操作过程。

matlab-simulink教程

matlab-simulink教程

Simulink仿真环境基础学习Simulink是面向框图的仿真软件。

7.1演示一个Simulink的简单程序【例7.1】创建一个正弦信号的仿真模型。

步骤如下:(1) 在MATLAB的命令窗口运行simulink命令,或单击工具栏中的图标,就可以打开Simulink模块库浏览器(Simulink Library Browser) 窗口,如图7.1所示。

(2)单击工具栏上的图标或选择菜单“File ”——“New ”——“Model ”,新建一个名为“untitled ”的空白模型窗口。

(3) 在上图的右侧子模块窗口中,单击“Source ”子模块库前的“+”(或双击Source),或者直接在左侧模块和工具箱栏单击Simulink 下的Source 子模块库,便可看到各种输入源模块。

(4) 用鼠标单击所需要的输入信号源模块“Sine Wave ”(正弦信号),将其拖放到的空白模型窗口“untitled ”,则“Sine Wave ”模块就被添加到untitled 窗口;也可以用鼠标选中“Sine Wave ”模块,单击鼠标右键,在快捷菜单中选择“add to 'untitled'”命令,就可以将“Sine Wave ”模块添加到untitled 窗口,如图7.2所示。

图7.1 Simulink 界面(5) 用同样的方法打开接收模块库“Sinks”,选择其中的“Scope”模块(示波器)拖放到“untitled”窗口中。

(6) 在“untitled”窗口中,用鼠标指向“Sine Wave”右侧的输出端,当光标变为十字符时,按住鼠标拖向“Scope”模块的输入端,松开鼠标按键,就完成了两个模块间的信号线连接,一个简单模型已经建成。

如图7.3所示。

(7) 开始仿真,单击“untitled”模型窗口中“开始仿真”图标,或者选择菜单“Simulink”——“Start”,则仿真开始。

双击“Scope”模块出现示波器显示屏,可以看到黄色的正弦波形。

讲义 第2篇 simulink入门 part 1

讲义 第2篇 simulink入门 part 1

2.2 simulink简介
• 1、什么是Simulimk?

Simulink是动态系统模拟仿真(Dynamic System Simulation)。使得MATLAB的功能得到进一 步的扩展。扩展的意义在于: • (1)实现了可视化建模,用户可以通过简单的鼠 标操作就可以建立起直观的系统模型,并进行仿真; • (2) 实现了多工作环境间文件互用和数据交换; • (3) 把理论研究和工程实现有机地结合在一起。
第2篇 Simulink入门
• 主要内容: • Simulink(动态系统仿真)简介 • Simulink使用初步
• Simulink的模块操作
• • • •
Simulink的基本模块 Simulink仿真 封装子模块 MATLAB与Simulink交换数据
2.1 参 考 书
• [1]邵玉斌 编著.MATLAB/Simulink 通信系统 建模与仿真实例分析.清华大学出版社,2008年. • [2]刘敏,魏玲编著.MATLAB通信仿真与应用, 国防工业出版社,2001年. • [3]徐明远、邵玉斌 编著.MATLAB仿真在通信 与电子工程中的应用,西安电子科技大学出版 社,2006年. • [4]姚俊,马松辉 编著.simulink建模与仿真.西安 电子科技大学出版社.
• 4、Simulink的启动与退出: (4种方法) • Simulink的启动
– (1)在MATLAB的命令窗口直接键入simulink。
– (2) 工具栏上的Simulink模块库浏览器命令按钮 – (3) File菜单中选择New菜单项下的Model命令 • • Simulink的退出 – 关闭所有模型窗口和Simulink模块库窗口即可
输入 系统 输出

第1章SIMULINK入门

第1章SIMULINK入门

12.4.2 手动连接模块
• 1.从模块到模块的手动连接 • 当鼠标移动至输出模块的输出端口时,鼠标图标 将变成十字符型,此时按下鼠标左键,拖动鼠标 至目标模块输入端口,当鼠标图标由十字符型变 为双十字符型时,松开鼠标左键即可,如图所示。 • 2.从信号线某一点到模块的手动连接 • 将鼠标移动到信号线上某一点,此时鼠标图标变 为十字符型,其后的连接方式完全与从模块到模 块的连接相同。这种连接方式可以将一个信号传 递到多个模块,
12.4.4 操作模块名称
• 在SIMULINK模型中,每个模块都有自己唯一的模 块名。如果在同一系统中出现模块名的重复, SIMULINK将弹出一个Error对话框。 • 1.更改模块名称 • 2.移动模块名位置 • 3.显示或隐藏模块名
• 4.改变模块名的字体和大小
12.4.5 设置模块参数
12.1.2 SIMULINK启动
• 启动SIMULINK之前,首先要打开MATLAB,打开 MATLAB主界面,在命令窗口(Command Window) 输入命令simulink,回车即可启动SIMULINK,即 打开SIMULINK库浏览器(Simulink Library Browser)窗口,如图所示。
Constant
2{10} double [3x3] [3x3] 2{10}
Scope2
[3x3]
Constant1 Scope
double
3 Gain
double
Sine Wave
12.6 仿真设置
• 接下来将介绍SimulinkParameters对话框中基本 参数的设置方式。SimulinkParameters对话框中 仿真参数主要包括,解法器设置(Solver)、仿 真参数输入输出(Data Import/Export)、仿真 优化(Optimization)、仿真诊断 (Diagnostics)、仿真硬件实现(Hardware Implementation)、参考模型(Model Referencing) 和实时工作间(Real-time workshop)。在模型窗 口中选择菜单栏【Simulation/Configuration Parameter】,就可以打开Configuration Parameter(参数配置)对话框,
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

3 Creating a Simulink Model•“Overview of a Simple Model”on page3-2•“Creating the Simple Model”on page3-3•“Connecting Blocks in the Simple Model”on page3-9•“Simulating the Simple Model”on page3-143Creating a Simulink®ModelOverview of a Simple ModelYou can use Simulink software to model dynamic systems and simulate thebehavior of the models.The basic techniques you use to create a simple modelare the same techniques you will use for more complex models.To create this simple model,you need four blocks:•Sine Wave—Generates an input signal for the model.•Integrator—Processes the input signal.•Mux—Multiplexes the input signal and processed signal into a singlesignal.•Scope—Visualizes the signals in the model.After connecting the blocks,they model a system that integrates a sine wavesignal and displays the result along with the original signal.You can build this simple model yourself,starting with“Creating a NewModel”on page3-3.3-2Creating the Simple ModelCreating the Simple ModelIn this section...“Creating a New Model”on page3-3“Adding Blocks to a Model”on page3-4“Moving Blocks in the Model”on page3-8Creating a New ModelBefore creating a model,you need to start Simulink,and then open an emptymodel window.1If Simulink is not running,in the MATLAB Command Window,entersimulinkThe Simulink Library Browser opens.2From the Simulink Library Browser menu,select File>New>Model.A Simulink editor window opens with an empty model in the right pane.3-33Creating a Simulink®Model3Select File>Save as.The Save As dialog box opens.4In the File name box,enter a name for your model,and then click Save.For example,enter simple_model.The software saves your model with the filename simple_model.mdl.Adding Blocks to a ModelTo create a model,you begin by copying blocks from the Simulink LibraryBrowser to the Simulink editor window.For a description of the blocks in thisexample,see“Overview of a Simple Model”on page3-2.1In the Simulink Library Browser,select the Sources library.The Simulink Library Browser displays blocks from the Sources library inthe right pane.3-4Creating the Simple Model3-53Creating a Simulink®Model2Select the Sine Wave block,and then drag it to the editor window.A copy of the Sine Wave block appears in your model.3Add the following blocks to your model in the same way you added theSign Wave block.Library BlockSinks ScopeContinuous IntegratorSignal Routing MuxYour model now has the blocks you need for the simple model.3-6Creating the Simple Model3-73Creating a Simulink®ModelMoving Blocks in the ModelBefore you connect the blocks in your model,you should arrange themlogically to make the signal connections as straightforward as possible.Tomove a block in a model,you can either•Click and drag the block•Select the block,and then press the arrow keys on the keyboard1Move the Scope block after the Mux block output.2Move the Sine Wave and Integrator blocks before the Mux block Inputs.Your model should look similar to the following figure.Your next task is to connect the blocks together with signal lines.See“Connecting Blocks in the Simple Model”on page3-9.3-8Connecting Blocks in the Simple ModelConnecting Blocks in the Simple ModelIn this section...“Block Connections in a Model”on page3-9“Drawing Lines Between Blocks”on page3-9“Drawing a Branch Line”on page3-12Block Connections in a ModelAfter you add blocks to your model,you need to connect them.The connectinglines represent the signals within a model.Most blocks have angle brackets on one or both sides.These angle bracketsrepresent input and output ports:•The>symbol pointing into a block is an input port.•The>symbol pointing out of a block is an output port.Input port Output portDrawing Lines Between BlocksConnect the blocks by drawing lines between output ports and input ports.For how to add blocks to the model in this example,see“Adding Blocks toa Model”on page3-4.1Position your mouse pointer over the output port on the right side of theSine Wave block.3-93Creating a Simulink®Model2Drag a line from the output port to the top input port of the Mux block.While holding the mouse button down,the connecting line is shown as alight colored arrow.3Release the mouse button over the output port.Simulink connects the blocks with an arrow indicating the direction ofsignal flow.4Drag a line from the output port of the Integrator block to the bottom inputport on the Mux block.The Integrator block connects to the Mux block with a signal line.3-10Connecting Blocks in the Simple Model5Select the Mux block,hold down the Shift key,and then select the Scopeblock.A line is drawn between the blocks to connect them.Note The Shift+click shortcut is useful when you are connecting widelyseparated blocks,or when working with complex models.Your model should now look similar to the following figure.3-113Creating a Simulink®ModelDrawing a Branch LineThe simple model is almost complete,but one connection is missing.To finishthe model,you need to connect the Sine Wave block to the Integrator block.This final connection is somewhat different from the other three connections,which all connect output ports to input ports.Because the output port of theSine Wave block already has a connection,you must connect this existing lineto the input port of the Integrator block.The new line,called a branch line,carries the same signal that passes from the Sine Wave block to the Mux block.1Position the mouse pointer on the line between the Sine Wave and theMux block.2Hold down the Ctrl key,and then drag a line to the input port of theIntegrator block input port.This step adds a connection to the existing line and draws a line betweenthe connection and the input port of the Integrator block.3-12Connecting Blocks in the Simple Model3From the File menu,click Save.Your model is now complete.It should look similar to the following figure.After your model is complete,you can simulate the model.See“Simulatingthe Simple Model”on page3-14.3-133Creating a Simulink®ModelSimulating the Simple ModelIn this section...“Setting Simulation Options”on page3-14“Running a Simulation and Observing Results”on page3-15Setting Simulation OptionsBefore you simulate a model,you have to set simulation options.You specifyoptions,such as the stop time and solver,using the Model ConfigurationParameters dialog box.For how to build the model in this example,see“Creating the Simple Model”on page3-3.1In the Simulink editor window,select Simulation>ModelConfiguration Parameters.The Configuration Parameters dialog boxopens to the Solver pane.2In the Stop time field,enter20,and in the Max step size field,enter0.2.3Click OK.The software updates the parameter values with your changes and closesthe Configuration Parameters dialog box.For more information about Simulink configuration parameters,see“Configuration Parameters Dialog Box”.3-14Simulating the Simple Model Running a Simulation and Observing ResultsAfter entering your configuration parameter changes,you are ready tosimulate the simple model and visualize the simulation results.1In the Simulink editor window and from the menu,selectSimulation>Start.The simulation runs,and then stops when it reaches the stop time specifiedin the Model Configuration Parameters dialog box.Tip Alternatively,you can control a simulation by clicking the Startsimulation button and Stop simulation button on the editorwindow toolbar.2Double-click the Scope block.The Scope window opens and displays the simulation results.The plotshows a sine wave signal with the resulting cosine wave signal from theIntegrator block.3-153Creating a Simulink®Model3From the toolbar,click the Parameters button,and then the Graphicstab.The Scope Parameters dialog opens with figure editing commands.4Make changes to the appearance of the figure.For example,select whitefor the Figure and Axes background color,and change the signal line colorsto blue and green.Click the Apply button to see your changes.3-16Simulating the Simple Model5Select File>Close.The Simulink editor window closes with changes to your model and the configuration parameters.3-173Creating a Simulink®Model 3-184 Modeling a Dynamic Control System•“Understanding a Demo Model”on page4-2•“Simulating the Demo Model”on page4-11•“Moving Data Between MATLAB and the Demo Model”on page4-194Modeling a Dynamic Control SystemUnderstanding a Demo ModelIn this section...“Overview of the Demo Model”on page4-2“Opening the Demo Model”on page4-3“Anatomy of the Demo Model”on page4-4“Subsystems in the Demo Model”on page4-5“Subsystems and Masks”on page4-9“Creating a Subsystem”on page4-9“Creating a Subsystem Mask”on page4-10Overview of the Demo ModelThis demo model illustrates how you can use Simulink software to modela dynamic control system.The model defines a heating system and thethermodynamics of a house.It included the outdoor environment,the thermalcharacteristics of a house,and the house heating system.Use this model to explore common Simulink modeling tasks,such as•Grouping multiple blocks into a single subsystem block to simplify a blockdiagram.See“Subsystems in the Demo Model”on page4-5•Customizing the appearance of blocks using the masking feature.See“Creating a Subsystem Mask”on page4-10•Simulating a model and observing the results using a Scope block.See“Running the Simulation”on page4-11•Changing the input parameters of the model to investigate how the systemresponds.See“Changing the Thermostat Setting”on page4-12.•Importing data from the MATLAB workspace into a model beforesimulation.See“Importing Data from the MATLAB Workspace”on page4-19.•Exporting simulation data from the model back to the MATLAB workspace.See“Exporting Simulation Data to the MATLAB Workspace”on page4-23. 4-2Understanding a Demo Model Opening the Demo ModelThe demo model for this example is called sldemo_househeat.It models the heating system and thermodynamics of a house.1Start MATLAB,and then In the MATLAB Command Window,enter sldemo_househeatThe Simulink editor opens with the demo model.4Modeling a Dynamic Control SystemAnatomy of the Demo ModelThe demo model defines the dynamics of the outdoor environment,thethermal characteristics of the house,and the house heating system.It allowsyou to simulate how the thermostat setting and outdoor environment affectthe indoor temperature and cumulative heating costs.The demo model includes many of the same blocks you used to create thesimple model in Chapter3,“Creating a Simulink Model”.These include:•A Scope block(labeled PlotResults)on the far right,displays thesimulation results.•A Mux block at the bottom right,combines the indoor and outdoortemperature signals for the Scope.•A Sine Wave block(labeled Daily Temp Variation)at the bottom left,provides one of three data sources for the model.In the demo model,the thermostat is set to70degrees Fahrenheit.Thesystem models fluctuations in outdoor temperature by applying a sine wavewith amplitude of15degrees to a base temperature of50degrees.The three data inputs(sources)are provided by two Constant blocks(labeledSet Point and Avg Outdoor Temp),and the Sine Wave block(labeled DailyTemp Variation).The Scope block labeled PlotResults is the one output(sink).Understanding a Demo Model Subsystems in the Demo ModelThe sldemo_househeat demo model uses subsystems to simplify theappearance of the block diagram,create reusable components,and customizethe appearance of blocks.A subsystem is a hierarchical grouping of blocks encapsulated by a single Subsystem block.The demo model uses the following subsystems:Thermostat,Heater,House, Fahrenheit to Celsius,and Celsius to Fahrenheit1In the MATLAB Command Window,entersldemo_househeatThe demo model opens in the Simulink editor window.4Modeling a Dynamic Control System2Subsystems can be complex and contain many blocks that might otherwiseclutter a diagram.For example,double-click the House subsystem block toopen it.Contents of House subsystemThe subsystem receives heat flow and external temperature as inputs,which it uses to compute the current room temperature.You could leaveeach of these blocks in the main model window,but combining them as asubsystem helps simplify the block diagram.Understanding a Demo Model3A subsystems can also be simple and contain only a few blocks.Forexample,double-click the Thermostat subsystem block to open it.Contents of Thermostat subsystemThis subsystem models the operation of a thermostat,determining whenthe heating system is on or off.It contains only one Relay block,butlogically represents the thermostat in the block diagram..4Modeling a Dynamic Control SystemUnderstanding a Demo Model Subsystems and MasksSubsystems allows you to group related blocks into one block.They are also reusable,enabling you to implement an algorithm once and use it multiple times.For example,the model contains two instances of identical subsystems named Fahrenheit to Celsius.These subsystems convert the inside and outside temperatures from degrees Fahrenheit to degrees CelsiusYou can customize the appearance of a subsystem by using a process knownas masking.Masking a subsystem allows you to specify a unique icon anddialog box for the Subsystem block.For example,the House and Thermostat subsystems display custom icons that depict physical objects,while the conversion subsystems display custom dialog boxes when you double-clickthem.1Double-click the Fahrenheit to Celsius block.The custom dialog box for the F2C block opens.2To view the underlying blocks in the conversion subsystem,right-click thesubsystem block,point to Mask,and then select Look Under Mask.The editor displays the blocks behind the mask.Creating a SubsystemTo create a subsystem:1In the demo model window,select the set point and Fahrenheit to Celsiusblocks.4Modeling a Dynamic Control System2From the menu,select Diagram>Subsystem&Modeling Reference>Create Subsystem from Selection.The blocks are combined into one subsystem block.For more information about working with subsystems,see“CreatingSubsystems”in the Simulink User’s Guide.Creating a Subsystem MaskTo mask a subsystem:1In the demo model window,right-click the new subsystem block,and thenselect Mask>Add/Edit Mask.The Mask Editor dialog box opens.2From the Command list,select disp(show text in center of block).The dialog box displays the syntax for this command below the list.3In the Icon Drawing commands field,enter disp('SelectTemperature').4Click OK.The software masks the subsystem block with the text you entered.For more information about masking subsystems,see“Working with BlockMasks”in the Simulink User’s Guide.Simulating the Demo ModelSimulating the Demo ModelIn this section...“Running the Simulation”on page4-11“Changing the Thermostat Setting”on page4-12“Changing the Average outdoor Temperature”on page4-14“Changing the Daily Temperature Variation”on page4-16Running the SimulationSimulating the model allows you to observe how the thermostat setting andoutdoor environment affect the indoor temperature and the cumulativeheating cost.1In the demo model window,double-click the Scope block namedPlotResults.The software opens a Scope window that contains two axes with the labelsHeatCost and Temperatures.2From the menu,select Simulation>Start.The software simulates the model.As the simulation runs,the cumulativeheating cost appears on the HeatCost graph at the top of the Scope window.The indoor and outdoor temperatures appear on the Temperatures graphas yellow(top)and magenta(bottom)signals,respectively.4Modeling a Dynamic Control SystemChanging the Thermostat SettingOne of the most powerful benefits of modeling a system with Simulink isthe ability to interactively define the system inputs and observe changes inthe behavior of your model.This allows you to quickly evaluate your modeland validate the simulation results.Change the thermostat setting to68degrees Fahrenheit and observe howthe model responds.1In the Simulink editor window,double-click the Set Point block.TheSource Block Parameters dialog box opens.2In the Constant value field,enter68.Simulating the Demo Model3Click OK.The software applies your changes.4To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that a lower thermostat setting reduces the cumulative heating cost.4Modeling a Dynamic Control SystemChanging the Average outdoor TemperatureChange the average outdoor temperature to45degrees Fahrenheit andobserve how the model responds.1In the Simulink editor window,double-click the Avg Outdoor Temp block.The Source Block Parameters dialog box opens.2In the Constant value field,enter45.Simulating the Demo Model3Click OK.The software applies your changes and closes the dialog box.4To rerun the simulation,select Simulation>Start.The software simulates the model dynamics.In the Scope window,noticethat a colder outdoor temperature increases the cumulative heating cost.4Modeling a Dynamic Control SystemChanging the Daily Temperature VariationDecrease the temperature variation to see how the model responds.1In the Simulink editor window,double-click the Daily Temp Variationblock.The Source Block Parameters dialog box opens.2In the Amplitude field,enter5.3Click OK.The software applies your changes and closes the dialog box.4To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that amore stable outdoor temperature alters the frequency with which theheater operates.Simulating the Demo Model4Modeling a Dynamic Control SystemMoving Data Between MATLAB and the Demo ModelMoving Data Between MATLAB and the Demo ModelIn this section...“Importing Data from the MATLAB Workspace”on page4-19“Exporting Simulation Data to the MATLAB Workspace”on page4-23Importing Data from the MATLAB WorkspaceSimulink also allows you to import data from the MATLAB workspace to themodel input ports.This allows you to import actual physical data into yourmodel.For information about other data import capabilities,see“Importingand Exporting Simulation Data”in the Simulink User’s Guide.Note In this example,you will create a vector of temperature data inMATLAB,and use that data as an input to the Simulink model.To import data from the MATLAB workspace:1In the MATLAB Command Window,create time and temperature data byentering the following commands:x=(0:0.01:4*pi)';y=32+(5*sin(x));z=linspace(0,48,1257)';2In the Simulink editor window,select the Avg Outdoor Temp block,andthen press the Delete key to delete it.3Delete the following items from the model in the same way:•Daily Temp Variation block•Two input signal lines to the Sum block•Sum block4Modeling a Dynamic Control SystemThe model should now look similar to the following figure.Notice that theoutput signal from the Sum block changes to a red,dotted line,indicatingthat it is not connected to a block.4In the demo model window,select View>Library Browser.The Simulink Library Browser window opens.5In the Simulink Library Browser,select the Sources library.6From the Sources library right pane,select the In1block,and then drag itto the model window.Moving Data Between MATLAB and the Demo ModelAn In1block appears in the model window.7Connect the dotted line(originally connected to the Sum block)to the In1 block.8In the Simulink editor window,select Simulation>Configuration Parameters.The Configuration Parameters dialog box opens.9In the menu on the left side of the dialog,select Data Import/Export.The Data Import/Export pane opens.4Modeling a Dynamic Control System10Select the Input check box.11In the Input field,enter[z,y].12Click OK.The software applies your changes and closes the dialog box.13To rerun the simulation,select Simulation>Start.The software simulates the model.In the Scope window,notice that themodel ran using the imported data,showing colder temperatures andhigher heat use.Exporting Simulation Data to the MATLAB Workspace Once you have completed a model,you may want to export your simulation results to MATLAB workspace for further data analysis or visualization.For information about additional data export capabilities,see“Exporting Simulation Data”.To export the HeatCost data from the model to the MATLAB workspace:1In the Simulink Library Browser window,select the Sinks library.2From the Sinks library,select the Out1block,and then drag it to the top right of the demo model window.An Out1block appears in the model window.3Draw a branch line from the HeatCost signal line to the Out1block.For more information,see“Drawing a Branch Line”on page3-12.4Select Simulation>Configuration Parameters.The Configuration Parameters dialog box opens.5From the menu on the left side of the dialog box,select DataImport/Export.The Data Import/Export pane opens.6Select the Time and Output check boxes.7Click OK.The software applies your changes and closes the dialog box.8To rerun the simulation,select Simulation>Start.The software simulates the model and saves the time and HeatCost data to the MATLAB workspace.Notice that the tout and yout variables nowappear in the MATLAB workspace.。

相关文档
最新文档