Signals Exp2
Signals Exp2
No: 2
DISCRETE TIME FOURIER TRANSFORM
Date: 13.2.2024
𝝅
1. Consider the discrete time sequence 𝒙[𝒏] = 𝐜𝐨𝐬 ( 𝟒 𝒏), 𝟎 ≤ 𝒏 ≤ 𝟗𝟗
a. Determine and plot the magnitude and phase response using DTFT formula for
−𝟐𝝅 ≤ 𝝎 ≤ 𝟐𝝅. Investigate its periodicity of the signal in frequency domain.
b. Determine and plot the magnitude and phase response using freqz command in
MATLAB.
Manual Calculation
Code
clc
clear all
close all
n = 0:99;
w = linspace(-2*pi,2*pi,1000);
pnts = length(w);
x = cos((pi/4)*n);
output = zeros(pnts);
for k=1:pnts
csw = exp(-1i*w(k)*n);
output(k) = sum(x.*csw)/length(n);
end
a = 2*abs(output);
p = angle(output);
[freqz_a,freqz_p] = freqz(x,1,1000,"whole");
freqz_p = freqz_p-pi;
subplot(221)
plot(w,a)
grid on;
title("DTFT Amplitude Spectrum")
xlabel("Angular frequency (w)"), ylabel("Amplitude")
subplot(222)
plot(w,p)
grid on;
title("DTFT Phase Spectrum")
xlabel("Angular frequency (w)"), ylabel("Phase")
subplot(223)
plot(freqz_p,abs(fftshift(freqz_a)))
grid on;
title("Freqz Amplitude Spectrum")
xlabel("Angular frequency (w)"), ylabel("Amplitude")
subplot(224)
plot(freqz_p,angle(fftshift(freqz_a)))
grid on;
title("Freqz Phase Spectrum")
xlabel("Angular frequency (w)"), ylabel("Phase")
Output
𝟏, −𝑵 ≤ 𝒏 ≤ 𝑵
2. A symmetric rectangular pulse is given by 𝒙[𝒏] = { ,
𝟎, 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
clc
clear all
close all
n = -100:1:100;
N = 15;
x = zeros(size(n));
for l=1:length(n)
if((l<=101+N)&&(l>=101-N))
x(l) = 1;
end
end
w = linspace(-pi,pi,201);
output = zeros(size(x));
for k=1:length(x)
csw = exp(-1i*w(k)*n);
output(k) = sum(x.*csw)/length(n);
end
a = 2*abs(output);
p = angle(output);
a = 3*a;
subplot(211)
stem(n,x)
grid on;
title("N=15 Signal")
xlabel("Time (n)"), ylabel("Amplitude")
subplot(212)
plot(w,a)
grid on;
title("N=15 Amplitude Spectrum")
xlabel("Angular frequency (w)"), ylabel("Amplitude")
Output
𝟏, 𝟎≤𝒏≤𝑵−𝟏
3. A symmetric rectangular pulse is given by 𝒙[𝒏] = { ,
𝟎, 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
Manual Calculation
Code
clc
clear all
close all
n = 0:1:100;
N = 2;
x = zeros(size(n));
for l=1:length(n)
if((l<=N-1)&&(l>=1))
x(l) = 1;
end
end
w = linspace(-pi,pi,101);
output = zeros(size(x));
for k=1:length(x)
csw = exp(-1i*w(k)*n);
output(k) = sum(x.*csw)/length(n);
end
a = 2*abs(output);
p = angle(output);
a = 50*a;
subplot(211)
stem(n,x)
grid on;
title("N=2 Signal")
xlabel("Time (n)"), ylabel("Amplitude")
subplot(212)
plot(w,a)
grid on;
title("N=2 Amplitude Spectrum")
xlabel("Angular frequency (w)"), ylabel("Amplitude")
Output
𝟏, 𝟎 ≤ 𝒏 ≤ 𝑵 − 𝟏
4. Generate A symmetric rectangular pulse is given by 𝒙[𝒏] = { ,
𝟎, 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
a. Determine the DTFT of the sequence y[n]= x[n]*x[n], for 𝑵 = 𝟐, 𝟓, 𝟏𝟎, 𝟏𝟓.
b. Scale the DTFT so that 𝒀(𝒆𝒋𝟎 ) = 𝟏 and plot the normalized magnitude
response of the DTFT over [−𝝅, 𝝅].
c. Study magnitude response plots and comment on their behavior as a function
of 𝑵.
Code
clc
clear all
close all
n = 0:1:100;
N = 15;
x = zeros(size(n));
for l=1:length(n)
if((l<=N-1)&&(l>=1))
x(l) = 1;
end
end
w = linspace(-pi,pi,101);
output = zeros(size(x));
for k=1:length(x)
csw = exp(-1i*w(k)*n);
output(k) = sum(x.*csw)/length(n);
end
y = output.*output;
a = 2*abs(y);
p = angle(y);
a = 25*a;
subplot(211)
stem(n,x)
grid on;
title("N=15 Signal")
xlabel("Time (n)"), ylabel("Amplitude")
subplot(212)
plot(w,a)
grid on;
title("N=15 Amplitude Spectrum")
xlabel("Angular frequency (w)"), ylabel("Amplitude")
Output
5. Determine H ( z ) , H ( e j ) and plots its pole-zero diagram magnitude and phase
responses using MATALB. Identify the nature of the system by observing the frequency
response of the system.
1 4
i) y (n) = x (n − m)
5 m =0
1 1
ii) y n = x n − x n − 1
2 2
1 1
iii) y n = x n + x n − 1
2 2
i)
Manual Calculation
Code
clc;
clear all;
close all;
b = (1/5) * [1 1 1 1 1];
a = [1];
subplot(3,1,3)
zplane(b, a);
title('Pole-Zero Diagram');
subplot(3,1,1)
plot(w, abs(H));
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response');
subplot(3,1,2)
plot(w, angle(H));
xlabel('Frequency');
ylabel('Phase (radians)');
title('Phase Response');
Output
ii)
Manual Calculation
Code
clc;
clear all;
close all;
b = [1 -1] / sqrt(2);
a = [1];
subplot(3,1,1)
zplane(b, a);
title('Pole-Zero Diagram');
[H, w] = freqz(b, a, 100);
subplot(3,1,2)
plot(w, abs(H));
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response');
subplot(3,1,3)
plot(w, angle(H));
xlabel('Frequency');
ylabel('Phase (radians)');
title('Phase Response');
Output
iii)
Manual Calculation
Code
clc;
clear all;
close all;
b = [1 1] / sqrt(2);
a = [1];
subplot(311)
zplane(b, a);
title('Pole-Zero Diagram');
subplot(312)
plot(w, abs(H));
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response');
subplot(313)
plot(w, angle(H));
xlabel('Frequency');
ylabel('Phase (radians)');
title('Phase Response');
Output
Result
Thus the discrete time Fourier transform has been executed and verified successfully.