Vous êtes sur la page 1sur 16

Handout 12

ELEN133/233E/COEN201E: Spring 17
5/6/2017

ELEN133/233E/COEN201E: HW #6 (120 points) DUE FRI MAY 12, 2017 at 11:59PM

QUIZ PREP:

Quiz #3 will be on Monday, May 8th and will cover HW5. Quiz #4 will be the following week on May
15th and will cover this HW.

Problems (graded for correctness):

1. (8 points) Download and experiment with fft_freqz_explanation.m (a MATLAB file that has
been provided to help provide understanding regarding the output of fft and freqz).
a. (0 points) Experiment with different sampling_freq values and different cosine_freq
values. Play with having a cosine_freq value that violates the Nyquist rate to see the
aliasing demonstrated. Getting comfort with this will contribute to a more solid
understanding of what MATLAB is doing and how to manipulate it to give you what
you want. You get no points for doing this, but it is highly recommended.
b. (5 points) Write an expression for the values of f (in Hertz) that comprise the x-axis in
the bottom subplot of Figure 2. These frequencies should be in terms of N, the
sampling frequency ( ) and some integer k that ranges from 1 to N. (Take care if
you need to decrement k to be correct in your expression.)

SOLUTION: The far left frequency should be , so, for k=1, our expression needs to equal
2

. If we made N+1 steps, we know wed make it to , so, the step size is .
2 2


Thus, frequency(k) = + ( 1) for k ranging from 1 to N where k=1 represents the
2
far left tick mark.

Now, lets double check a few key points to make sure:



k=1 should be the far left frequency and plugging k=1 into the expression yields 2 CHECK!

= should be the last frequency before 0 and should, thus, be negative <step size> or .
2

Plugging in = yields CHECK.
2

Plugging in = + 1 should get our frequency to 0 and it does: CHECK!
2

Finally, plugging in = should get us to one <step size> shy of or and, it does.
2 2
CHECK!

For those that assumed that k should match n the far left tick mark would be associated with
N/2 instead of 1. Thus, the above expression would become:

Thus, frequency(k) = + ( + 2 ) for k ranging from /2 (/2) 1
2
where = /2 represents the far left tick mark.

c. (3 points) Verify that your expression is correct by setting the sampling frequency to
10 and using 128 points. What is the 10th frequency value from the far left? Verify
this by running fft_freqz_explanation.m with these values and use the data cursor to
determine the x-axis value for the 10th point from the far left.

SOLUTION:
Zooming in on the bottom plot and using the data cursor to determine the 10th point from the far

left, we see that the frequency is -4.2969 Hz. Using our expression, we have: 2 + ( 1)
So, plugging in k=10, and = 10, and N=128 we get:

10 10 5 45
(10) = + (10 1) = 5 + 9 = 5 + = 4.2969 .
2 128 64 64

If you had an equation above for = 64 63, youd have to use = 55 for this.

2. (15 points) Cyclic Prefix, Overlap-Add and Overlap-Save


For the following parts you use x=[1 4 -2 5 6 1 -4 1 -3 11 2 5 3 1 -2 4 1 9] and
h=[4 3 3].
a. (3 points) What is the cyclic prefix that you would append to the front of x if your
goal was to obtain the circular convolution of x and h through the cyclic prefix
method?

SOLUTION: Here, the length of the longer sequence is 18 and, the length of the shorter
sequence, M, is 3. For the cyclic prefix method, we take the last M-1 samples of x[n] and
append it to the front. So, for this, the cyclic prefix is simply the last two terms [1 9]. Taking the
center 18 terms of the linear convolution of [1 9 x] and h yields the circular convolution. This
can be verified in MATLAB.

b. (6 points) If you were to use the Overlap-Add method with N=6 and, assume that you
would calculate each sub-convolution by taking the DFT of each sequence,
multiplying the DFTs in the frequency domain and then taking the inverse DFT.
i. (3 points) What is the length of the DFTs that would be used throughout this
procedure? Meaning, what length would you have to zero-pad the sub-
sequences (and h) to in order to perform the requested convolutions according
to the procedure as described in the lecture notes?
ii. (3 points) How many of these DFTs and inverse DFTs would be computed
throughout this whole Overlap-Add procedure?

SOLUTION: The Overlap-Add method has one break the longer sequence into length-N chunks
and perform a linear convolution with the shorter sequence, h. In this case, N=6, so the linear
convolution would be of a length-6 sequence with a length-3 sequence. We are told to perform
the linear convolution using the DFT method. Thus, we must zero pad each sequence to the
length of the linear convolution. In this case, that length is 6+3-1 = 8. So, the answer to (i) is 8.
To answer (ii), we must simply consider what occurs throughout this process. We break the
length-18 sequence into THREE length-6 chunks. So, to perform the three required linear
convolutions, we take two length-8 DFTs and one length-8 inverse DFT. Note, however, that
one of the DFTs (the one for h) only has to be done once. So, we actually do one for each chunk
of x (3), one for h (1) and the three inverse DFTs. So, 4 forward DFTs and 3 inverse DFTs. If
you answered, 6 forward DFTs and 3 inverse DFTs, that is close but, it doesnt take advantage
of the fact that you only have to take the DFT of h once (it doesnt change).

c. (6 points) Now assume that you are going to use the Overlap-Save method with N=6
and, again, assume that all sub-convolutions would be taken by finding the DFT of
the sequences involved, multiplying them in the frequency domain, and taking the
inverse DFT.
i. (3 points) How many subsequences would x be broken into before the last
point of x appeared at least once in a chunk. In other words, using the
breakdown on slide 23 of Lecture Notes 10, how many x_m are formed before
all the points of x have appeared in at least one chunk?
ii. (3 points) What is the length of the DFTs that would be used throughout this
procedure? Meaning, what length would you have to zero-pad the sub-
sequences (and h) to in order to perform the requested convolutions according
to the procedure as described in the lecture notes?

SOLUTION: According to the lecture notes, the first chunk is going to go from n=0 to 5 (length-
6). Then, the next chunk will start at N-M+1 which is 6-3+1 = 4. So, it would go from n=4 to 9.
This pattern would continue with the next chunk going from n=8 to n=13. The fourth chunk
would go from n=12 to 17. n=17 is the last sample of the sequence. So, the answer to this
question is four. Four [] are formed before each sample of [] appear at least once.

In this, we are asked to perform length-N circular convolutions. Thus, h would be zero-padded
to length-6. So, you would NOT have to zero pad the chunks of x, and you would zero-pad h[n]
to length-6. The answer to (ii) is 6.

3. (21 points) MATLAB understanding


Manipulate the files provided specifically, my_linconv.m, my_circconv.m and
my_cp_conv.m by reading through the code and finding the seven TASKS. Each task asks
you to replace the word ANSWER with an appropriate piece of code that will cause the
function to work as expected. Your submission for this should simply be the list of
ANSWERS.

SOLUTIONS:
ANSWER1: conv_length=x_length+h_length-1;
ANSWER2: new_x = [x zeros(1,conv_length-x_length)];
OR
ANSWER2: new_x = [x zeros(1,h_length-1)];

ANSWER3: new_h = [h zeros(1,conv_length-h_length)];


OR
ANSWER3: new_h = [h zeros(1,x_length-1)];
ANSWER4: h = [h zeros(1,x_length-h_length)];
ANSWER5: x = [x zeros(1,h_length-x_length)];

ANSWER6: new_x = [x(x_length-h_length+2:x_length) x];


ANSWER7: new_h = [h(h_length-x_length+2:h_length) h];

When you are done, run my_linconv(x,h), my_cp_conv(x,h), my_overlapadd(x,h,6) and


my_overlapsave(x,h,6) and verify that all give you as expected by comparing them. Also
Note that I added zeroes to the front and back of x inside the code of my_overlapsave.m so
that the full convolution would appear so, you can ignore the leading and trailing zeroes in
the result.

SOLUTION: Note, I rounded the result to get rid of the unnecessary decimal places.

>> round(my_linconv(x,h))

4 19 7 26 33 37 5 -5 -21 38 32 59 33 28 4 13 10 51 30 27

>> round(my_circconv(x,h))

ans =

34 46 7 26 33 37 5 -5 -21 38 32 59 33 28 4 13 10 51

>> round(my_cp_conv(x,h))

ans =

34 46 7 26 33 37 5 -5 -21 38 32 59 33 28 4 13 10 51

>> round(my_overlapadd(x,h,6))

ans =

4 19 7 26 33 37 5 -5 -21 38 32 59 33 28 4 13 10 51 30 27

>> round(my_overlapsave(x,h,6))

ans =
4 19 7 26 33 37 5 -5 -21 38 32 59 33 28 4 13 10 51 30 27

All answers are as expected.

4. (15 points) DFT Properties: Assume x[n]=[1 2 3 4 5 6]. And, X(k) is the DFT of x[n].
a. (5 points) Using duality, determine the DFT(DFT(x[n])) in terms of a generic x[n].
Apply that to provide the DFT(DFT(x[n])) for the x[n] provided above.

SOLUTION:
Here, DFT(DFT(x[n])) = DFT(X[n]) (this means, take the DFT of x[n], which is X[k] replace
the variable k with n, and take the DFT again) which, according to the property sheet is:
[< > ]. So, we take the circular time reversal of x[n] and multiply it by N.

Thus, for our specific example, [< > ] = [1 6 5 4 3 2] and, our final DFT(DFT(x[n]))
would equal this times N, or, in this case, 6. So, we end up with: [6 36 30 24 18 12].

b. (5 points) Prove the circular time shift property as shown in the table provided in the
lecture notes.

SOLUTION: The circular time shift property finds an expression for [< 0 > ]. Lets go
back to the definition of the DFT:
1

[ ] = [] 2
=0


2
So, the DFT of [< 0 > ] would be: 1
=0 [< 0 > ]

Performing a variable replacement, we can express this as:


10
(+0 )
[< > ] 2
=0

We can pull out the constant exponential (the one that doesnt depend on m):
10
0
2 [< > ] 2
=0

Given the periodicity, all values from m=0 to N-1 get covered, so, we can replace the right side
with G[k].
0
Thus, the desired DFT is: 2 [] which is the same as: 0 [].

c. (5 points) Using the circular time-shifting property, determine the DFT([4 5 6 1 2 3])
in terms of X[k]. In other words, dont calculate X(k), but, instead, determine the
point by point mulitpliers that are needed to adjust X(k) to determine this new DFT.

SOLUTION: Here, we shifted to the left or the right by 3 (note, it doesnt matter). So, using the
expression from the previous part (i.e. by applying the circular shift property), we find DFT([4 5
3
6 1 2 3]) to be 6 3 []. Calculating 6 3 , we expand it to 2 6 = which equals 1
for even k and -1 for odd k. Thus, the multipliers are [1 -1 1 -1 1 -1] and they get multiplied to
the six samples of X[k].

5. (16 points) Find the Z transform, (), for the following sequences x[n]. What is the region
of convergence for each?
a. [] = []

SOLUTION:


() = [] = = ( 1 )
= =0 =0
As we have seen in previous summation reductions, this reduces to:

1 ( 1 ) 1
() = 1
=
1 1 1

This is the region of convergence: |z| > |a|. The above reduction only occurs if |z|>|a|.

This can also be viewed as: () = . This has a zero at z=0 and a pole at z=a.

b. [] = [ 2]

SOLUTION:


() = [ 2] = = ( 1 )
= =2 =2

Again, our summation reductions are useful here and this reduces to:

( 1 )2 ( 1 ) ( 1 )2
() = =
1 1 1 1

This also has a region of convergence: |z| > |a|. The above reduction only occurs if |z|>|a|.

2 2 2 2
This can also be viewed as: () = 1 1 = 2 = (). This has no zeros. It has poles at
z=0 and z=a.

c. [] = 2 []

SOLUTION:

2 2 2 ( 1 )
() = [] = =
= =0 =0

From here, we can see that this is identical to part (a), with a factor of 2 in front. Thus,
2 2
() = =
1 1

The ROC, zeros and poles are identical to part a.

d. [] = [] [ 4]

SOLUTION:
3

() = ( [] [ 4]) =
= =0
This reduces to:

1 4
() =
1 1
OR

4 1
() =
3 ( 1)

The region of convergence here is |z|>0.


This transform has three poles at z=0, one pole at z=1. It also has four zeros recall as described
in lecture that we are looking for something that, when raised to the fourth power, equals 1. This
2 3
is: 4 for k=0,1,2 and 3 thus: the four zeros are at: 1, 2 , , 2 1, -j, -1 and j.
Note that the zero and the pole that occur at z=1 cancel each other out.

6. (10 points) Find the Z transform of [] = [] + [] where |a| > |b| . What is the
region of convergence? Identify the poles and zeros of X(z) when A = B = 1. Show a
pole/zero plot for A = B = 1, a = 0.75, and b=0.5.

SOLUTION:
Using the results from #5, and that fact that the Z-transform is linear, we can find X(z) by finding
the Z-transform of each of the two parts.

[] transforms to: = with a ROC of |z|>|a|
1 1
and

[] transforms to: 1 = with a ROC of |z|>|b|
1

()+()
So, the Z-transform of x[n] is () = + = ()()
and, since |a|>|b|, the ROC is

limited by the greater and is |z|>|a|.
2 + 2 (2(+))
If A=B=1, then we have: ()()
= ()()
This has zeros at 0 and (a+b)/2. This has
poles at a and b.

Here is a pole/zero plot for A=B=1, a=0.75, b=0.5:

7. (12 points) Find the transfer function, H(z), for the systems defined by the following
difference equations. Find the poles and zeros of H(z) and show a pole/zero plot. Sketch the
frequency response.
a. [] = [] [ 2]

SOLUTION:
Taking the Z-transform of both sides yields:
() = () 2 ()
Solving for the transfer function, H(z), we get:

()
() = = 1 2
()

1 2 2 1
This can be viewed as =
1 2

This has two zeros, at = 1 and = 1.


This also has two poles both at z=0.

Here is the pole/zero plot:


Here is the plot of the frequency response:

Given what was discussed in class, Id expect the sketch to show peaks at = /2 and zeroes
at = 0 , ,

b. [] = 0.75[ 1] 0.125[ 2] + [] + 4[ 2]

SOLUTION:
Similar to part a, we take the Z-transform of both sides and obtain:
() = 0.75 1 () 0.125 2 () + () + 4 2 ()

Rearranging yields:

() 0.75 1 () + 0.125 2 () = () + 4 2 ()
Solving for the transfer function, H(z), we get:

() 1 + 4 2
() = =
() 1 0.75 1 + 0.125 2
We can rewrite H(z) as:

2 + 4 2 + 4
() = 2 =
0.75 + 0.125 ( 1)( 1)
2 4

The poles can be obviously seen at z=0.5 and z=0.25.


The zeros occur at z=2j and -2j.

Here is the pole/zero plot:

And, here is the frequency response:


Again, I dont expect an exact match of this but, there should be a maximum at = 0 with
minimums a bit to the left of = /2 and a bit to the right of = +/2.

8. (14 points) An LTI system is the series combination of two lower order filters defined by:
[] = [] + [ 1] + [ 2]

[] = [] + [ 1]

a. (6 points) Find the transfer function for each filter individually. Show the pole/zero
diagram and use MATLABs freqz to plot the frequency response of each.

SOLUTION:
The first filter looks like this:

() 2 + + 1
() = = 1 + 1 + 2 =
() 2

Two poles appear at z=0. The zeros can be calculated using the quadratic equation:
1 1 4 3
= = 0.5 = 0.5 0.866
2 2

The pole/zero plot looks like this:


And, the frequency response looks like this:

The frequency plot above was generated with this code:


>> [H,w]=freqz([1 1 1],[1],1024,'whole');
>> plot(w-pi,fftshift(abs(H)))
>> xlabel('w');

For what it is worth, the pole/zero plot above it was generated with this line:
>> zplane([1 1 1],[1])

The second filter is similar:


() + 1
() = = 1 + 1 =
()

One pole appears at = 0, one zero appears at = 1.

The pole/zero plot looks like this:


And, the frequency response looks like this:

b. (4 points) Show the pole zero diagram for the series combination of the two filters
and justify your answer.

SOLUTION: The series combination is the product of the two filters. So, we get:
(1 + 1 + 2 )(1 + 1 ) = 1 + 1 + 2 + 1 + 2 + 3 = 1 + 2 1 + 2 2 + 3
OR
3 + 2 2 + 2 + 1
3

This results in 3 poles at z=0 and zeroes at: 0, 0.5 0.866 (note, these were the zeros
from the two transfer functions that were multiplied to create this transfer function).

So, here is the pole/zero diagram:


c. (4 points) Use MATLAB to plot the frequency response of the series combination of
the two filters. How does this compare to the frequency response of the first filter
alone?

Finally, here is the frequency response plot:

This filter is a better low pass filter than the first filter as it suppresses some higher frequencies
and has a sharper transition from the suppressed frequencies to the passed frequencies.

9. (9 points) Design a filter to cancel 12Hz in an input sampled at 50Hz. Determine the zeroes
required, the resulting transfer function and the resulting difference equation.

SOLUTION:
This follows the example in the Lecture Notes. In this problem, we have:
12 24 12
= 50, 0 = 12 0 = 2 0 = 2 = =
50 50 25
To achieve this, we can put two zeroes at 0, i.e. 1 = 0 and 2 = 0
12 12

25 25
2 2 cos
12
+1
(1 )(2 ) 12
Thus, () = 2
= = 25
= 1 2 cos 1 + 2
2 2 25
1 0.1256 1 + 2

From here, we can create the difference equation:

()
= 1 0.1256 1 + 2
()
So, () = ()(1 0.1256 1 + 2 )
Taking the inverse Z-transform of both sides yields.

[] = [] 0.1256 [ 1] + [ 2]

It wasnt asked for, but the following MATLAB code is yields the pole/zero plot and frequency
response plot below.
>> zplane([1 -0.1256 1],[1])
>> [H,w]=freqz([1 -0.1256 1],[1],1024,'whole');
>> plot(w-pi,fftshift(abs(H)))
>> xlabel('w');
>> scusetup
>> plot((w-pi)*50/(2*pi),fftshift(abs(H)))
>> xlabel('f');
This shows that we achieved a null at the desired frequency of f=12Hz.

Vous aimerez peut-être aussi