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.

We want to create a lowpass filter with a passband frequency of 0.4*pi rad/sample, a stopband frequency of 0.6*pi 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);

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

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

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 = Tag: 'filtervisualizationtool' UIContextMenu: [0x0 GraphicsPlaceholder] UserData: [] Visible: 'on' MagnitudeDisplay: 'Magnitude (dB)' FrequencyRange: '[0, pi)' NumberofPoints: 8192 NormalizedFrequency: 'on' Analysis: 'magnitude' FrequencyScale: 'Linear' ShowReference: 'on' FrequencyVector: [1x256 double] NormalizeMagnitudeto1: 'off' OverlayedAnalysis: '' PolyphaseView: 'off'

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 = 'Magnitude' 'Magnitude (dB)' 'Magnitude squared' 'Zero-phase'

Turn the display to 'Magnitude Squared'

```
hfvt.MagnitudeDisplay = 'Magnitude Squared';
```

Get all possible values for the 'Analysis' property

```
set(hfvt, 'Analysis')
```

ans = Columns 1 through 6 'magnitude' 'phase' 'freq' 'grpdelay' 'phasedelay' 'impulse' Columns 7 through 11 'step' 'polezero' 'coefficients' 'info' 'magestimate' Column 12 '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;

We would also like to see how the Group Delay and the Zero-phase 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', 'MagnitudeDisplay', 'Zero-phase', ... 'Legend', 'On');

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

hfvt.OverlayedAnalysis = ''; hfvt.Legend = 'Off';

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.

delete(htext); close(hfvt)

Was this topic helpful?