digital signal processing

profileJasonGUa
Lab2.pdf

ELC 4351 DSP Lab 2: Filters and Filter Banks

Dr. Gravagne

Introduction

Digital filters are the heart of an astounding collection of modern technologies. A digital filter is simply a

difference equation; in the Z-domain, its transfer function can be represented as 𝐻(𝑧) =

𝑂𝑢𝑝𝑢𝑡(𝑧)/𝐼𝑛𝑝𝑢𝑡(𝑧). In essence, the purpose of a digital filter is to separate and isolate certain

frequencies (or “frequency bands”) in a signal. A filter bank consists of multiple filters doing frequency

isolation at the same time, so that a signal can be split into its various frequency bands and processed.

The figure below shows a type of filter bank designed to split an incoming signal into frequency bands,

process it, and then reconstruct it (or a near-copy of it).

(credit: National Instruments)

In the figure above, filters 𝐻𝑘(𝑧) and 𝐹𝑘(𝑧) are bandpass filters; they allow a certain range of

frequencies to pass – called the passband – and block all others. (In many cases, 𝐻𝑘 and 𝐹𝑘 are the same

filter or only have minor differences.) If we let 𝑧 = 𝑒𝑗2𝜋𝑓𝑛, we can sweep through values of f from -0.5

to 0.5 (or 0 to 1) and see the frequency response of a bandpass filter, like we did in a recent M/W class

meeting. An example is below.

On the “Analysis” side of the filter bank, the filter outputs are downsampled, so a signal 𝑥(𝑛) with N

samples is split into M signals 𝑣𝑘(𝑛) with only N/M samples each. This keeps the total number of

samples the same – and interestingly, no information is lost!

On the “Synthesis” side of the filter bank, the signals 𝑤𝑘(𝑛) are upsampled, filtered and summed. If

there is no processing unit, then the output 𝑦(𝑛) will be a perfect or near-perfect reconstruction of

𝑥(𝑛). That is what we’re doing in this lab.

y0[n]

y1[n]

yM-1[n]

The figure above shows a bandpass filter. It allows a narrow range of frequencies to pass through

(although bandpass filters can be wide too!). Its cutoff frequencies are 𝑓𝐿 and 𝑓𝐻, and its center

frequency is 𝑓𝐶, exactly in between the low and high cutoffs. A filter bank will use many of these, all with

different center frequencies.

Assignment

Download the file V.mat and h.mat and load them into your MATLAB workspace. You will see that V is a

matrix with 32 rows and h is 512-point vector. Each row of V consists of the signals 𝑣0(𝑛) through

𝑣31(𝑛) referring back to the filter bank figure. This means 𝑀 = 32; there are 32 filters in the bank. The

vector ℎ(𝑛) is the 512-point impulse response of a “prototype” bandpass filter.

Your job is to synthesize 𝑦(𝑛), which should be very close to the original 𝑥(𝑛) I used to create the

assignment. To do this, you will need to create filters 𝐹0(𝑧) through 𝐹31(𝑧), which in this case are simply

copies of 𝐻0(𝑧) through 𝐻31(𝑧) because we aren’t doing any processing in the middle. To get the

impulse responses of your 32 filters you’ll use the “modulation property” – detailed in this week’s

pencast! If ℎ(𝑛) is the impulse response of the prototype filter with a center frequency at 𝑓𝑐 = 0, then

ℎ𝑘(𝑛) = ℎ(𝑛)𝑐𝑜𝑠(2𝜋𝑓𝑘𝑛) is the impulse response of a filter with center frequency at 𝑓𝑘. We need 32

center frequencies uniformly distributed across the spectrum. If the low cutoff of each filter is at

1

2 × {0,

1

32 , …

31

32 } and the high cutoff is at

1

2 × {

1

32 ,

2

32 , …

32

32 } then the centers are at 𝑓𝑘 =

1

2

𝑘+ 1

2

32 for 𝑘 =

0 … 31.

Using the filters is easy. If we apply an input signal 𝑝(𝑛) to filter 𝐻(𝑧), the output of the filter is simply

𝑞(𝑛) = ℎ(𝑛) ∗ 𝑝(𝑛). Easy! One detail to observe though: If 𝑝(𝑛) is N samples, and ℎ(𝑛) has L samples,

then the output of a convolution of the two is N+L-1 samples. So we need to throw away some of the

output samples at the beginning and end. We should keep the ones from L/2 + 1 to L/2 + N. (So now

we’re back to having a filter output that is the same length as the input.)

So in summary: Take each row of V and upsample it by a factor of 32, as we did in M/W class time.

Create the 32 bandpass filters. Filter the 32 upsampled signals using convolution. Trim the beginning and

end of the results off (trim off the convolution artifacts). Sum up the results and play the output as an

audio signal with 𝐹𝑠 = 44100. [Hint: DO NOT USE MATLAB’S UPSAMPLE COMMAND; Matlab got too

cute with that so it does unexpected things.]

One final surprise! The first 10 rows of V are not in correct order! To sort out which signals are in which

row, you will need to compute the signal energies of each 𝑣𝑘. It is often true (but not always) that signal

energy decreases with increasing frequency. Use that fact to re-sort your first 10 rows: highest energy

first, then decreasing.

Deliverables

You will electronically submit a file named “filterbank.m” which has the first line

% ELC 4351 DSP Lab 2: Your Name

When I run the script, it should do these things:

First, display a 2 x 1 subplot array, complete with axis labels and titles, showing

1.) A plot of all 32 bandpass filters’ frequency response, magnitude vs frequency. From -0.5 to 0.5

on the frequency axis, absolute value on the magnitude axis. I recommend that you plot

frequency response using the FFT as we learned in class. (Don’t forget fftshift.)

2.) A stem plot of the 32 signal energies for each 𝑣𝑘(𝑛), dB vs. k. (In the correct order!) Since it’s a

measure of energy, we use 𝑑𝐵 = 10𝑙𝑜𝑔10(𝑒𝑛𝑒𝑟𝑔𝑦).

Next, print the answers to the following questions in the command window:

1.) If the original signal was sampled at 44100 samples/second, what is the approximate bandwidth

in Hz of each of your filters? (Plot one. Measure the bandwidth at about 0.8 magnitude, which is

roughly -3dB)

2.) In your filter frequency response plot, you will notice an odd artifact at 𝑓 = 0. Explain. (This

can be corrected with a more sophisticated filter modulation technique.)

3.) In an audio compression algorithm such as MP3, the “processing” in the middle of the filter bank

figure decides (among many things) how many bits to allocate to various frequency bands. More

bits = higher fidelity playback and less noise. Based on your energy stem plot, do you think all

frequency bands should be allocated the same number of bits? In general terms, what

frequency bands could reasonably be allocated more or fewer bits?

Third, your code should play back the recovered signal.

Optional: for fun, play back individual channels 𝑦𝑘(𝑛) to yourself. Is any single one of them enough to

recognize the original signal? That’s what a bandpass-filtered signal sounds like!

Read these instructions carefully – it will be easy to lose points by not following instructions exactly.

Final note: uploaded codes will be submitted to a plagiarism tool specifically for computer code. Write

yours from scratch and you won’t have to worry!