Vous êtes sur la page 1sur 11

Lab 7

Filter banks

0. Preface
Filter banks are very important because several books have been written about them. Actually, many books have been written about filter banks because of how important they are. A filter bank is not a place where one earns interest on filters. Instead, a filter bank is simply any set of filters in parallel. Filter banks provide ways to work with signals in numerous ways. One might want to decompose a signal into a set of bandpass signals, each of which can be processed separately and perhaps added back together at a later time. This is done in MPEG-1, layer 3 (MP3), for instance. In this lab, the last lab of the quarter, you will explore filter banks. Answer all problems in all sections. There is a little present at the end, but dont look until you finish the lab.

1. My First Filterbank

Figure 1: A simple two-channel filter bank In this part of the lab you will explore a simple two-channel FIR filter bank; and in particular a simple quadrature mirror filter bank (QMF). Consider the system shown in Figure 1, where: Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

H 0 (z) =

1 1 (1+ z1 ) , H1 (z) = (1 z1 ) . 2 2

(1)

1.1 Plot the magnitude responses (not dB) of each of these filters on the same graph over normalized frequency (0-0.5). Include your plot with each curve labeled. Obviously one of the filters is a lowpass, and the other is a highpass. These two filters are special in that they are power complementarytheir squared magnitudes sums to a constant over all frequencies. Now lets create a signal to send through this filter bank. 1.2 Create the following random signal:
9 Ak cos( k n + k ), 0 n < 511 x[n] = k= 0 , 0 else

(2)

where Ak ~ unif[0,1] , k , k ~ unif[0,2 ) . (This means each Ak is drawn from a uniform random distribution between 0 and 1 (help rand), and the same with k and k , except over 0 and 2 .) (Note too that Ak , k , and k do not depend on n .) Plot a realization of this random signal. Also plot the

normalized magnitude dB frequency content of x[n] windowed by a Hann window (length-512) using a 1024-point DFT. Limit your dB range to [-60, 0]. (Think of the sampling rate as 2 and plot the frequency content versus normalized frequency [0, 0.5].) My realization is shown in Figure 2. (Your realization should not look exactly like mine, for it is a random signal!) Include your plot and code.

Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

Figure 2: A realization (top) of the random signal (2), and its frequency content found using a 512-length Hann window and 1,024-point DFT (bottom). 1.3 Now pass your random signal through the two-channel filter bank (1). Plot each output signal on two plots. From these time-domain signals can you see the difference in frequency content, i.e., that one is a highpass signal and the other a lowpass signal? Include your code and plot in the lab report. 1.4 This two-channel filter bank is special in that if you sum the outputs of the two channels and divide by

2 you can retrieve the original signal exactly. Verify

this by plotting your original signal against the scaled sum of the twochannels. Plot just the first hundred samples. Include your veriferific plot. Now consider the system shown in Figure 3, with H0 and H1 as given in (1). Why would you want to do such a thing, downsample that is? In splitting our input into two separate channels, we are in effect doubling the amount of data. We can maintain the data-rate by downsampling the output of each filter by 2. Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

Figure 3: A simple two-channel filter bank with downsampling 1.5 Do you have any concerns about this system using the filters given by (1)? Do you think we can get the original signal back? What might prohibit us from doing so? 1.6 As in 1.2 and 1.3, plot the normalized dB 1024-point DFT of the input and both outputs of the system shown in Figure 3 for the random signal (2). Use the Hann window again for each signal. See Figure 4 for guidance. Include your code and plot.

Figure 4: (Top) the frequency content of the random input to the system in Figure 3. (Middle) the frequency content of the output from the upper path. (Bottom) the frequency content of the output from the lower path. 1.7 Provide some interpretation of your figure in 1.6. For instance, how do the components in the output of the two channels correspond to the components in the original input? (Hint: this question is worth some large points.) Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

You probably wont believe me when I say that even though we have extreme aliasing occurring, we can get our original signal back exactly! Such is the magic of QMFs, OMFG.

Figure 5: A simple two-channel filter bank with downsampling followed by upsampling 1.8 Consider the system shown in Figure 5. As in 1.7, plot the frequency content of this system for your random signal, and the frequency content of the outputs of both channels. Include your plot, but not your code. (Please use
upsample

to upsample.)

Now that we have images appearing in the frequency content of the upsampled signals we need to filter to remove them to get our original signal back. To this end consider the system shown in Figure 6 with:

G0 (z) =

1 1 (1+ z1 ) , G1 (z) = (1+ z1 ) . 2 2

(3)

Figure 6: A simple two-channel filter bank with downsampling followed by upsampling and finally filtering. 1.9 As in 1.8, plot the frequency content of the input as well as the output of the two channels in the system shown in Figure 6 with your random signal, as well the frequency content of the sum of the two outputs (four plots in total.) Include your plot and code. The frequency content of the sum should be exactly the same as the frequency content of the input. Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

So what have we learned here? We can break a signal into two signals that overlap in the frequency domain, downsample them to preserve the data rate, send those pieces across a channel, and them reconstruct the original exactly with no aliasing. We could have done the same with two brickwall filtersi.e., ideal lowpass and highpass filters. But those filters require many, many coefficients. Here we were able to get perfect reconstruction and alias cancellation using two very simple filters that greatly overlap in their frequency response. This is only just the beginning. You can now consider breaking a signal into hundreds of channels that overlap in the frequency domain, process and code each one separatelyfor instance allocating more bits to regions that are more importantand finally sending that information through a structure that will at least provide alias cancellation. This is in fact what is done in MP3. Yay!

2. Modeling Your Cochlea. What? Modeling Your Cochlea


If you have never thought about how impressive the human ear (Figure 7) is, then perhaps it is time you think real hard about it.

Figure 7: The ear is an incredible organ, especially when growing on the back of a mouse I cannot in the space provided explain how it works (nor how you grow one on the back of a mouse); but in this section you will learn about the amazing filter bank you have in your head: the cochlea. The what? The cochlea, seen in Figure 8, is basically the stage where sound that has entered your outer ear and been transmitted through the ossicles (the smallest bones in your entire body) is converted to electrical impulses that travel to the brain via the auditory nerve. Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

Figure 8: The cochlea (labeled) resembles the well-known French hors doeuvre, escargot, but it isnt nearly as tasty with garlic butter Once the ossicles affect the cochlea, a traveling wave works its way down the basilar membrane, which runs through the center of the fluid-filled cochlea. This membrane has a non-linear transmission characteristic where low frequencies travel further down the basilar membrane than higher frequencies, as diagrammed in Figure 9.

Figure 9: Approximate areas of resonance along the basilar membrane, with frequencies shown in Hertz. Low frequency energy is not transmitted well where the membrane is thin. Instead it travels down to the end where the membrane is wider. Hair cells on the basilar membrane are grouped into what is called stereocilia (Figure 10), and these are connected to nerve cells. As the basilar membrane vibrates particular hair cells bend and transmit pulses along the auditory nerve to Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

the brain. From there much less is known about what happens and how the brain assimilates all this information into a coherent auditory picture. Fantastic!!!

Figure 10: Scanning electron microscope images of a cross-section of the cochlea (left), and stereocilia (right), both waiting to be abused by your next visit to a barn dance, or whatever you young people do these days One of the models of the cochlea that has been proposed is that of a filter bank! In fact, celebrated scientist Hermann Ludwig Ferdinand von Helmholtz (18211894) (Figure 11) proposed this idea in the late 19th centurythough without using the word filter bank, or its German equivalent zerlegensiesignalinfrequenzen bank. Knowing the frequency selectivity of the basilar membrane, it isnt too much of a stretch to think of our ear as a filter bank. To explore this idea you will use a black-box approach.

Figure 11: The young Hermann Ludwig Ferdinand von Helmholtz (18211894) as the smart ass he really was Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

2.1 Download from the class website the three MATLAB scripts: ERBFilterBank.m, ERBSpace.m, and MakeERBFilters.m. These programs create a filter bank model of the cochlea, proposed by two people named Patterson and Holdworth. (My friend Malcolm Slaney wrote this code, so I dont really understand it.) Run the following code and include the resulting plot in your report.
Fs = 40000; % Humans typically cant hear above 20 kHz numChannels = 20; lowFreq = 20; % this is the lowest frequency a human can hear N = 4096; [fcoefs] = MakeERBFilters(Fs,numChannels,lowFreq); h = ERBFilterBank([1 zeros(1,N-1)], fcoefs); f = figure('Position',[500 300 700 600],'MenuBar','none', ... 'Units','Normalized'); set(f,'PaperPosition',[0.25 1.5 8 6]); left = 0.09; top = 0.09; width = 0.88; height = 0.88; axes('position', [left top width height],'FontSize',14); freqScale = (0:N-1)/N*Fs; plot(freqScale./1000,20*log10(abs(fft(h'))),'k'); axis([0 Fs/2000 -60 1]) xlabel('Frequency (kHz)','FontSize',14); ylabel('Filter Response (dB)','FontSize',14); grid on;

2.2 Observing that each filter in this filter bank has a sharp resonance about some frequency, what kind of filters are these: IIR or FIR? Now you are going to run a musical signal through this cochlear filterbank and inspect the energy that comes out of each one. 2.3 Run the following code and tell me exactly what the code is doing. Include the final image in your lab report. (Hint: the most important parts are lines 2025. Focus on those.) (Hint: you will need the file PDQBach.wav as well.)
01: 02: 04: 05: 07: 08: 10: 11: 12: 13: [x,Fs] = wavread('PDQBach.wav'); x = x(1:Fs*1); numChannels = 20; lowFreq = 20; [fcoefs]=MakeERBFilters(Fs,numChannels,lowFreq); xout = ERBFilterBank(x, fcoefs); t = [0:numChannels:length(xout)-1]./Fs; f = figure('Position',[500 300 600 600], ... 'Units','Normalized'); set(f,'PaperPosition',[0.25 1.5 8 8]);

Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks


14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 31: left = 0.07; top = 0.09; width = 0.88; height = 0.88; axes('position', [left top width height],'FontSize',14); hold on; linestyle = {'-','--','-.'}; for j=1:size(xout,1) c = max(xout(j,:),0); c = filter(1,[1 -0.99],c); c = c(1:numChannels:end); plot(t,c+2*(j-1),'k','LineStyle',linestyle{mod(j,3)+1}); end set(gca,'YTick',[0:2:2*size(xout,1)-1]); set(gca,'YTickLabel',[0:j-1]); axis([0 1 -0.5 numChannels*2+5]); ylabel('Filter Number','FontSize',14); grid on;

10

The graph you just created is an illustration of the how 20-channel cochlear model resonates to the sound input. Filter number 0 corresponds to point B in Figure 9, and the highest frequency filter shown in the figure you created in 2.1. Filter number 19 corresponds to point A in Figure 9, or the lowest frequency filter. 2.4 Now increase the number of channels to 100 and find the response of the model to the first two seconds of the same music file. Include your plot. Make sure you change the axis limits to reflect that 2 seconds are being analyzed. 2.5 Now try the following using the results of 2.4, with your headphones on:
for j=50:size(xout,1) sound(xout(j,:),Fs); pause(2); end

What is the above code doing? Discuss what you hear. 2.6 Discuss one way you could use the filter bank model of the cochlea for audio compression. Congratulations! You have made it to the end of the lab portion of ECE 158!!! There are so many memories. We laughed and cried, together. There are so many people I would like to thank: Dr. Gibson, for giving me free reign over designing the labs; my wife for all the support; my parents of course; and finally, the students for all the helpful hints, including the unanimous Could you make the labs a bit shorter? To every student I present the following: Copyright 2006 Bob L. Sturm

ECE 158 Lab 7: Filter Banks

11

Copyright 2006 Bob L. Sturm

Vous aimerez peut-être aussi