主要内容

What Are System Objects?

A System object™ is a specialized MATLAB®目的。许多工具箱都包含系统对象。系统对象专门设计用于实现和模拟动态系统,其输入随时间变化。许多信号处理,通信和控制系统都是动态的。在动态系统中,输出信号的值都取决于输入信号的瞬时值以及系统的过去行为。系统对象使用内部状态存储过去的行为,该行为用于下一个计算步骤中。结果,系统对象是针对迭代计算进行了优化的,该计算处理段中的大量数据流,例如视频和音频处理系统。这种处理流数据的能力提供了不必在内存中保存大量数据的优势。流媒体数据的使用还允许您使用有效使用循环的简化程序。

例如,您可以在系统中使用系统对象,该系统从文件中读取数据,过滤数据,然后将过滤的输出写入另一个文件。通常,在每个循环迭代中将指定量的数据传递给过滤器。文件读取器对象使用状态来跟踪文件中开始读取下一个数据的位置。同样,文件写入对象跟踪上次将数据写入输出文件的位置,以免数据覆盖。过滤对象保持自己的内部状态,以确保正确执行过滤。该图代表系统的单个循环。

这些优势使系统对象非常适合处理流数据。

许多系统对象支持:金宝app

  • Fixed-point arithmetic (requires a Fixed-Point Designer™ license)

  • C code generation (requires aMATLAB Coder™或者金宝app®编码器license)

  • HDL code generation (requires an HDL Coder™ license)

  • 可执行文件或共享库生成(需要一个MATLAB Compiler™license)

Note

Check the product documentation to confirm fixed-point, code generation, andMATLAB Compiler金宝app支持您要使用的特定系统对象。

系统对象使用至少两个命令来处理数据:

  • Creation of the object (such as,FFT256 = DSP.FFT)

  • Running data through the object (such as,FFT256(x))

This separation of creation from execution lets you create multiple, persistent, reusable objects, each with different settings. Using this approach avoids repeated input validation and verification, allows for easy use within a programming loop, and improves overall performance. In contrast, MATLAB functions must validate parameters every time you call the function.

In addition to the System objects provided with System Toolboxes, you can create your own System objects. See创建系统对象.

Running a System Object

要运行系统对象并执行由其算法定义的操作,请将对象称为函数。例如,创建一个使用fft对象dsp.fft系统对象指定1024的长度,并将其命名dft使用:

dft = dsp.fft('FFTLengthSource','Property','FFTLength',1024);
To run this object with the inputx使用:
dft(x);
如果您在没有任何输入参数的情况下运行系统对象,则必须包括空括号。例如,asysobj().

When you run a System object, it also performs other important tasks related to data processing, such as initialization and handling object states.

Note

An alternative way to run a System object is to use thestepfunction. For example, for an object created usingdft = dsp.FFT, you can run it using步骤(DFT,X).

系统对象功能

创建系统对象后,您使用各种对象函数来处理数据或从对象或周围获取信息。用于使用函数的语法是<对象函数名称>(<系统对象名称>), plus possible extra input arguments. For example, fortxfourier = dsp.FFT, wheretxfourieris a name you assign, you call theresetfunction usingreset(txfourier).

Common Object Functions

全部System objects support the following object functions. In cases where a function is not applicable to a particular object, calling that function has no effect on the object.

功能 Description
Run the object function, or
step

Runs the object to process data using the algorithm defined by that object.

Example: For the objectdft = dsp.FFT;,通过:

  • y = dft(x)

  • y = step(dft,x)

As part of this processing, the object initializes resources, returns outputs, and updates the object states as necessary. During execution, you can change only tunable properties. Both ways of running a System object return regular MATLAB variables.

release

Release resources and allow changes to System object property values and additional characteristics that are limited while the System object is in use.

reset 将系统对象重置为该对象的初始值。
nargin Returns the number of inputs accepted by the System object algorithm definition. If the algorithm definition includesvarargin,nargin输出为负。
Nargout Returns the number of outputs accepted by the System object algorithm definition. If the algorithm definition includesvarargout,Nargout输出为负。
clone Creates another object of the same type with the same property values
isLocked Returns a logical value indicating whether the object has been called and you have not yet calledrelease在对象上。
isDone Applies only to source objects that inherit frommatlab.system.mixin.FiniteSource. Returns a logical value indicating whether the end of the data file has been reached. If a particular object does not have end-of-data capability, this function value always returnsfalse.

See Also

相关话题