# Documentation

## Using the Filter Designer

### Filter Designer

FDATool is the recommended filter design tool. Filter Designer will be removed in a future release. The following information is provided for users that choose to use Filter Designer while they transition to FDATool. Filter Designer, provides an interactive graphical environment for the design of digital IIR and FIR filters based on specifications that you enter on a magnitude or pole-zero plot.

### Filter Types

You can design filters of the following types using the Filter Designer:

• Bandpass

• Lowpass

• Bandstop

• Highpass

### FIR Filter Methods

You can use the following filter methods to design FIR filters:

• Equiripple

• Least squares

• Window

### IIR Filter Methods

You can use the following filter methods to design IIR filters:

• Butterworth

• Chebyshev Type I

• Chebyshev Type II

• Elliptic

### Pole/Zero Editor

You can use the Pole/Zero Editor to design arbitrary FIR and IIR filters by placing and moving poles and zeros on the complex z-plane.

### Spectral Overlay Feature

You can also superimpose spectra on a filter's magnitude response to see if the filtering requirements are met.

### Opening the Filter Designer

Open the Filter Designer from SPTool by either:

• Clicking New in the Filters list in SPTool

• Selecting a filter you want to edit from the Filters list in SPTool, and then clicking Edit

The Filter Designer has the following components:

• A pull-down Filter menu for selecting a filter from the list in SPTool

• A Sampling Frequency text box

• A pull-down Algorithm menu for selecting a filter design method or a pole-zero plot display

• A Specifications area for viewing or modifying a filter's design parameters or pole-zero locations

• A plot display region for graphically adjusting filter magnitude responses or the pole-zero locations

• A Measurements area for viewing the response characteristics and stability of the current filter

• A toolbar with the following buttons

Icon

Description

Print and print preview

Zoom in and out

Passband view

Overlay spectrum

Turn on the What's This help

### Accessing Filter Parameters in a Saved Filter

The MATLAB® structures created by SPTool have several associated fields, many of which are also MATLAB structures. See the MATLAB documentation for general information about MATLAB structures.

For example, after exporting a filter filt1 to the MATLAB workspace, type

```filt1 ```

to display the fields of the MATLAB filter structure. The ```tf, Fs```, and `specs` fields of the structure contain the information that describes the filter.

#### The tf Field: Accessing Filter Coefficients

The `tf` field is a structure containing the transfer function representation of the filter. Use this field to obtain the filter coefficients;

• `filt1.tf.num` contains the numerator coefficients.

• `filt1.tf.den` contains the denominator coefficients.

The vectors contained in these structures represent polynomials in descending powers of z. The numerator and denominator polynomials are used to specify the transfer function

`$H\left(z\right)=\frac{B\left(z\right)}{A\left(z\right)}=\frac{b\left(1\right)+b\left(2\right){z}^{-1}+\cdots +b\left(nb+1\right){z}^{-m}}{a\left(1\right)+a\left(2\right){z}^{-1}+\cdots +a\left(na+1\right){z}^{-n}}$`

where:

• b is a vector containing the coefficients from the `tf.num` field.

• a is a vector containing the coefficients from the `tf.den` field.

• m is the numerator order.

• n is the denominator order.

You can change the filter representation from the default transfer function to another form by using the `tf2ss` or `tf2zp` functions.

#### The Fs Field: Accessing Filter Sample Frequency

The `Fs` field contains the sampling frequency of the filter in hertz.

#### The specs Field: Accessing other Filter Parameters

The `specs` field is a structure containing parameters that you specified for the filter design. The first field, `specs.currentModule`, contains a string representing the most recent design method selected from the Filter Designer's Algorithm list before you exported the filter. The possible contents of the `currentModule` field and the corresponding design methods are shown below.

Contents of the currentModule field

Design Method

`fdbutter`

Butterworth IIR

`fdcheby1`

Chebyshev Type I IIR

`fdcheby2`

Chebyshev Type II IIR

`fdellip`

Elliptic IIR

`fdfirls`

Least Squares FIR

`fdkaiser`

Kaiser Window FIR

`fdremez`

Equiripple FIR

Following the `specs.currentModule` field, there may be up to seven additional fields, with labels such as `specs.fdremez`, `specs.fdfirls`, etc. The design specifications for the most recently exported filter are contained in the field whose label matches the `currentModule` string. For example, if the `specs` structure is

```filt1.specs ans currentModule: 'fdremez' fdremez: [1x1 struct] ```

the filter specifications are contained in the `fdremez` field, which is itself a data structure.

The specifications include the parameter values from the Specifications region of the Filter Designer, such as band edges and filter order. For example, the filter above has the following specifications stored in `filt1.specs.fdremez`:

```filt1.specs.fdremez ans = setOrderFlag: 0 type: 3 f: [0 0.2000 0.3000 0.5000 0.6000 1] m: [6x1 double] Rp: 0.0100 Rs: 75 wt: [3.2371 1 3.2371] order: 78 ```

Because certain filter parameters are unique to a particular design, this structure has a different set of fields for each filter design.

The table below describes the possible fields associated with the filter design specification field (the `specs` field) that can appear in the exported structure.

Parameter

Description

`Beta`

Kaiser window β parameter.

`f`

Contains a vector of band-edge frequencies, normalized so that 1 Hz corresponds to half the sample frequency.

`Fpass`

Passband cutoff frequencies. Scalar for lowpass and highpass designs, two-element vector for bandpass and bandstop designs.

`Fstop`

Stopband cutoff frequencies. Scalar for lowpass and highpass designs, two-element vector for bandpass and bandstop designs.

`m`

The response magnitudes corresponding to the band-edge frequencies in `f`.

`order`

Filter order.

`Rp`

Passband ripple (dB)

`Rs`

Stopband attenuation (dB)

`setOrderFlag`

Contains `1` if the filter order was specified manually (i.e., the Minimum Order box in the Specifications region was not selected). Contains `0` if the filter order was computed automatically.

`type`

Contains `1` for lowpass, `2` for highpass, `3` for bandpass, or `4` for bandstop.

`w3db`

-3 dB frequency for Butterworth IIR designs.

`wind`

Vector of Kaiser window coefficients.

`Wn`

Cutoff frequency for the Kaiser window FIR filter when `setOrderFlag = 1`.

`wt`

Vector of weights, one weight per frequency band.

### Designing a Filter with the Pole/Zero Editor

To design a filter transfer function using the Filter Designer Pole/Zero Editor:

1. Select the `Pole/Zero Editor` option from the Algorithm list to open the Pole/Zero Editor in the Filter Designer display.

2. Enter the desired filter gain in the Gain edit box.

3. Select a pole or zero (or conjugate pair) by selecting one of the (pole) or (zero) symbols on the plot.

4. Choose the coordinates to work in by specifying `Polar` or `Rectangular` from the Coordinates list.

5. Specify the new location(s) of the selected pole, zero, or conjugate pair by typing values into the Mag and Angle fields (for angular coordinates) or X and Y (for rectangular coordinates) fields. Alternatively, position the poles and zeros by dragging the and symbols.

6. Use the Conjugate pair check box to create a conjugate pair from a lone pole or zero, or to break a conjugate pair into two individual poles or zeros.

Design a new filter or edit an existing filter in the same way.

 Note   Keep the Filter Visualization Tool (FVTool) open while designing a filter with the Pole/Zero Editor. Any changes that you make to the filter transfer function in the Pole/Zero Editor are then simultaneously reflected in the response plots of FVTool.

### Positioning Poles and Zeros

You can use your mouse to move poles and zeros around the pole/zero plot and modify your filter design.

Icon

Description

Enable moving poles or zeros by dragging on the plot

Erase poles or zeros

You can move both members of a conjugate pair simultaneously by manipulating just one of the poles or zeros.

To ungroup conjugates, select the desired pair and clear Conjugate pair in the Specifications region on the Filter Designer.

When you place two or more poles (or two or more zeros) directly on top of each other, a number is displayed next to the symbols (on the left for poles, and on the right for zeros) indicating the number of poles or zeros at that location (e.g., for three zeros). This number makes it easy to keep track of all the poles and zeros in the plot area, even when several are superimposed on each other and are not visually differentiable. Note, however, that this number does not indicate the multiplicity of the poles or zeros to which it is attached.

To detect whether or not a set of poles or zeros are truly multiples, use the zoom tools to magnify the region around the poles or zeros in question. Because numerical limitations usually prevent any set of poles or zeros from sharing exactly the same value, at a high enough zoom level even truly multiple poles or zeros appear distinct from each other.

A common way to assess whether a particular group of poles or zeros contains multiples is by comparing the mutual proximity of the group members against a selected threshold value. As an example, the `residuez` function defines a pole or zero as being a multiple of another pole or zero if the absolute distance separating them is less than 0.1% of the larger pole or zero's magnitude.

### Redesigning a Filter Using the Magnitude Plot

After designing a filter in the Filter Designer, you can redesign it by dragging the specification lines on the magnitude plot. Use the specification lines to change passband ripple, stopband attenuation, and edge frequencies.

In the following example, create a Chebyshev filter and modify it by dragging the specification lines:

1. Select `Chebyshev` `Type` `I` `IIR` from the Algorithm menu.

2. Select `highpass` from the Type menu.

3. Type `2000` in the Sampling Frequency field.

4. Set the following parameters:

• Fp = `800`

• Fs = `700`

• Rp = `2.5`

• Rs = `35`

5. Select Minimum Order so the Filter Designer can calculate the lowest filter order that produces the desired characteristics.

6. Click Apply to compute the filter and update the response plot.

7. Position the cursor over the horizontal filter specification line for the stopband. This is the first (leftmost) horizontal specification line you see.

The cursor changes to the up/down drag indicator.

8. Drag the line until the Rs (stopband attenuation) field reads `100`.

 Note   The Order value in the Measurements region changes because a higher filter order is needed to meet the new specifications.