Você está na página 1de 9

Solutions to Matlab problem Homework 3 EEE407/591 Spring 2009

1. Matlab problem on Sampling.


Consider 3 continuous time (CT) signals corresponding to the sinusoids:
x1 (t) = cos (2π10t), x2 (t) = cos (2π60t), and x3 (t) = cos (2π90t).

(a) We want to sample the signals using sampling period T = 0.0025 s.


(a.1) Nyquist frequency: fs /2 = 200 Hz.
(a.2) Sampling frequency: fs = 1/T = 1/0.0025 = 400 Hz.
Using the plot Matlab command, we plot each signal in time, assuming that each signal has
256 samples. Note that the time (horizontal) axis is correctly labeled in in seconds.
Matlab sample code:

clear; clf;
N=256; Ts=0.0025; Duration=N*Ts; f_s=1/Ts; t=linspace(0,Duration,N);

s_1=cos(2*pi*10*t);
figure(1); subplot(311); plot(t, s_1);
xlabel(’time, seconds’); ylabel(’amplitude’);
title(’Cosine signal with frequency 10 Hz’);

s_2=cos(2*pi*60*t);
figure(1); subplot(312); plot(t, s_2);
xlabel(’time, seconds’); ylabel(’amplitude’);
title(’Cosine signal with frequency 60 Hz’);

s_3=cos(2*pi*90*t);
figure(1); subplot(313); plot(t, s_3);
xlabel(’time, seconds’); ylabel(’amplitude’);
title(’Cosine signal with frequency 90 Hz’);

1
Cosine signal with frequency 10 Hz
1

amplitude
0

−1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
time, seconds
Cosine signal with frequency 60 Hz
1
amplitude

−1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
time, seconds
Cosine signal with frequency 90 Hz
1
amplitude

−1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
time, seconds

(b) Using the fft command, we obtain and plot the magnitude of the Fourier transform (FT) of each
signal. The frequency f is in Hz (1/second). Recall that f = ω/2π Hz.

Nf=256; f=linspace(-fs/2, fs/2, Nf);

S1=abs(fftshift(fft(s_1,Nf)));
figure(2); subplot(311); plot(f,S1);
xlabel(’frequency, Hz’); ylabel(’magnitude’);
title(’FT of 10 Hz cosine signal’);

S2=abs(fftshift(fft(s_2,Nf)));
figure(2); subplot(312); plot(f,S2);
xlabel(’frequency, Hz’); ylabel(’magnitude’);
title(’FT of 60 Hz cosine signal’);

S3=abs(fftshift(fft(s_3,Nf)));
figure(2); subplot(313); plot(f,S3);
xlabel(’frequency, Hz’); ylabel(’magnitude’);
title(’FT of 90 Hz cosine signal’);

2
FT of 10 Hz cosine signal
100

magnitude
50

0
−200 −150 −100 −50 0 50 100 150 200
frequency, Hz
FT of 60 Hz cosine signal
100
magnitude

50

0
−200 −150 −100 −50 0 50 100 150 200
frequency, Hz
FT of 90 Hz cosine signal
150
magnitude

100

50

0
−200 −150 −100 −50 0 50 100 150 200
frequency, Hz

(b.1) For each sinusoid, the FT would be given as

cos Ω0 t ↔ π [δ(Ω − Ω0 ) + δ(Ω + Ω0 )]

(b.2) Note that the peaks are at the correct frequencies, as expected, since no aliasing has occured:
the maximum frequency (90 Hz) is less than the Nyquist (200 Hz).
(b.3) Note that the answer in part (b.1) does not quite agree with our Matlab plots. We would
get the answer in part (b.1) only if the sinusoids were not windowed. Instead, each signal term is
windowed by a rectangular window g(t) whose duration is N Ts . The corresponding FT is a sinc
function convolved with the two Dirac functions; thus, we obtain two sinc functions, still with
peaks occuring at the correct sinusoidal frequencies.
(c) After changing the sampling period to T = 0.02 s, the Nyquist is now fs /2 = 1/(2T ) = 25 Hz.
It is smaller than the frequency of second and third sinusoids. So, even though the first sinusoid
does not alias, the second and third ones do alias, and their aliasing is such that they appear at
the same frequency as the first sinuoid.

3
Cosine signal with frequency 10 Hz
1

amplitude
0

−1
0 1 2 3 4 5 6
time, seconds
Cosine signal with frequency 60 Hz
1
amplitude

−1
0 1 2 3 4 5 6
time, seconds
Cosine signal with frequency 90 Hz
1
amplitude

−1
0 1 2 3 4 5 6
time, seconds

FT of 10 Hz cosine signal
100
magnitude

50

0
−30 −20 −10 0 10 20 30
frequency, Hz
FT of 60 Hz cosine signal
100
magnitude

50

0
−30 −20 −10 0 10 20 30
frequency, Hz
FT of 90 Hz cosine signal
100
magnitude

50

0
−30 −20 −10 0 10 20 30
frequency, Hz

4
2. Matlab problem on linear time-invariant (LTI) system transfer functions and pole-zero plots.
Consider the following causal, stable LTI system whose transfer function is given by:
0.26z 2 − 0.53 z + 0.26
H(z) =
z 2 + 1.2 z + 0.52
(a) Poles and zeros of the system.
PM
The Matlab command roots can be used to find the roots of the polynomial D(z) = m=0 αm z m .
Specifically, roots(coeff) provides the roots of D(z) provided the vector coeff is used to define
the polynomial coefficients as coeff= [αM αM−1 . . . α0 ] in Matlab.
Using this Matlab command, we find the poles and zeros of H(z) by first defining the coefficient
vectors num and den for the numerator and denominator, respectively.
num=[0.26 -0.53 0.26]; den=[1.00 1.2 0.52];
poles= roots(den); zeros= roots(num);
(b) Transfer function and pole-zero plots.
The Matlab function tf can be used to create the discrete-time transfer function given the
coefficient vectors of the numerator and the denominator, num and den. The title command is
used to add a title to the plots.
The Matlab function pzmap is then used to obtain a pole-zero plot in the z-plane. You can use
help pzmap (or doc pzmap) to obtain additional information on the use of this function.
Hz=tf(num,den,-1); zgrid;
figure(1); pzmap(Hz); title(’Pole-zero plot of H(z)’);

Pole−zero plot of H(z)

0.8

0.6

0.4
Imaginary Axis

0.2

−0.2

−0.4

−0.6

−0.8

−1
−1 −0.5 0 0.5 1 1.5
Real Axis

(c) Magnitude response.


The Matlab function freqz can be used to obtain the frequency response H(ejω ) of the LTI
system. Recall that the frequency response is the transfer function H(z) evaluated on the unit
circle, z = ejω ). Given that the sampling frequency is fs = 10, 000 Hz,
(c.1) compute the frequency response from 0 to fs using 1000 samples (see the sample code below);
(c.2) compute the magnitude response |H(ejω )| using the Matlab function abs to obtain Hmagn;
(c.3) plot the magnitude response, making sure the frequency axis is correctly labeled in Hz,
and the frequency values range from −fs /2 to fs /2 (you can obtain a frequency vector using the
Matlab command linspace. Note that f is in Hz (or one over second) where is ω = 2πf is
in radians per second. The fftshift command shifts the zero-frequency to the center of the
spectrum so that we obtain the frequency response from −fs /2 to fs /2.

5
samples=1000; fs=10000; % sampling frequency
H=freqz(num,den,samples,’whole’,fs);
H_magn=abs(fftshift(H)); % magnitude response
freq=linspace(-fs/2,fs/2,samples);
figure(2); subplot(211); plot(freq,H_magn); title(’Magnitude response’);
xlabel(’Frequency, Hz’); ylabel(’magnitude’);

(d) Phase response.


The phase response of the system is obtained using the Matlab function angle.
H_phase=(180/pi)*(unwrap(angle(H))); % phase response
figure(2); subplot(212); plot(freq,H_phase);
title(’Phase response’); xlabel(’Frequency, Hz’); ylabel(’Phase’);

Magnitude response
4

3
magnitude

0
−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 5000
Frequency, Hz
Phase response
200

100
Phase

−100

−200
−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 5000
Frequency, Hz

(e) This is an IIR filter since it has poles that are not at the origin of the z-plane. The poles indicate
that the system has feedback and thus infinite response. This is a highpass filter.
(f) Impulse response.
To find the impulse response h[n], we first perform partial fraction expansion
A B
H(z) = + .
1 − p1 z −1 1 − p1 z −1
using the Matlab function residue and then we use z-transform (ZT) pair tables to find h[n].
[r p k]= residue(num,den)
r =
-0.4210 - 0.7875i
-0.4210 + 0.7875i

p =
-0.6000 + 0.4000i
-0.6000 - 0.4000i

k =
0.2600

6
From this, we obtain roots for z, not z −1 . Thus,

(−0.4210 − j0.7875) (−0.4210 + j0.7875)


H(z) = 0.26 + +
z − (−0.6 + j0.4) z − (−0.6 − j0.4)
(−0.4210 − j0.7875)z −1 (−0.4210 + j0.7875)z −1
= 0.26 + + .
1 − (−0.6 + j0.4)z −1 1 − (−0.6 − j0.4)z −1

Thus, using ZT tables, since the LTI system is causal, it corresponds to a right-handed sequence,

h[n] = 0.26 δ[n] + (−0.4210 − j0.7875)(−0.6 + j0.4)n−1 u[n − 1]


+(−0.4210 + j0.7875)(−0.6 − j0.4)n−1 u[n − 1]

(g) Consider another LTI system whose impulse response is given by g[n] = 1.5n ejπn h[n] = (1.5ejπ )n h[n] =
(−1.5)n h[n].
i. We can use ZT properties to find the transfer function G(z) of this system as G(z) =
H(−z/1.5).
To express G(z) in three different ways: (i) with numerator and denominator as polynomial
functions
numg= [0.26/(1.5^2) 0.53/1.5 0.26]
numg =

0.1156 0.3533 0.2600

deng=[1/(1.5^2) -1.2/1.5 0.52]


deng=

0.4444 -0.8000 0.5200

Using this information, we can write G(z) as

0.1156 z 2 + 0.3533 z + 0.26


G(z) =
0.4444 z 2 − 0.8 z + 0.52
(ii) with numerator and denominator as products of zeros and poles, respectively,
polesg= roots(deng)
polesg =

0.9000 + 0.6000i
0.9000 - 0.6000i

zerosg= roots(numg)
zerosg =

-1.8244
-1.2333

Using this information, we can write G(z) as

(z + 1.8244)(z + 1.2333) (1 + 1.8244z −1)(1 + 1.2333z −1)


G(z) = =
(z − (0.9 + j0.6))(z − (0.9 − j0.6)) (1 − (0.9 + j0.6)z −1 )(1 − (0.9 − j0.6)z −1 )

(iii) To write G(z) as a linear combination of poles,

7
[rg pg kg] = residue(numg, deng)

rg =

0.6315 - 1.1812i
0.6315 + 1.1812i

pg =

0.9000 + 0.6000i
0.9000 - 0.6000i

kg =

0.2600

Using the above, we can write,

(0.6315 − j1.1812)z −1 (0.6315 + j1.1812)z −1


G(z) = 0.26 + + .
1 − (0.9 + j0.6)z −1 1 − (0.9 − j0.6)z −1

ii. We already found the poles and zeros of this system. In order to plot them in the z-plane,
Gz= tf(numg,deng,-1); zgrid;
figure(3); pzmap(Gz); title(’Pole-Zero Plot for G(z)’);
Pole−Zero Plot for G(z)

0.8

0.6

0.4
Imaginary Axis

0.2

−0.2

−0.4

−0.6

−0.8

−1
−2 −1.5 −1 −0.5 0 0.5 1
Real Axis

iii. Assuming the same sampling frequency and the same number of frequency samples as for
H(ejω ), we can find the frequency response of G(ejω ).
samples= 1000; fs= 10000; %sampling frequency
G=freqz(numg,deng,samples,’whole’,fs);
G_magn=abs(fftshift(G)); % magnitude response
G_phase=(180/pi)*(unwrap(angle(G))); % phase response

freq=linspace(-fs/2,fs/2,samples);
figure(5); subplot(211); plot(freq,G_magn);
title(’Magnitude response’);
xlabel(’Frequency, Hz’); ylabel(’magnitude’);
subplot(212); plot(freq,G_phase);
title(’Phase response’);
xlabel(’Frequency, Hz’); ylabel(’Phase’);

8
Magnitude response
20

15

magnitude
10

0
−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 5000
Frequency, Hz
Phase response
200

Phase 100

−100

−200
−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 5000
Frequency, Hz

iv. This is an IIR filter as before (filter still has poles) but now we have a lowpass filter.
v. Comment on whether this filter is causal or stable. The filter is causal, but it is not stable
since ROC does not include unit circle, |z| > |0.9 + j0.6| = 1.0817.

Você também pode gostar