主要内容

Discrete FIR Filter

R2026b

构建 FIR 滤波器模型

  • Discrete FIR Filter block

库:
Simulink / Discrete
DSP System Toolbox / Filtering / Filter Implementations
HDL Coder / Discrete
HDL Coder / HDL Floating Point Operations

描述

Discrete FIR Filter 模块使用指定的数字 FIR 滤波器单独对输入信号的每个通道进行滤波。该模块可以实现系数固定的静态滤波器以及系数随时间变化的时变滤波器。您可以在仿真期间调整静态滤波器的系数。

此模块随时间的推移单独对输入信号的每个通道进行滤波。输入处理参数用于指定该模块将输入的每个元素作为独立通道处理(基于采样的处理)还是将输入的每个列作为独立通道处理(基于帧的处理)。要执行基于帧的处理,您必须拥有 DSP System Toolbox™ 许可证。

输出维度等于输入维度,但为系数参数指定滤波器抽头矩阵时除外。当您执行此操作时,输出维度取决于您指定的不同滤波器抽头集的数量。

此模块支持自定义状态属性以更高效地自定义和生成代码。有关示例,请参阅Custom State Attributes in Discrete FIR Filter Block。在某些条件下,模块还支持 SIMD 代码生成。有关详细信息,请参阅代码生成。

此模块的输出在数值上与 DSP System Toolbox Digital Filter Design (DSP System Toolbox) 模块的输出相匹配。

此模块支持 Simulink® 状态记录功能。有关详细信息,请参阅 State。

滤波器结构支持

您可以更改通过 Discrete FIR Filter 模块实现的滤波器结构,方法是从滤波器结构参数中选择以下选项之一:

  • 直接型

  • 直接型对称

  • 直接型反对称

  • 直接型转置

  • 格型 MA

您必须拥有可用的 DSP System Toolbox 许可证才能运行具有上述任意滤波器结构(直接型除外)的模型。

有关滤波器结构的详细信息,请参阅算法。

指定初始状态

Discrete FIR Filter 模块默认将内部滤波器状态初始化为零,这等效于假定过去的输入和输出为零。您可以选择使用初始状态参数为滤波器延迟指定非零初始条件。

要确定您必须指定的初始状态数量以及如何指定这些状态,请参阅有关有效初始状态的表。初始状态参数可采用下表所述的形式之一。

有效初始状态

初始条件描述

标量

模块将滤波器中的所有延迟元素初始化为标量值。

向量或矩阵
(用于将不同的延迟元素应用于每个通道)

每个向量或矩阵元素均为相应通道中的相应延迟元素指定唯一的初始条件:

  • 向量长度等于输入通道数与滤波器中延迟元素数 #_of_filter_coeffs-1(对于格型 MA,则为 #_of_reflection_coeffs)的乘积。

  • 矩阵的行数必须与滤波器中的延迟元素数 #_of_filter_coeffs-1(对于格型 MA,则为 #_of_reflection_coeffs)相同,并且每一列还须对应输入信号的一个通道。

示例

端口

输入

全部展开

要滤波的输入信号,指定为标量、向量或矩阵。

Discrete FIR Filter 模块接受 Simulink 支持的任何数值数据类型的实信号和复信号。

依赖关系

将系数来源设置为对话框参数时,输入信号的端口不带标签。将系数来源设置为输入端口时,输入信号的端口的标签为 In。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
复数支持: 是

将滤波器系数指定为标量或向量。当指定滤波器抽头的行向量时,模块会对输入应用单个滤波器。要对输入应用多个滤波器,请通过系数参数以矩阵形式指定系数。

依赖关系

要启用此端口,请将系数来源设置为输入端口。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

外部重置信号,指定为标量。当指定的触发事件发生时,模块将状态重置为其初始条件。

提示

此端口的图标根据外部重置参数的值更改。

依赖关系

要启用此端口,请将外部重置设置为上升沿、下降沿、任一沿、电平或电平保持。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

启用信号,指定为标量。此端口可以控制模块的执行。当此端口的输入非零时,模块被启用;当输入为 0 时,模块被禁用。输入的值在执行模块的同一时间步进行检查。

依赖关系

要启用此端口,请选中显示使能端口复选框。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

输出

全部展开

滤波后的输出信号,以标量、向量或矩阵形式返回。Discrete FIR Filter 模块输出 Simulink 支持的任何数值数据类型的实信号和复信号。

当模块的输入为定点时,模块输出的数据类型取决于您在输出参数中指定的值。当输入为浮点时,输出数据类型与输入数据类型匹配,因为浮点继承优先于定点设置。

当您将采样时间设置为 -1 时,输出信号的采样时间与输入信号 In 的采样时间相同。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

参数

全部展开

常设

选择以指定是使用可调参数对话框参数还是通过输入端口指定滤波器系数,这对于时变系数非常有用。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: CoefSource
值: 'Dialog parameters' (默认) | "Input port"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",CoefSource="Input port")

选择您要模块实现的滤波器结构。有关详细信息,请参阅算法。

依赖关系

如果模型包含 Discrete FIR Filter 模块且该模块实现直接型以外的滤波器结构,则您必须有可用的 DSP System Toolbox 许可证才能运行该模型。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: FilterStructure
值: 'Direct form' (默认) | "Direct form symmetric" | "Direct form antisymmetric" | "Direct form transposed" | "Lattice MA"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",FilterStructure="Direct form transposed")

将滤波器系数指定为标量、向量或矩阵。

当指定滤波器抽头的行向量时,模块会对输入应用单个滤波器。要为同一输入应用多个滤波器,请指定一介系数矩阵,其中每一行代表一组不同的滤波器抽头。要实现多个滤波器,必须满足以下条件:

  • 将滤波器结构设置为直接型。

  • 输入必须为标量。

  • 将输入处理设置为元素作为通道(基于采样)。

依赖关系

要启用此参数,请将系数来源设置为对话框参数。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: Coefficients
值: '[0.5 0.5]' (默认) | vector
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",Coefficients="[0.25 0.5 0.25]")

指定模块是执行基于采样还是基于帧的处理。您可以选择以下选项之一:

  • 元素作为通道(基于采样) - 将输入的每个元素作为独立通道处理(基于采样的处理)。

  • 列作为通道(基于帧) - 将输入的每列作为独立通道处理(基于帧的处理)。

    注意

    基于帧的处理需要具有 DSP System Toolbox 许可证。

    有关详细信息,请参阅Sample- and Frame-Based Concepts (DSP System Toolbox)。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: InputProcessing
值: 'Elements as channels (sample based)' (默认) | "Columns as channels (frame based)"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",InputProcessing="Columns as channels (frame based)")

指定滤波器状态的初始条件。要了解如何指定初始状态,请参阅指定初始状态。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: InitialStates
值: '0' (默认) | scalar | vector | matrix
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",InitialStates="0")

此选项使用使能端口来控制此模块的执行。当此端口的输入非零时,模块被视为启用;当输入为 0 时,模块被视为禁用。输入的值在执行模块的同一时间步进行检查。

编程用法

模块参数:ShowEnablePort
类型:字符向量
值:'off' | 'on'
默认值:'off'

指定用于将状态重置为初始条件的触发事件。

重置模式行为
无不重置。
上升沿基于上升沿重置。
下降沿基于下降沿重置。
任一沿基于上升或下降沿重置。
电平

在下列任一情况下重置:

  • 当重置信号在当前时间步为非零值时

  • 当重置信号值从上一时间步的非零更改为当前时间步的零时

电平保持当重置信号在当前时间步为非零值时重置

编程用法

模块参数:ExternalReset
类型:字符向量
值:'None' | 'Rising' | 'Falling' | 'Either' | 'Level' | 'Level hold'
默认值:'None'

指定采样时间间隔。要继承采样时间,请将此参数设置为 -1。有关详细信息,请参阅指定采样时间。

依赖关系

仅当您将此参数设置为 -1 以外的值时才可见。要了解详细信息,请参阅不推荐设置采样时间的模块。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: SampleTime
值: "-1" (默认) | scalar or vector in quotes

点击此按钮以打开滤波器可视化工具 (fvtool (DSP System Toolbox)),并显示在模块对话框中定义的滤波器的滤波器响应。

依赖关系

要启用此参数,请将系数来源参数设置为对话框参数。

仅当您有有效的 DSP System Toolbox 许可证时,此参数才会出现。

数据类型

指定直接型对称或直接型反对称滤波器的抽头加和数据类型。当滤波器在乘以系数之前对输入求和时,使用此数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 从内部规则继承

  • 内置整数,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

数据类型助手可帮助您设置数据属性。要使用数据类型助手,请点击 the Show data type assistant button。有关详细信息,请参阅使用数据类型助手指定数据类型。

依赖关系

仅当滤波器结构设置为直接型对称或直接型反对称时,此参数才可见。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: TapSumDataTypeStr
值: 'Inherit: Inherit via internal rule' (默认) | "Inherit: Same as input" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",TapSumDataTypeStr="Inherit: Same as input")

指定系数数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 与输入的字长相同

  • 内置整数,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

数据类型助手可帮助您设置数据属性。要使用数据类型助手,请点击 the Show data type assistant button。有关详细信息,请参阅使用数据类型助手指定数据类型。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: CoefDataTypeStr
值: 'Inherit: Same wordlength as input' (默认) | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16)" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",CoefDataTypeStr="int16")

指定滤波器系数应具有的最小值。默认值为 [](未指定)。Simulink 软件使用此值执行:

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: CoefMin
值: '[]' (默认) | scalar
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",CoefMin="-1")

指定滤波器系数应具有的最大值。默认值为 [](未指定)。Simulink 软件使用此值执行:

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: CoefMax
值: '[]' (默认) | scalar
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",CoefMax="1")

指定乘积输出的数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 从内部规则继承

  • 内置数据类型,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

数据类型助手可帮助您设置数据属性。要使用数据类型助手,请点击 the Show data type assistant button。有关详细信息,请参阅使用数据类型助手指定数据类型。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: ProductDataTypeStr
值: 'Inherit: Inherit via internal rule' (默认) | "Inherit: Same as input" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",ProductDataTypeStr="Inherit: Same as input")

指定累加器数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 从内部规则继承

  • 内置数据类型,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

数据类型助手可帮助您设置数据属性。要使用数据类型助手,请点击 the Show data type assistant button。有关详细信息,请参阅使用数据类型助手指定数据类型。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: AccumDataTypeStr
值: 'Inherit: Inherit via internal rule' (默认) | "Inherit: Same as input" | "Inherit: Same as product output" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",AccumDataTypeStr="Inherit: Same as input")

指定状态数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 与累加器相同

  • 内置整数,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

依赖关系

要启用此参数,请将滤波器结构设置为格型 MA。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: StateDataTypeStr
值: 'Inherit: Same as accumulator' (默认) | "Inherit: Same as input" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",StateDataTypeStr="Inherit: Same as input")

指定输出数据类型。可以将其设置为:

  • 继承数据类型的规则,例如继承: 与输入相同

  • 内置数据类型,例如 int8

  • 数据类型对象,例如 Simulink.NumericType 对象

  • 计算结果为数据类型的表达式,例如 fixdt(1,16,0)

数据类型助手可帮助您设置数据属性。要使用数据类型助手,请点击 the Show data type assistant button。有关详细信息,请参阅使用数据类型助手指定数据类型。

当模块的输入是浮点时,输出数据类型匹配输入数据类型,因为浮点继承优先于定点设置。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: OutDataTypeStr
值: 'Inherit: Same as accumulator' (默认) | "Inherit: Same as input" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32" | "int64" | "uint64" | "fixdt(1,16)" | "fixdt(1,16,0)" | "<data type expression>"
数据类型: char | string

示例: set_param("myModel/Discrete FIR Filter",OutDataTypeStr="Inherit: Same as input")

软件检查的输出范围的下限值。

软件使用最小值执行下列操作:

提示

输出最小值不会对实际输出信号进行饱和处理或截断。请改用 Saturation 模块。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: OutMin
值: '[]' (默认) | scalar in quotes

软件检查的输出范围的上限值。

软件使用最大值执行下列操作:

提示

输出最大值不会对实际输出信号进行饱和处理或截断。请改用 Saturation 模块。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: OutMax
值: '[]' (默认) | scalar in quotes

选择此选项可锁定数据类型设置,防止使用定点工具和定点顾问进行更改。有关详细信息,请参阅Lock the Output Data Type Setting (Fixed-Point Designer)。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: LockScale
值: 'off' (默认) | "on"

指定定点运算的舍入模式。有关详细信息,请参阅舍入模式 (Fixed-Point Designer)。

编程用法

模块参数:RndMeth
类型:字符向量
值:'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
默认值:'Floor'

指定对溢出是进行饱和处理还是绕回处理。

  • on - 将溢出饱和处理为数据类型能够表示的最小值或最大值。

  • off - 溢出将绕回到数据类型可以表示的合适值。

例如,有符号 8 位整数 int8 可以表示的最大值是 127。任何大于此最大值的模块运算结果都会导致 8 位整数溢出。

  • 选择此参数后,模块输出将在达到 127 时饱和。类似地,模块输出将在达到最小输出值 -128 时饱和。

  • 清除此参数后,软件会将导致溢出的值解释为 int8,这可能产生意外结果。例如,以 int8 表示的模块结果 130(二进制 1000 0010)为 -126。

提示

  • 如果您的模型存在可能的溢出,而您希望在生成的代码中进行显式饱和保护,请考虑选中此参数。

  • 如果您希望优化生成的代码的效率,请考虑清除此参数。清除此参数还可以帮助您避免过度地指定信号超出范围时模块的处理方式。有关详细信息,请参阅信号范围错误故障排除。

  • 如果选中此参数,饱和将应用于模块中的每个内部操作,而不仅仅应用于输出或结果。

  • 一般情况下,代码生成进程可以检测到何时不可能发生溢出。在这种情况下,代码生成器不会生成饱和代码。

编程用法

要以编程方式设置模块参数值,请使用 set_param 函数。

参数: SaturateOnIntegerOverflow
值: 'off' (默认) | 'on'

模块特性

数据类型

double | fixed point | integer | single

直接馈通

否

多维信号

否

可变大小信号

是

过零检测

否

详细信息

全部展开

算法

以下是 Discrete FIR Filter 模块中使用的结构图。

直接型

Signal flow diagram of the direct form FIR filter structure. The input signal enters from the left and feeds into a chain of unit-delay blocks labeled z to the power of negative 1 connected in series from top to bottom. The input and each delayed version of the input branch rightward into triangular gain blocks labeled b sub 0, b sub 1, through b sub N, representing the filter coefficients. Each gain output feeds into a chain of circular summation nodes that accumulate all weighted signals. The final accumulated sum exits as the output on the right. Ellipsis dots between the middle delay stages indicate the pattern continues for an arbitrary number of filter taps.

直接型对称

假定滤波器系数对称。该模块仅使用系数的前半部分进行滤波。

Signal flow diagrams of two direct form symmetric FIR filter structures shown side by side. On the left is the even order Type I structure, where the input feeds into a vertical chain of z to the power of negative 1 delay blocks and symmetric tap pairs from the top and bottom of the delay line are added together in circular summation nodes before being multiplied by coefficients b sub 0, b sub 1, through b sub N over 2. The weighted results are accumulated through a summation chain to produce the output. On the right is the odd order Type II structure, which has a similar layout but with an additional delay element to accommodate the odd number of taps. The center tap, which has no symmetric partner, passes through its own coefficient multiplier independently. Both structures exploit the symmetric property of the filter coefficients to reduce the number of multiplications by half.

直接型反对称

假定滤波器系数反对称。该模块仅使用系数的前半部分进行滤波。

Signal flow diagrams of two direct form antisymmetric FIR filter structures shown side by side. On the left is the even order Type III structure, and on the right is the odd order Type IV structure. Both structures are visually similar to the direct form symmetric structures but use subtraction instead of addition when combining the antisymmetric tap pairs, reflecting the property that filter coefficients satisfy b sub k equals negative b sub N minus k. The input feeds into a chain of z to the power of negative 1 delay blocks, antisymmetric tap pairs are subtracted, and the results are multiplied by coefficients b sub 0, b sub 1, through b sub N over 2 before accumulation to produce the output. The odd order version has an additional delay element and a center tap that passes through its own coefficient multiplier.

直接型转置

当输入或系数为复数时,状态为复数。

Signal flow diagram of the direct form transposed FIR filter structure. The section input enters from the left and fans out simultaneously to all triangular coefficient gain blocks labeled b sub 0, b sub 1, through b sub N. Each coefficient multiplier output feeds into a circular summation node. The partial sums propagate upward through a chain of z to the power of negative 1 delay blocks. At each stage, the delayed partial sum from the stage below is added to the current coefficient product. The topmost stage, corresponding to coefficient b sub 0, produces the section output on the right. Ellipsis between the middle stages indicates the pattern repeats for an arbitrary number of taps.

格型 MA

Signal flow diagram of one stage of the lattice MA moving average FIR filter structure. The input enters from the left and splits into upper and lower signal paths that are cross-coupled through the reflection coefficients. In the upper path, the input feeds into a circular summation node along with a branch that passes through a triangular gain block labeled k sub i representing the reflection coefficient. In the lower path, the delayed signal from a z to the power of negative 1 delay block passes through a rectangular block labeled CONJ of k sub i, representing the conjugate of the reflection coefficient, and feeds into a lower summation node together with the direct input signal. The lower summation output feeds into another z to the power of negative 1 delay block. The upper path also includes a gain block labeled k sub r. The output exits on the right. This cross-coupled lattice topology allows the forward and backward paths to interact through the reflection coefficients.

扩展功能

全部展开

PLC 代码生成
使用 Simulink® PLC Coder™ 生成结构化文本代码。

定点转换
使用 Fixed-Point Designer™ 设计和仿真定点系统。

版本历史记录

在 R2008a 中推出

全部展开