Main Content

Filter Analysis Using FVTool

This example shows how to use several filter analysis functions in a single figure window by using the Filter Visualization Tool (FVTool), a graphical user interface available in Signal Processing Toolbox™.

FVTool also has an Application Program Interface (API) that allows you to interact with the GUI from the command line. This enables you to integrate FVTool into other applications.

Launch FVTool

We want to create a lowpass filter with a passband frequency of 0.4π rad/sample, a stopband frequency of 0.6π rad/sample, a passband ripple of 1 dB and a stopband attenuation of 80 dB. We will design the filters using some of the Signal Processing Toolbox's filter design tools and then analyze the results in FVTool.

Design a lowpass equiripple FIR filter

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

Design a lowpass elliptic IIR filter

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

Launch FVTool with the filter objects and return a handle to FVTool which enables us to reuse the same FVTool figure.

hfvt = fvtool(Df1, Df2);

Figure Filter Visualization Tool - Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (dB) contains 2 objects of type line.

Add and Remove Filters

We can observe that both filters meet the design specifications, but we also want to see how well the Chebyshev Type II design performs.

You can add a filter to FVTool using the ADDFILTER function.

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

Figure Filter Visualization Tool - Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (dB) contains 3 objects of type line.

To identify which line on the plot belongs to which filter, you can add a legend using the LEGEND function of the FVTool handle.

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

Figure Filter Visualization Tool - Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (dB) contains 3 objects of type line. These objects represent Equiripple, Elliptic, Chebyshev Type II.

You can remove a filter from FVTool using the DELETEFILTER function and passing the index of the filter(s) that you want to remove.

deletefilter(hfvt, [1 3]);

Figure Filter Visualization Tool - Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (dB) contains an object of type line. This object represents Elliptic.

Change Analysis Parameters

The handle that FVTool returns contains properties that allow you to interact with both the filter and the current analysis.

To see all of the available properties you can use the GET command. The first properties are those of a regular MATLAB® figure. The last fourteen properties are FVTool specific. The last six of these (from FrequencyScale to MagnitudeDisplay) are analysis specific.

s = get(hfvt);

Figure Filter Visualization Tool - Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (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
         MagnitudeDisplay: 'Magnitude (dB)'
           NumberofPoints: 8192
    NormalizeMagnitudeto1: 'off'
      NormalizedFrequency: 'on'
           FrequencyScale: 'Linear'
                 Analysis: 'magnitude'
           FrequencyRange: '[0, pi)'
          FrequencyVector: [0 0.0039 0.0078 0.0118 0.0157 0.0196 0.0235 ... ]
            PolyphaseView: 'off'
        OverlayedAnalysis: ''
            ShowReference: 'on'

All the parameters that are available from the FVTool's Analysis Parameters dialog are also available as properties of the FVTool object. The SET command with only two input arguments returns all possible values.

set(hfvt, 'MagnitudeDisplay')
ans = 1x4 cell
  Columns 1 through 3

    {'Magnitude'}    {'Magnitude (dB)'}    {'Magnitude squared'}

  Column 4

    {'Zero-phase'}

Turn the display to 'Magnitude Squared'

hfvt.MagnitudeDisplay = 'Magnitude Squared';

Figure Filter Visualization Tool - Magnitude Response (squared) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Magnitude Response (squared) contains an object of type line. This object represents Elliptic.

Get all possible values for the 'Analysis' property

set(hfvt, 'Analysis')
ans = 1x12 cell
  Columns 1 through 5

    {'magnitude'}    {'phase'}    {'freq'}    {'grpdelay'}    {'phasedelay'}

  Columns 6 through 10

    {'impulse'}    {'step'}    {'polezero'}    {'coefficients'}    {'info'}

  Columns 11 through 12

    {'magestimate'}    {'noisepower'}

Let us now change the analysis to look at the Group Delay Response of the filter.

hfvt.Analysis = 'grpdelay';

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay contains an object of type line. This object represents Elliptic.

The GET command will return new Analysis Parameters for the new analysis.

GroupDelayUnits = hfvt.GroupDelayUnits;

Overlay Two Analyses

We would also like to see how the Group Delay and the magnitude response overlap in the frequency domain.

You can overlay any two analyses in FVTool that share a common x-axis (time or frequency) by setting the 'OverlayedAnalysis' property.

set(hfvt, 'OverlayedAnalysis', 'magnitude', 'Legend', 'On')

Figure Filter Visualization Tool - Group delay and Magnitude Response (dB) contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay and Magnitude Response (dB) contains an object of type line. This object represents Elliptic: Group delay.

To turn off the overlayed analysis simply set the 'OverlayedAnalysis' property to ''.

hfvt.OverlayedAnalysis = '';

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay contains an object of type line. This object represents Elliptic.

Interact with FVTool like a Figure Window

The FVTool window can also be annotated like a normal figure window.

The FVTool figure behaves as a normal figure window. This allows you to use MATLAB's grid and axis functions.

grid on
axis([.3 .45 5 25]);

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group delay contains an object of type line. This object represents Elliptic.

The axis is also accessible from the command line. This allows you to change the title and labels.

title('Group Delay of an Elliptic filter');
xlabel('Frequency (normalized to 1)');
ylabel('Group Delay in samples');

htext = text(.35, 23, 'Maximum Group Delay');

Figure Filter Visualization Tool - Group delay contains an axes object and other objects of type uitoolbar, uimenu. The axes object with title Group Delay of an Elliptic filter contains 2 objects of type line, text. This object represents Elliptic.

FVTool will not automatically delete additional annotations from your analysis, you can do this by deleting the handle itself. You can close the FVTool figure by calling the close function on the FVTool handle.

delete(htext);
close(hfvt)

See Also

|