Вы находитесь на странице: 1из 6

EE 424, Lab 2.

Block Convolution We look at a technique known as block convolution, particularly useful for computing the discretetime convolution of a long data sequence with a short lter. In this case, it makes sense to break the long sequence into shorter blocks; these blocks are convolved with the lter, and the results of these block convolutions are combined to produce the same result as the single long convolution. We now outline a reason for applying block convolution. Algorithms and hardware for implementing nite-length convolutions make block convolution a particularly attractive approach. One example is fast Fourier transform (FFT) that will be discussed later in this course. In real-time applications, such as speech processing, this approach reduces the processing delay compared with the single long convolution. We break a long sequence x[n] of length L into M short blocks of length N ,
M 1

x[n] =
m=0

xm [n m N ]

where we have assumed that L = N M and that xm [n] = x[n + m N ], 0 n < N . 0, otherwise

Here, xm [n] is just the mth block of x[n], shifted so that it starts at n = 0. Our goal is to process each of these blocks independently by convolving each with a K-sample FIR lter, and then combining the lter outputs to produce the same result as a single, long convolution over the entire input x[n]. The single long convolution y[n] = x[n] h[n] has length L + K 1. The convolution of each N -sample block ym [n] = xm [n] h[n] has length N +K 1, which is longer than the original block. When we combine the blocks ym [n] to produce y[n], the blocks will overlap. Since convolution is a linear operation, we can simply add the overlapping segments. This approach is hence known as the overlap-and-add algorithm.

EE 424, Lab 2.

An example for K = 9, L = 128, and a block length of 32 is shown below:

EE 424, Lab 2.

Task 1. Determine how to combine the blocks ym [n] to produce the desired LTI system output y[n], and then implement it in a Matlab m-le. 1. To perform block convolution, we break x into N -sample blocks. There are then M of these blocks. We can do this in Matlab by changing the L-sample x vector into a matrix xm using Matlabs reshape command: >> xm = reshape(x,n,m); Note the transpose, which gives us the signal blocks along rows of the matrix. Then xm(4,:) is the fourth block of n samples of x. Generate a discrete-time square-wave function >> t = [0:255]/256; >> x = cos(2*pi*5*t)>0; and a lter function >> h = ones(1,12)/12; Plot the signal x and convolution of x and h. This is the function that we are trying to compute with the block-convolution m-le that you will write. Generate four 64-sample blocks as follows: >> xm = reshape(x,64,4); Filter the rst two blocks by convolving each with h and determine the overlap required so that the combination of the rst two blocks agree with the rst part of the full convolution.

EE 424, Lab 2.

For example, >> lf = 256+12-1; >> yb = zeros(1,lf); >> lb = 64+12-1; >> yb(1:lb) = conv(xm(1,:),h); >> yb((d+1):(d+lb)) = yb((d+1):(d+lb)) + conv(xm(2,:),h); where lf is the length of the full convolution, lb is the length of each ltered block, and d is the delay of the second ltered block relative to the rst, which you need to determine. Then, lb-d is the overlap between the two blocks. In general, what is the overlap if the lter length is K samples? 2. Write an m-le that does this for an arbitrary block size, given an input vector x and lter vector h. The function denition should look like >> function yb = oaconv(x,h,n) where n is the block size. Append zeros to the input to make its length a multiple of the block size, if needed. Test using the above square wave x and compare it with the full convolution. Task 2. We now use the convolution function that you have written to simulate the way you would test the frequency response of an analog system (such as a lter) that you are testing on the lab bench. You would generate an sinusoidal input that sweeps in frequency. On the bench you would do this using a ramp generator to drive a voltage-controlled oscillator. This would generate an input signal that has a linearly increasing frequency. Then, if you connect ramp generator as the x input to an oscilloscope and the output to the y input, the display would show the frequency response of the circuit.

EE 424, Lab 2.

In this case, we will take an impulse response of the system we are interested in, and convolve it with a signal that is linearly increasing in frequency. If the frequency is changing slowly relative to the length of the impulse response, the output is then the frequency response, corresponding to the frequency at that time. A signal with a linear frequency sweep in time is called a chirp. The phase of the signal is the integral of the instantaneous frequency:
t

(t) =
0

(s) ds.

If (t) = t, then
t t t

(t) =
0

(s) ds =
0

s ds =
0

s ds =

t2 2

which is quadratic in time. For this task, we are interested in the frequency response of a system from zero to the sampling frequency. For Matlab, audio waveforms are sampled at 8192 Hz, so one second of the chirp can be generated by >> t = [0:8191]/8192; >> y = cos(2*pi*4096*(t.*t)); At sample n, the instantaneous frequency of this waveform is n 1 Hz. (a) We rst convolve y with a simple lowpass lter, given by the window function of length K = 9: >> h = hamming(9); >> h = h/sum(h); Plot this using a stem plot to see what this window function looks like. This is closely related to the Hann window from the last lab, but has a slightly better frequency response.

EE 424, Lab 2.

Filter x with h, using your oaconv() m-le and 256 sample blocks. Play this: >> y = oaconv(x,h,256); >> sound(y, 8192); Compare this to the original sound. Does this make sense? Plot the absolute value of the signal as a function of time. For the time axis, recall that the input signal has a frequency that is linearly increasing with time. We can then relate the sample number to frequency by multiplying by 8192 Hz, >> plot(t*8192,abs(y)); What does this plot show? Is it consistent with what you heard? (b) Now take the window function and modulate it using the modulator system from handout #3. This multiplies h with the sequence (1)n . Show a stem plot of the modulated window. Filter the chirp signal and plot the response. Finally, listen to the sound the waveform produces. What type of lter is the modulated window?

Вам также может понравиться