Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

使用 FVTool 进行滤波器分析

此示例说明如何通过滤波器可视化工具 (FVTool) 在单个图窗窗口中使用多个滤波器分析函数,Fvtool 是 Signal Processing Toolbox™ 中提供的一个图形用户界面。

FVTool 还有一个应用程序编程接口 (API),以支持您从命令行与 GUI 交互。这使您能够将 FVTool 集成到其他应用程序中。

启动 FVTool

我们希望创建一个低通滤波器,其通带频率为 0.4π 弧度/采样点、阻带频率为 0.6π 弧度/采样点、通带波纹为 1 dB、阻带衰减为 80 dB。我们使用 Signal Processing Toolbox 的一些滤波器设计工具来设计滤波器,然后在 FVTool 中分析结果。

设计低通等波纹 FIR 滤波器。

Df1 = designfilt("lowpassfir",PassbandFrequency=0.4,...
                              StopbandFrequency=0.6,...
                              PassbandRipple=1,...
                              StopbandAttenuation=80,...
                              DesignMethod="equiripple");

设计低通椭圆 IIR 滤波器。

Df2 = designfilt("lowpassiir",PassbandFrequency=0.4,...
                              StopbandFrequency=0.6,...
                              PassbandRipple=1,...
                              StopbandAttenuation=80,...
                              DesignMethod="ellip");

使用滤波器对象启动 FVTool 并返回 FVTool 的句柄,这使我们能够重用相同的 FVTool 图窗。

hfvt = fvtool(Df1,Df2);

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 2 objects of type line.

添加和删除滤波器

我们可以观察到两个滤波器都符合设计规范,但仍需要查看切比雪夫 II 型设计的性能如何。

您可以使用 addfilter 函数向 FVTool 添加滤波器。

Df3 = designfilt("lowpassiir",PassbandFrequency=0.4,...
                              StopbandFrequency=0.6,...
                              PassbandRipple=1,...
                              StopbandAttenuation=80,...
                              DesignMethod="cheby2");
addfilter(hfvt,Df3);

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 3 objects of type line.

要识别绘图上的哪条线属于哪个滤波器,可以使用 FVTool 句柄的 legend 函数添加图例。

legend(hfvt,"Equiripple","Elliptic","Chebyshev Type II");

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains 3 objects of type line. These objects represent Equiripple, Elliptic, Chebyshev Type II.

您可以使用 deletefilter 函数并传递要删除的滤波器的索引,从 FVTool 中删除滤波器。

deletefilter(hfvt,[1 3]);

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains an object of type line. This object represents Elliptic.

更改分析参数

FVTool 返回的句柄包含允许您与滤波器和当前分析进行交互的属性。要查看所有可用的属性,请使用 get 命令。显示特定于 FVTool 的最后 14 个属性。

s = get(hfvt);

Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude (dB) contains an object of type line. This object represents Elliptic.

% Keep the last 14 properties
c = struct2cell(s);
f = fieldnames(s);
s = cell2struct(c(end-14:end),f(end-14:end),1)
s = struct with fields:
       SelectionHighlight: on
                      Tag: 'filtervisualizationtool'
                 UserData: []
                  Visible: on
           FrequencyScale: 'Linear'
                 Analysis: 'magnitude'
      NormalizedFrequency: 'on'
           FrequencyRange: '[0, pi)'
          FrequencyVector: [0 0.0039 0.0078 0.0118 0.0157 0.0196 0.0235 0.0275 0.0314 0.0353 0.0392 0.0431 0.0471 0.0510 0.0549 0.0588 0.0627 0.0667 0.0706 0.0745 0.0784 0.0824 0.0863 0.0902 0.0941 0.0980 0.1020 0.1059 0.1098 0.1137 ... ] (1x256 double)
        OverlayedAnalysis: ''
         MagnitudeDisplay: 'Magnitude (dB)'
            PolyphaseView: 'off'
            ShowReference: 'on'
           NumberofPoints: 8192
    NormalizeMagnitudeto1: 'off'

所有可从 FVTool 的“分析参数”对话框获得的参数也可用作 FVTool 对象的属性。只带两个输入参数的 set 命令返回所有可能的值。

set(hfvt,"MagnitudeDisplay")
ans = 1x4 cell
    {'Magnitude'}    {'Magnitude (dB)'}    {'Magnitude squared'}    {'Zero-phase'}

将显示转至 Magnitude Squared

hfvt.MagnitudeDisplay = "Magnitude Squared";

Figure Figure 1: Magnitude Response (squared) contains an axes object. The axes object with title Magnitude Response (squared), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Magnitude squared contains an object of type line. This object represents Elliptic.

获取 Analysis 属性的所有可能值。

set(hfvt,"Analysis")
ans = 1x12 cell
    {'magnitude'}    {'phase'}    {'freq'}    {'grpdelay'}    {'phasedelay'}    {'impulse'}    {'step'}    {'polezero'}    {'coefficients'}    {'info'}    {'magestimate'}    {'noisepower'}

现在更改分析,看看滤波器的群延迟响应。显示默认单位。

hfvt.Analysis = "grpdelay";

Figure Figure 1: Group delay contains an axes object. The axes object with title Group delay, xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Group delay (in samples) contains an object of type line. This object represents Elliptic.

GroupDelayUnits = hfvt.GroupDelayUnits
GroupDelayUnits = 
'Samples'

重叠两个分析

我们还想查看群延迟和幅值响应在频域中是如何重叠的。

通过设置 OverlayedAnalysis 属性,可以在 FVTool 中重叠共用一个 x 轴(时间或频率)的任意两个分析。

set(hfvt,OverlayedAnalysis="magnitude",Legend="On")

Figure Figure 1: Group delay and Magnitude Response (dB) contains an axes object. The axes object with title Group delay and Magnitude Response (dB), xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Group delay (in samples) contains an object of type line. This object represents Elliptic: Group delay.

要关闭重叠的分析,请将 OverlayedAnalysis 属性设置为 ''

hfvt.OverlayedAnalysis = '';

Figure Figure 1: Group delay contains an axes object. The axes object with title Group delay, xlabel Normalized Frequency ( times pi blank rad/sample), ylabel Group delay (in samples) contains an object of type line. This object represents Elliptic.

您可以通过对 FVTool 句柄调用 close 函数来关闭 FVTool 图窗。

close(hfvt)

另请参阅

|