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 the 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.

Launching 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,...

Design a lowpass elliptic IIR filter

Df2 = designfilt('lowpassiir','PassbandFrequency',0.4,...

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

Adding and Removing 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,...
addfilter(hfvt, Df3);

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

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

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

% 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)'
           FrequencyScale: 'Linear'
           NumberofPoints: 8192
    NormalizeMagnitudeto1: 'off'
      NormalizedFrequency: 'on'
          FrequencyVector: [1x256 double]
            PolyphaseView: 'off'
                 Analysis: 'magnitude'
        OverlayedAnalysis: ''
            ShowReference: 'on'
           FrequencyRange: '[0, pi)'

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


Turn the display to 'Magnitude Squared'

hfvt.MagnitudeDisplay = 'Magnitude Squared';

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

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

GroupDelayUnits = hfvt.GroupDelayUnits;

Overlaying 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')

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

hfvt.OverlayedAnalysis = '';

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

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

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.


See Also