project
ECE505 Digital Signal Processing Laboratory Project - IIR Notch Filter Design
Dr. Ratliff
1 Project Definition:
In this project, you are given a digital audio clip that has been corrupted by sinusoidal tones resulting from pressing the numeric keys on a touch-tone phone. The goal is to remove the tones from the signal by designing cascaded digital notch filters. This project is designed to make use of the mathematical tools we have learned this semester by applying them to a practical DSP problem.
2 Problem Description:
The Touch-Tone phone system, developed during the 1960’s by AT&T, was created to eliminate the need for rotary-dialing telephone systems. This is accomplished using Dual-Tone Multi-Frequency (DTMF) signaling and has resulted in the familiar tones we hear when dialing a telephone. As the name implies, each tone is generated by introducing a sinusoidal wave at two distinct frequencies. As such, the DTMF telephone keypad is laid out in a 4 × 4 matrix of push buttons in which each row represents the low frequency component and each column represents the high frequency component of the DTMF signal. Pressing a key sends a combination of the row and column frequencies, as described in the figure below:
For example, pressing the ‘1’ key produces a superposition of tones at 697 and 1209 hertz (Hz). When these keys are pressed, they are mixed with the audio signal from the phone microphone. When such an audio stream is digitized and recorded, it may be desirable to later remove these tones from the audio stream. One way to do this is to design a group of filters such that each respective filter removes the content at a single frequency. Such filters are called digital notch filters. A block diagram for such a system can be represented by:
In this case each hk[n], for k = 1, 2, . . . , 8, represents a digital notch filter for one of the numeric tone frequencies from the DTMF keypad. Thus, if such an ideal filter bank is employed, it would indeed remove the tones resulting from any key-press. Notice that the total impulse response of such a filter bank can be obtained as
h[n] = h1[n] ∗ h2[n] ∗ . . . ∗ h8[n]. (1)
1
In this project we are going to design second order IIR notch filters to remove each sinusoidal frequency term. Thus, we expect to have two poles and two zeros for each filter. For notch filters of this type the design is straight- forward. For each frequency we want to filter, we simply place a pole and zero along a line corresponding to the digital frequency we wish to notch, along with their respective complex conjugate pairs, as shown in the pole-zero diagram below.
Notice that the zero is placed upon the unit circle with a magnitude of 1, i.e., znk = e±jθk , and each pole is
placed at the same angle, θk, only at a magnitude of α, i.e., zdk = αe±jθk , where 0 < α < 1, znk denotes system
zeros and zdk denote system poles. Here θk corresponds directly to the digital frequency of the sinusoid to be notched. Later we will use α as a tuning parameter to optimize our system. We can directly write the transfer function, Hk(z) for this filter from the pole-zero plot above. Once we do this for each frequency we wish to notch, we can form the total system transfer function, i.e,
H(z) = H1(z)H2(z) . . . H8(z). (2)
Once we obtain the total transfer function we can obtain the difference equation for the system and then implement it in a for loop in MATLAB to actually apply it to digital audio signals.
3 Design Tasks:
In this section we will make the computations necessary to design our cascaded digital notch filter. In the document you submit online, create a Design section and provide the information requested below in each task.
1. Compute the digital frequencies in radians per sample corresponding to each of the eight possible sinusoidal frequencies that can be present in the signal for fs = 16kHz. Using these digital frequencies, determine the locations of the poles (zdk) and zeros (znk
) for each notch filter (use polar coordinates). Use a magnitude of 1 for all zeros and assume a magnitude value of α for the poles, where |α| < 1 (this will be a tuning parameter). Create the following table with your results in the document you submit. Create the following table with your results in the document you submit.
Frequency (Hertz) θk znk zdk
697 Hz 770 Hz 852 Hz 941 Hz 1209 Hz 1336 Hz 1477 Hz 1633 Hz
2. Determine the general form for the transfer function, Hk(z), and frequency response, Hk(ejω), of each second order notch filter and as a function of α, znk
and zdk .
2
3. Now, open the provided function cascadeIIRNotch() in MATLAB and study it. This function takes a vector that specifies each digital frequency where we want to create a notch filter, along with the tuning parameter α for the magnitude of each pole. It also allows you to specify β, the magnitude of each zero location. Using the eight digital frequencies calculated above and α = 0.75 and β = 1.0, run the function to compute the coefficients of the numerator and denominator polynomials for the total cascaded transfer function and store the values in variables a and b. Create the following table with your results in the document you submit that specifies these coefficients.
k 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ak bk
Note that the transfer function for the resulting cascaded filter is a 16th order filter of the form
H(z) =
∑16 k=0 akz
16−k∑16 k=0 bkz
16−k , (3)
with frequency response
H(ejω) =
∑16 k=0 ak
( ejω )16−k∑16
k=0 bk (ejω) 16−k , (4)
and corresponding difference equation
y[n] =
16∑ k=0
akx[n− k]− 16∑ k=1
bky[n− k]. (5)
4 Implementation and Analysis:
In this section we will implement and apply our notch filter to digital audio data. Download the audio file crows tones.wav and the MATLAB function cascadeIIRNotch.m that are provided with the assignment on the course website. In your submitted document create an Implementation and Analysis section and include the figures generated and discuss any analysis in this section.
1. Use the analytic form of the frequency response obtained in 3.2 to plot the magnitude |Hk(ejω)| and phase response ∠Hk(ejω) of the notch filters corresponding to 697 and 1633 Hertz. I suggest sampling ω using 2048 points over the [−π, π] window. Assume a value of α = 0.75. Plot both magnitude responses in a subplot on the same figure. Do the same for the phase responses in a separate subplot. Verify that the notched frequencies occur at the digital frequencies you expect. Be sure to properly label all axes and plot these for ω ∈ [−π, π]. Include this plot in your document as Figure 1.
2. Using the coefficients obtained in 3.3 above, use Equation (4) above to plot the analytic magnitude response |H(ejω)| and phase response ∠H(ejω) for the full cascaded system in Figure 2, each within a separate subplot. I suggest sampling ω using 2048 points over the [−π, π] window. Plot the magnitude response in decibels so that you can get better insight into the filter’s performance at the notches. Be sure and label all axes property.
3. Using the coefficients obtained in 3.3 above, use the zplane() function to generate a pole zero plot for the cascaded system in Figure 3.
4. Obtain the impulse response for the total cascaded system by computing the inverse Fourier transform of H(ejω), i.e., (ifft(fftshift(H)), of the analytic frequency response computed in 4.2. Plot the impulse response in Figure 4 for n = [0, 50].
3
5. Read the provided audio file in MATLAB using the audioread() function. Store the returned audio data in the variable x and the returned sampling rate in the variable fs. Use the sound() function to play back the read audio file, ensuring you pass the function both x and fs. You should hear the audio sequence of some crows cawing mixed with 16 tones, one from each press of the keypad.
6. Use a for loop to implement the cascaded digital notch filter as shown in Equation (5) using the ak and bk coefficients that are returned by the cascadeIIRNotch() function. Experiment with the value of α in the range of [0.1 to 0.95] (i.e., placing the poles different distances from their corresponding zeros) until you determine a value for α that removes the tones to your satisfaction. We are trying to remove the tones while preserving the underlying audio signal as best as possible. Note the value of α you find works best for each audio signal.
NOTE: Depending upon your implementation you may need to truncate the first 100 samples or so of y[n] as initial condition effects can cause these values to be very large. It is easiest just to remove them from the signal.
7. Plot the audio sequences as a function of n before and after processing each audio file. Include this plot as Figure 5. Be sure and label all axes properly.
8. Compute the Fourier Transform of the audio signal before and after processing. Plot the magnitude response for the signal and its processed version on the same plot for ω ∈ [−π, π]. Note: to compute the Fourier Transform use: X = abs(fftshift(fft(x, 2048))), where x is the audio data and X is its corresponding Fourier Transform. Include this plot as Figure 6.
5 Questions:
Create a section entitled Results and Discussion and answer the following questions, making use of the design results from Section 2 and the implementation experience and figures generated in Section 3.
1. Regarding Figures 1 through 3, do the notches appear to be at the correct digital frequencies in the pole/zero plot as well as within each filter’s magnitude response?
2. Are the phase responses of each filter in Figure 1 linear? Explain the behavior of the phase response at the notched frequencies.
3. Regarding Figure 2, does the magnitude response of the cascaded filter appear to have the same clean notch shape as the individual filters? What about the phase response?
4. Does the impulse response of the cascaded filter plotted in Figure 4 appear to be that of a stable system?
5. Given the constraints of our 2nd order filters, were you able to find a setting for α that removes the tones and does not distort the underlying audio signal? What value of α did you think worked best for this audio signal? Keep in mind that there is a subjective aspect to this so your answer may not agree with others.
6. In regards to Figure 5, can you identify where the tones were added to the audio signal? Is it obvious that they have been (completely) removed after processing?
7. In regards to Figure 6, can you identify the tone frequencies in the frequency domain? What is their shape? Do the tones show up at the proper discrete frequencies? Are they removed after application of your designed filters?
8. Overall, what are your conclusions as to how effective the notch filters are at removing the tones from each signal while preserving the underlying signal? Do you have any suggestions on how we might be able to improve upon this filter?
4