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 design the filters using some of the Signal Processing Toolbox 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);

{"String":"Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 2 objects of type line.","Tex":"Magnitude Response (dB)","LaTex":[]}

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);

{"String":"Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 3 objects of type line.","Tex":"Magnitude Response (dB)","LaTex":[]}

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");

{"String":"Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 3 objects of type line. These objects represent Equiripple, Elliptic, Chebyshev Type II.","Tex":"Magnitude Response (dB)","LaTex":[]}

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]);

{"String":"Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains an object of type line. This object represents Elliptic.","Tex":"Magnitude Response (dB)","LaTex":[]}

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, use the get command. Display the last fourteen properties which are specific to FVTool.

s = get(hfvt);

{"String":"Figure Figure 1: Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains an object of type line. This object represents Elliptic.","Tex":"Magnitude Response (dB)","LaTex":[]}

% 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
           FrequencyRange: '[0, pi)'
      NormalizedFrequency: 'on'
         MagnitudeDisplay: 'Magnitude (dB)'
                 Analysis: 'magnitude'
          FrequencyVector: [0 0.0039 0.0078 0.0118 0.0157 0.0196 0.0235 ... ]
        OverlayedAnalysis: ''
           FrequencyScale: 'Linear'
            PolyphaseView: 'off'
            ShowReference: 'on'
           NumberofPoints: 8192
    NormalizeMagnitudeto1: 'off'

All the parameters that are available from the FVTool 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";

{"String":"Figure Figure 1: Magnitude Response (squared) contains an axes object. The axes object with title Magnitude Response (squared) contains an object of type line. This object represents Elliptic.","Tex":"Magnitude Response (squared)","LaTex":[]}

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'}

Now change the analysis to look at the group delay response of the filter. Display the default units.

hfvt.Analysis = "grpdelay";

{"String":"Figure Figure 1: Group delay contains an axes object. The axes object with title Group delay contains an object of type line. This object represents Elliptic.","Tex":"Group delay","LaTex":[]}

GroupDelayUnits = hfvt.GroupDelayUnits
GroupDelayUnits = 
'Samples'

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")

{"String":"Figure Figure 1: Group delay and Magnitude Response (dB) contains an axes object. The axes object with title Group delay and Magnitude Response (dB) contains an object of type line. This object represents Elliptic: Group delay.","Tex":"Group delay and Magnitude Response (dB)","LaTex":[]}

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

hfvt.OverlayedAnalysis = '';

{"String":"Figure Figure 1: Group delay contains an axes object. The axes object with title Group delay contains an object of type line. This object represents Elliptic.","Tex":"Group delay","LaTex":[]}

You can close the FVTool figure by calling the close function on the FVTool handle.

close(hfvt)

See Also

|