# Digital Signal Processing/Digital Filters

Digital Filters can be very complicated devices, but they must be able to map to the difference equations of the filter design. This means that since difference equations only have a limited number of operations available (addition and multiplication), digital filters only have limited operations that they need to handle as well. There are only a handful of basic components to a digital filter, although these few components can be arranged in complex ways to make complicated filters.

## Contents

## Digital Filter Types[edit]

There are two types of filters in the digital realm: **Finite Impulse Response** (FIR) filters and **Infinite Impulse Response** (IIR) filters. They are very different in essence.

### FIR Filters[edit]

FIR filters are specific to sampled systems. There is no equivalent in continuous-time systems. Therefore, only very specific analog filters are capable of implementing an FIR filter.

If we define the discrete time impulse function as

the response of an FIR filter to δ*[n]*, denoted as *h[n]*, will decay to zero after a finite number of samples. The transfer function of an FIR filter contains only zeros and either no poles or poles only at the origin.

An FIR filter with symmetric coefficients is guaranteed to provide a linear phase response, which can be very important in some applications. However, FIR filters suffer from low efficiency, and creating an FIR to meet a given spec requires much more hardware than an equivalent IIR filter.

### IIR Filters (infinite impulse response filter)[edit]

IIR filters are typically designed basing on continuus-time transfer functions. IIR filters differ from FIR filters because they always contain feedback elements in the circuit, which can make the transfer functions more complicated to work with.

The transfer function of an IIR filter contains both poles and zeros. Its impulse response never decays to zero (though it may get so close to zero that the response cannot be represented with the number of bits available in the system).

IIR filters provide extraordinary benefits in terms of computing: IIR filters are more than *an order of magnitude more efficient* than an equivalent FIR filter. Even though FIR is easier to design, IIR will do the same work with fewer components, and fewer components translate directly to less money.

#### Filtering a time-series in Octave/Sciplot[edit]

First create some points for a time series. In this case we'll create one second of random data sampled at 44 kHz.

sampling_t = 1/44000; t = 0:sampling_t:1; x = rand(size(t));

Have a look at the time series

plot(t,x);

Have a look at its spectrum (it is mostly uniform, what we would expect from noise)

specgram(x)

Now we'll use a built-in function to create a third order Butterworth low-pass filter with cutoff frequency pi*0.1 radians

[b,a] = butter(3,0.1)

Now filter the time series.

y = filter(b,a,x);

Have a look at the first 100 points of the filtered data.

hold on plot(y(1:100)) plot(x(1:100)) hold off

Check its spectrogram

specgram(y)

Now look at the magnitude of the FFT

plot(log(abs(fft(y))))

## Filter response Types[edit]

### High-pass and Low-pass[edit]

High-Pass and Low-Pass filters are the simplest forms of digital filters, and they are relatively easy to design to specifications. This page will discuss high-pass and low-pass transfer functions, and the implementations of each as FIR and IIR designs.

### Band-pass[edit]

**Band-pass Filters** are like a combination of a high-pass and a low-pass filter. Only specific bands are allowed to pass through the filter. Frequencies that are too high or too low will be rejected by the filter.

### Stop-band[edit]

**Notch filters** are the complement of Band-pass filters in that they only stop a certain narrow band of frequency information, and allow all other data to pass without problem.

### Notch[edit]

The direct complement of a bandpass filter is called a **bandstop filter**. A notch filter is essentially a very narrow bandstop filter.

### Comb Filters[edit]

**Comb Filters**, as their name implies, look like a hair comb. They have many "teeth", which in essence are notches in the transfer function where information is removed. These notches are spaced evenly across the spectrum, so they are only useful for removing noise that appear at regular frequency intervals.

### All-pass[edit]

The All-pass filter is a filter that has a unity magnitude response for all frequencies. It does not affect the frequency response of a filter. The All-pass filter does affect the phase response of the system. For example, if an IIR filter is designed to meet a prescribed magnitude response often the phase response of the system will become non-linear. To correct for this non-linearity an All-pass filter is cascaded with the IIR filter so that the overall response(IIR+All-pass) has a constant group delay.

## Canonic and Non-Canonic[edit]

**Canonic filters** are filters where the order of the transfer function matches the number of delay units in the filter. Conversely, **Noncanonic filters** are when the filter has more delay units than the order of the transfer function. In general, FIR filters are canonic. Some IIR filter implementations are noncanonic.

Here is an example of a canonical, 2nd order filter:

Here is an example of a non-canonical 2nd order filter:

Notice that in the canonical filter, the system order (here: 2) equals the number of delay units in the filter (2). In the non-canonical version, the system order is not equal to the number of delays (4 delay units). Both filters perform the same task. The canonical version results in smaller digital hardware, because it uses fewer delay units. However, this drawback nearly disappears if several second order IIRs are cascaded, as they can share delay elements. In this case, the only "extra" delay elements are those on the input side of the first section.

## Notations[edit]

There are some basic notations that we will be using:

- ω
_{p}Pass-band cut off frequency - ω
_{s}Stop-band cut off frequency - δ
_{p}Pass-band ripple peak magnitude - δ
_{s}Stop-band ripple peak magnitude