Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
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.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)’);
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
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’);
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,
Thus, using ZT tables, since the LTI system is causal, it corresponds to a right-handed sequence,
(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.9000 + 0.6000i
0.9000 - 0.6000i
zerosg= roots(numg)
zerosg =
-1.8244
-1.2333
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
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.