ELEC 241 Lab

Experiment 8.1

Filtering, Continued

We will use the same setup (mixer amp to A/D and sound out to earphone amp) this week as we did last week. For circuit diagrams, refer back to Lab7.

Part 1: Reference Signals

If you saved your reference signals from last week, you can use them. If not, record a new spoken reference signal (sig1).

Part 2: New Filters for Old

Since multiplying a time function by $\cos(2\pi f_0 n)$ shifts the spectrum of the signal by $f_0$ in the frequency domain, we can shift the frequency response of a filter by multiplying its time domain representation (its unit-pulse response) by $\cos(2\pi f_0 n)$ . In the case of an FIR filter, this is particularly handy, because the unit-sample response is the filter. So if we multiply the coefficients of an FIR filter by $\cos(2\pi f_0 n)$ we get a new filter having the same shape as the old one (including negative frequencies) but centered about $f_0$ rather than zero.

We saw this happen indirectly when we changed the sign of $a_1$ in our first order IIR filter. The frequency response went from low pass to high pass and the new pulse response contained the same values as the old, but they alternated in sign (i.e. were multiplied by (1, -1, 1, -1, ...) = $\cos(2\pi \frac{1}{2} n)$ = $\cos(n\pi)$ = $(-1)^n$ .

Let's try this with an FIR filter.


Step 1:

Generate a length 50 FIR filter having a bandwidth of 1000 Hz.

   >> b0=fir1(50,1000/5000);


Step 2:

Plot its frequency response to verify it is correct.

   >> freqz(b0,1)


Step 3:

Create a new filter by multiplying the coefficients by $\cos(n\pi)$ .

   >> b1 = b0 .* cos(pi*[0:50]);


Step 4:

Once again we have a high pass filter, but this time much more nearly ideal than our simple IIR.

   >> freqz(b1,1)

Apply this filter to your speech reference signal.

   >> out1=filter(b1, 1, sig1);


Step 5:

Listen to the filter output and plot its spectrogram.

Step 6:

What happens if we don't shift all the way to Fs/2? Lets try this, but with a narrower filter.

Generate a length 50 FIR filter having a bandwidth of 200 Hz.

   >> b=fir1(50,200/5000);


Step 7:

Plot its frequency response to verify it is correct.

   >> freqz(b,1)


Step 8:

Shift its response up to 2 kHz (0.2 * Fs).

   >> b2 = b .* cos(0.4*pi*[0:50]);
   >> freqz(b2,1)


Question 1:

What is the bandwidth of this bandpass filter? How does it relate to the bandwidth of the low pass filter?

Step 9:

Apply it to your speech reference signal.

   >> out2=filter(b2, 1, sig1);


Step 10:

Listen to the filter output and plot its spectrogram.

Hint:

When a signal is so small that it is hard to hear, or so large that it distorts, use the soundsc() function instead of sound(). This scales the signal to just fill the available output range.

   >> soundsc(out2, Fs)

Part 3: Better IIR Filters

So far we've seen that long (50 in our case) FIR filters can be pretty good and that short filters of either type are pretty bad. What about long IIR filters?

It turns out that if we let our transfer function have both a numerator and a denominator (i.e. both $a$ and $b$ coefficients) we can get filters of "good" shape with a modest number of total coefficients. Filters of this form have been used in analog circuits (where filter order corresponds to the number of inductors and capacitors and op amps, and hence smaller is better) and the techniques for designing them carry over to digital filters. One of these is the Butterworth, which we've already seen. Another is the Elliptic or Cauer filter (so called because its design involves the use of the Jacobi elliptic function).


Step 1:

Let's design an 8th order Elliptic low pass filter with a cutoff frequency of Fs/8:

   >> [b,a] = ellip(8, 1, 60, 1000/5000);
   >> freqz(b,a)

The first argument (8) is the filter order. The second argument (1) is the passband ripple, the amount (in dB) that we're willing to allow the actual value of the transfer function in the passband to deviate from the desired value (1, or 0 dB). The third argument (60) is the maximum value (in dB) that we're willing to allow the transfer function to have in the stopband. Subject to these constraints, the Elliptic design gives us the shortest possible transition band, the region where the transfer function is changing from one to zero.

Step 2:

Apply this filter to your reference signal, listen to the results, and look at the spectrogram. Can you see the difference between this filter and the "equivalent" FIR filter (b0)? Can you hear it?

Question 2:

Make a capsule summary of each of the different types of filter we've looked at (boxcar, first order IIR, Butterworth, fir1, elliptic). Consider such factors as the shape of the frequency response, phase characteristics, computational complexity, etc.

Is any one type of filter clearly the "best" (or the "worst")? If not, can you identify circumstances where a particular filter would be the best choice (or should not be chosen)?