Lab 10: Octave Band Filtering
Pre-Lab and Warm-Up: You should read at least the Pre-Lab and Warm-up sections of this lab assignment
and go over all exercises in the Pre-Lab section before going to your assigned lab session.
Verification: The Warm-up section of each lab must be completed during your assigned Lab time and
the steps marked Instructor Verification must also be signed off during the lab time. One of the laboratory
instructors must verify the appropriate steps by signing on the Instructor Verification line. When you have
completed a step that requires verification, simply demonstrate the step to the TA or instructor. Turn in the
completed verification sheet to your TA when you leave the lab.
Lab Report: It is only necessary to turn in a report on Sections 4 and 5 with graphs and explanations. You
are asked to label the axes of your plots and include a title for every plot. In order to keep track of plots,
include your plot inlined within your report. If you are unsure about what is expected, ask the TA who will
grade your report.
1 Introduction
This lab introduces a practical application where we attempt to extract information from sinusoidal signals—
in this case, piano notes. Bandpass FIR filters can be used to extract the information encoded in the wave-
forms. The goal of this lab is to design and implement several bandpass FIR filters in M ATLAB, and use the
filtered outputs to determine automatically which note is being played. However, since there are 88 keys on
the piano, we will only require the system to figure out which octave the note is in, not the exact note. In
the experiments of this lab, you will use firfilt(), or conv(), to implement filters and freqz() to
obtain the filter’s frequency response.1 As a result, you should learn how to characterize a filter by knowing
how it reacts to different frequency components in the input.
1.1 Frequency Response of FIR Filters
ˆ . Often a
The output or response of a filter for a complex sinusoid input, ej !ˆ n , depends on the frequency, !
filter is described solely by how it affects different frequencies—this is called the frequency response. The
frequency response of a general FIR linear time-invariant system is
M
X
H(ej !ˆ ) = bk e j!
ˆk
(1)
k=0
M ATLAB has a built-in function for computing the frequency response of a discrete-time LTI system. The
following M ATLAB statements show how to use freqz to compute and plot the magnitude (absolute value)
ˆ in the range ⇡ !
of the frequency response of an L-point averaging system2 as a function of ! ˆ ⇡:
1
If you are working at home and do not have the function freqz.m, there is a substitute available in the SP First toolbox
called freekz.m.
2
The filter length L is equal to M + 1.
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7. 1
Prentice Hall, Upper Saddle River, NJ 07458. c 2003 Pearson Education, Inc.
, bb = ones(1,L)/L; %-- Filter Coefficients
ww = -pi:(pi/100):pi; %-- omega hat frequency axis
HH = freqz(bb, 1, ww); %<--freekz.m is an alternative
subplot(2,1,1);
plot(ww, abs(HH))
subplot(2,1,2);
plot(ww, angle(HH))
xlabel(’Normalized Radian Frequency’)
We will always use capital HH for the frequency response. For FIR filters, the second argument of freqz(
, 1, ) must always be equal to 1. The frequency vector ww should cover the interval ⇡ !ˆ ⇡ for
ˆ , and its spacing must be fine enough to give a smooth curve for H(ej !ˆ ).
!
2 Background and Pre-Lab
2.1 Piano Notes
A piano keyboard consists of 88 keys grouped into octaves. Each octave contains 12 notes, the notes in one
octave being twice the frequency of the notes in the next lower octave.
OCTAVE
41 43
C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4 B4 C5 D5 E5 F5 G5 A5 B5
28 30 32 33 35 37 39 40 42 44 45 47 49 51 52 54 56 57 59 61 63
Middle-C A-440
Figure 1: Layout of a piano keyboard. Key numbers are shaded. The notation C4 means the C-key in the
fourth octave.
Frequencies of the notes are defined by setting the frequency of one note and referring all other frequen-
cies to that note. The reference note is the A above middle-C, which is usually called A-440 (or A4 ) because
its frequency is 440 Hz. Each octave contains 12 notes (5 black keys and 7 white) and the ratio between the
frequencies of the notes is constant between successive notes. As a result, this ratio must be 21/12 . Since
middle C is 9 keys below A-440, its frequency is approximately 261 Hz. Consult Chapter 3 for more details.
If we want to produce a system capable of writing music directly from a recorded signal x(t), we need
to analyze the frequency content of the signal. One way to do this analysis is to use a set of bandpass FIR
filters, each one having its passband designed for one note on the keyboard. This would require a very large
number of filters. Another way to do the analysis would be to use a two stage approach. First, we would
use a set of bandpass FIR filters where each passband would pass the frequencies in one octave. Then these
“octave filters” would be followed by more precise bandpass filters (BPFs) that would determine which key
inside the octave is being played. The work in this lab will be to produce a working set of “octave filters.”
McClellan, Schafer, and Yoder, Signal Processing First, ISBN 0-13-065562-7. 2
Prentice Hall, Upper Saddle River, NJ 07458. c 2003 Pearson Education, Inc.