主要内容

信号基础

Asignal是一个随时间变化的数量,在所有时间点具有值。您可以指定广泛的信号属性,包括:

  • Signal name

  • 数据类型(例如,8位,16位或32位整数)

  • Numeric type (real or complex)

  • 维度(一维,二维或多维阵列)

In Simulink®, signals are the outputs of dynamic systems represented by blocks in a Simulink diagram and by the diagram itself. The lines in ablock diagramrepresent mathematical relationships among the signals defined by the block diagram. For example, a line connecting the output of block A to the input of block B indicates that the signal output of B depends on the signal output of A.

Simulink block diagrams represent signals with lines that have an arrowhead. The source of the signal corresponds to the block that writes to the signal during evaluation of its block methods (equations). The destinations of the signal are blocks that read the signal during the evaluation of the block methods (equations). The destination of signals in a model do not necessarily represent the order of simulation of blocks in a model. The simulation order is determined by Simulink automatically.

Note

Simulink signals are mathematical, not physical, entities. The lines in a block diagram represent mathematical, not physical, relationships among blocks. Simulink signals do not travel along the lines that connect blocks in the same way that electrical signals travel along a wire. Block diagrams do not represent physical connections between blocks.

You can create a signal by adding a source block to your model. For example, you can create a signal that varies sinusoidally with time by adding an instance of theSine, Cosineblock from the Simulink Sources library into your model. To see a list of the blocks that create signals in a model, seeSources。或者,您可以使用观众和发电机经理在模型中创建信号而无需使用块。

Signal Line Styles

A Simulink model can include many different types of signals. As you construct a block diagram, all signal types appear as a thin, solid line. After you update the diagram or start simulation, the signals appear with the specified line styles. These signal types enable you to differentiate between different signal types. From all signal types, you can only customize the nonscalar signal type. To learn more, see信号类型s

信号类型 Line Style
Scalar and nonscalar
Nonscalar (with the宽的非标准线option enabled—seeWide Nonscalar Lines)

Control signal

虚拟巴士
Nonvirtual bus
Array of buses
Variable-size

Signal Properties

您可能需要在模型中指定信号属性,以在信号中给出名称或标签,准备记录数据或在模型中自定义信号。使用属性检查器,模型数据编辑器或“信号属性”对话框指定属性:

  • 信号名称和标签

  • Signal logging

  • 金宝appSimulink Coder™用于生成代码

  • Documentation of the signal

To access the signal properties in the Property Inspector, first display the Property Inspector. On theModelingtab, underDesign, clickProperty Inspector。When you select a signal, the properties appear in the Property Inspector.

To open the Model Data Editor, on theModelingtab, clickModel Data Editor。然后,检查Signals选项卡并选择一个信号。

使用信号属性对话框,right-click a signal and selectProperties

To specify signal properties programmatically, use a function such asget_param创建一个将手柄保存到创建信号线的块输出端口的变量。然后,使用set_paramto set the programmatic parameters of the port. For example:

p = get_param(gcb,“ Porthandles”) l = get_param(p.Outport,'Line')set_param(l,'Name','s9')

Signal Names and Labels

You can name a signal interactively or programmatically in a model. The syntactic requirements for a signal name depend on how you use the name. The most common cases are:

  • Do not use a less than character (<)启动信号名称。

  • 信号名称可以解析为金宝appsimulink.signalobject. (See金宝appsimulink.signal。) The signal name must then be a legal MATLAB®identifier. This identifier starts with an alphabetic character, followed by alphanumeric or underscore characters up to the length given by the functionnamelengthmax

  • 该信号具有名称,因此可以在数据日志中以名称识别和引用该信号。(看Export Signal Data Using Signal Logging。) Such a signal name can contain space and newline characters. These characters can improve readability but sometimes require special handling techniques, as described inHandling Spaces and Newlines in Logged Names

  • The signal name exists only to clarify the diagram and has no computational significance. Such a signal name can contain anything and does not need special handling.

  • The signal is an element of a bus object. Use a valid C language identifier for the signal name.

  • Inputs to a公共汽车创建者block must have unique names. If there are duplicate names, the公共汽车创建者block appends(signal#)to all input signal names, where#is the input port index.

Making every signal name a legal MATLAB identifier handles a wide range of model configurations. Unexpected requirements can require changing signal names to follow a more restrictive syntax. You can use the functionISVARNAMEto determine whether a signal name is a legal MATLAB identifier.

使用以下一个选项之一交互式命名信号:

The signal name appears below a signal, displayed as asignal label

To name a signal programmatically, use theget_paramset_paramfunctions on the signal. The table below summarizes how to work with signal names and labels in the Simulink Editor.

Task Action
命名信号线 Double-click the signal and type its name.
Name a branch of a named signal line Double-click the branch.
Name every branch of a signal Right-click the signal, selectProperties,并使用对话框。
Delete signal label and name Delete characters in the label or delete the name in Signal Properties dialog box.
Delete signal label only 右键单击标签并选择Delete Label
Open signal label text box for editing

Double-click the signal line.

单击标签。

Select the signal line (not the label) and useF2

On aMac, select the signal line (not the label) and usecontrol+return

Move signal label Drag the label to a new location on the same signal line.
Copy signal label Ctrl+drag the signal label.
Change the label font 选择信号线(不是标签),然后在格式tab, click the字体属性button arrow, then clickFonts for Model

Signal Display Options

Displaying signal attributes in the model diagram can make the model easier to read. For example, in the Simulink Editor, on the调试tab, use theInformation Overlaysmenu to include in the model layout information about signal attributes, such as:

  • Port data types

  • Design ranges

  • Signal dimensions

  • Signal resolution

For details, seeDisplay Signal Attributes

You can also highlight a signal and its source or destination blocks. For details, see突出显示信号来源和目的地

Store Design Attributes of Signals and States

You can use block parameters and signal properties to specify signal design attributes such as data type, minimum and maximum values, physical unit, and numeric complexity. To configure states, you can use block parameters. When you use these block parameters and signal properties, you store the specifications in the model file.

另外,您可以使用A的属性来指定这些属性金宝appsimulink.signal或者Simulink.ValueTypeobject that you store in a workspace or data dictionary.

Choose which strategy to use based on your modeling goals.

Modeling Goal 战略

Improve model portability, readability, and ease of maintenance

Store signal attribute specifications in the model file. You do not need to save and manage external objects. Consider setting the model configuration parameterSignal resolutiontoNone, which disables the use of金宝appsimulink.signalobjects by the model.

单独的信号属性规格与模型,以便您可以独立管理每个信号

Use金宝appsimulink.signalobjects.

Separate signal attribute specifications from the model so that you can reuse an application-specific set of attributes

UseSimulink.Valuetypeobjects.

To configure design attributes and code generation settings for signals by using a list that you can sort, group, and filter, consider using theModel Data Editor。For objects, you can also use theModel Explorer

To determine where to permanently store a金宝appsimulink.signal或者Simulink.ValueTypeobject, see确定在何处存储simulink模型的变量和对象金宝app

Test Signals

You can perform the following kinds of tests on signals:

  • Minimum and Maximum Values — For many Simulink blocks, you can specify a range of valid values for the output signals. Simulink provides a diagnostic for detecting when blocks generate signals that exceed their specified ranges during simulation. For details, seeSpecify Signal Ranges

  • 连接验证——许多仿真软件模块金宝applimitations on the types of signals that they accept. Before simulating a model, Simulink checks all blocks to ensure that the blocks can accommodate the types of signals output by the ports to which the blocks connect and reports errors about incompatibilities. To detect signal compatibility errors before running a simulation, update the diagram.

TheSignal Editor块显示可互换的方案组。使用Signal Editorto display, create, edit, and switch interchangeable scenarios.

方案可以帮助测试模型。

相关话题