[go: up one dir, main page]

0% found this document useful (0 votes)
8 views11 pages

sns_lab_8

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 11

Department of Electrical Engineering and

Computer Science

Faculty Member: Dr. Salman Ghafoor Dated: 31/10/2022

Semester: 5th Section: BEE 12C

EE-232: Signals and Systems

Lab 8: Discrete Time Fourier Series

Group Members

PLO4 – PLO5 - PLO8 - PLO9 -


CLO3 CLO3 CLO4 CLO4
Name Reg. No Viva / Analysis Modern Ethics
Quiz / Lab of data Tool and
Performa in Lab Usage Safety
nce Report

5 Marks 5 Marks 5 Marks 5 Marks

Danial Ahmad 331388

Muhammad Umer 345834

Syeda Fatima
334379
Zahra

EE-232: Signals and Systems Page 1


1 Table of Contents
2 Introduction to Properties of Systems ....................................................................................... 3
2.1 Objectives ............................................................................................................................... 3
2.2 Equipment ............................................................................................................................... 3
2.3 Lab Instructions ...................................................................................................................... 3
3 Lab Tasks ..................................................................................................................................... 4
3.1 Lab Task 1 & 2 (Reconstruction done in a single code) ......................................................... 4
3.1.1 Fourier Series of a DT Sinusoid ...................................................................................... 4
3.1.2 Fourier Series of a DT Rectangular Wave ...................................................................... 7
4 Conclusion .................................................................................................................................. 11

EE-232: Signals and Systems Page 2


2 Introduction to Properties of Systems
2.1 Objectives

The goal of this laboratory is to be able to calculate the Fourier series of discrete time signals and plot
the real part of the spectrum / Fourier series coefficients.

• Fourier Series Calculation of Discrete Time Signals


• Inverse Fourier Series Calculation given Fourier Series Coefficients

2.2 Equipment

Software
• MATLAB

2.3 Lab Instructions

All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:

• Lab objectives
• MATLAB codes
• Results (Graphs/Tables) duly commented and discussed
• Conclusion

EE-232: Signals and Systems Page 3


3 Lab Tasks
3.1 Lab Task 1 & 2 (Reconstruction done in a single code)

3.1.1 Fourier Series of a DT Sinusoid

Write a function that will generate a single Discrete Time (DT) sinusoid 𝑥[𝑛] = 𝐴 sin[𝑤𝑛] =
𝑓
𝐴 sin [2𝜋 𝐹 𝑛]. 𝐴 = 3, 𝑓 = 500Hz and sampling frequency 𝐹𝑠 = 8000Hz.
𝑠

function [] = discreteSine(A, f, Fs)


N = Fs / f;

n_definition = 0:1:N;
x = A * sin(2 * pi * (f / Fs) * n_definition);

subplot(2, 2, 1)
stem(n_definition, x, 'filled')
title('Original Signal x[n]')
xlabel('n')
grid

n_obv = 0:1:15;
x_n = A * sin(2 * pi * (f / Fs) * n_obv);
length(n_obv);

ak = zeros(1, 41);
length(ak);

for k = -20:1:20
for n = 0:1:15
ak(k + 21) = ak(k + 21) + (x_n(n + 1) ...
* (exp(-1i * k * (2 * pi * (1 / N)) * n))) / N;
end
end

k_axis = -20:20;
length(k_axis);

mag_ak = abs(ak);

tol = 1e-6;

for k = -20:1:20
if abs(ak(k + 21)) < tol
ak(k + 21) = 0;
end
end

phase_ak = angle(ak);

% subplot(2, 2, 2)
% stem(k_axis, mag_ak);

EE-232: Signals and Systems Page 4


% title('Magnitude Spectrum');
% xlabel('k')
% grid
%
% subplot(2, 2, 3)
% stem(k_axis, phase_ak);
% title('Phase Spectrum');
% xlabel('k')
% grid

frequency_radians = zeros(1, 41);

for k = -20:20
frequency_radians(k + 21) = 2 * pi * (k / N);
end

frequency_Hertz = zeros(1, 41);

for k = -20:20
frequency_Hertz(k + 21) = (k / N);
end

subplot(2,2,2)
stem(frequency_radians, mag_ak)
title('Magnitude of a_{k}')
xlabel('Frequency (in Radians)')
grid

subplot(2,2,3)
stem(frequency_Hertz, mag_ak)
title('Magnitude of a_{k}')
xlabel('Frequency (in Hertz)')
grid

x_recon = zeros(1, N + 1);

for n = 0:N
for k = -7:1:8
x_recon(n + 1) = x_recon(n + 1) + (ak(k + 21) ...
.* (exp(1i * k * (2 * pi * (1 / N)) * n)));
end
end

n_axis = 0:1:N;
subplot(2, 2, 4)
stem(n_axis, x_recon, 'filled')
title('Reconstructed Signal x[n]')
xlabel('n')
grid

EE-232: Signals and Systems Page 5


1. Determine the period, 𝑁, of this sinusoid? Determine the DT Fourier series coefficients and plot
the magnitude and phase of the DT Fourier series coefficients.

2𝜋𝑚 𝐹𝑠
𝑃𝑒𝑟𝑖𝑜𝑑 𝑁 = = = 16
𝜔 𝑓

2𝜋
1
2. For calculating the DT Fourier series coefficients use 𝑎𝑘 = 𝑁 ∑𝑛=<𝑁> 𝑥[𝑛]𝑒 −𝑗𝑘( 𝑁 )𝑛 . It will return
the value of the 𝑘 th DTFS coefficient. For remaining coefficients, you may use a loop to iterate
over values of 𝑘. What will be the range of 𝑘?

𝑅𝑎𝑛𝑔𝑒 𝑘 = −20: 20

3. You must make two plots of the coefficients against frequency axis instead of 𝑘. One plot should
be against frequency in radians. Other plot should be against frequency in Hz.

EE-232: Signals and Systems Page 6


2𝜋
4. 𝑘-th coefficient corresponds to frequency 𝑘. Determine the range in radians of the distinct
𝑁
frequency components?

𝑅𝑎𝑛𝑔𝑒 𝑓 (𝑖𝑛 𝐻𝑒𝑟𝑡𝑧) = 0.3926

𝑅𝑎𝑛𝑔𝑒 𝑓 (𝑖𝑛 𝑅𝑎𝑑𝑖𝑎𝑛𝑠) = 0.0625

5. What is relation between frequency in Hz and frequency in radians?

𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 (𝑖𝑛 𝑟𝑎𝑑𝑖𝑎𝑛𝑠) = 2𝜋 × 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 (𝑖𝑛 ℎ𝑒𝑟𝑡𝑧)

3.1.2 Fourier Series of a DT Rectangular Wave

Assume a rectangular wave as shown below. Using a similar approach outlined in the previous task,
obtain the DTFS representation of the rectangular wave. Plot the magnitude and phase of the Fourier
series coefficients with appropriate axes, labels, and titles.

function [] = discreteSquare()
N = 10; % Period N

n_definition = 1:1:N;
x = [0 0 0 0 0 1 1 1 1 1]; % 1 - 10
subplot(2, 2, 1)
stem(n_definition, x, 'filled');
title('Original Function x[n]')
xlabel('n');
axis([1 N -0.25 1.25]);

ak = zeros(1, 35);
length(ak);

for k = -17:1:17
for n = 1:1:N
ak(k + 18) = ak(k + 18) + (x(n) ...
* (exp(-1i * k * (2 * pi * (1 / N)) * n))) / N;

EE-232: Signals and Systems Page 7


end
end

k_axis = -17:1:17;
length(k_axis);

mag_ak = abs(ak);

tol = 1e-6;

for k = -17:1:17
if abs(ak(k + 18)) < tol
ak(k + 18) = 0;
end
end

phase_ak = phase(ak);

subplot(2, 2, 2)
stem(k_axis, mag_ak);
title('Magnitude Spectrum');
xlabel('k')
grid

subplot(2, 2, 3)
stem(k_axis, phase_ak);
title('Phase Spectrum');
xlabel('k')
grid

x_recon = zeros(1, N + 1);

for n = 1:N
for k = 1:1:N
x_recon(n + 1) = x_recon(n + 1) + (ak(k + 18) ...
.* (exp(1i * k * (2 * pi * (1 / N)) * n)));
end
end

n_axis = 0:1:N;
subplot(2, 2, 4)
stem(n_axis, x_recon, 'filled')
title('Reconstructed Signal x[n]')
xlabel('n')
grid

1. Determine the period, 𝑁, of this sinosoid? Determine the DT Fourier series coefficients and plot
the magnitude and phase of the DT Fourier series coefficients.

𝑃𝑒𝑟𝑖𝑜𝑑 𝑁 = 10

EE-232: Signals and Systems Page 8


2𝜋
1 −𝑗𝑘( )𝑛
2. For calculating the DT Fourier series coefficients use 𝑎𝑘 = 𝑁 ∑𝑛=<𝑁> 𝑥[𝑛]𝑒 𝑁 . It will return
the value of the 𝑘 th DTFS coefficient. For remaining coefficients, you may use a loop to iterate
over values of 𝑘. What will be the range of 𝑘?

𝑅𝑎𝑛𝑔𝑒 𝑘 = −17: 17

3. You must make two plots of the coefficients against frequency axis instead of 𝑘.

2𝜋
4. 𝑘-th coefficient corresponds to frequency 𝑘. Determine the range in radians of the distinct
𝑁
frequency components?

𝑅𝑎𝑛𝑔𝑒 𝑓 (𝑖𝑛 𝐻𝑒𝑟𝑡𝑧) = 0.3926

𝑅𝑎𝑛𝑔𝑒 𝑓 (𝑖𝑛 𝑅𝑎𝑑𝑖𝑎𝑛𝑠) = 0.0625

EE-232: Signals and Systems Page 9


5. What is relation between frequency in Hz and frequency in radians?

𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 (𝑖𝑛 𝑟𝑎𝑑𝑖𝑎𝑛𝑠) = 2𝜋 × 𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 (𝑖𝑛 ℎ𝑒𝑟𝑡𝑧)

Assume a rectangular wave as shown below. Using a similar approach outlined in the previous task,
obtain the DTFS representation of the rectangular wave. Plot the magnitude and phase of the DT
Fourier series coefficients with appropriate axes, labels, and titles. What differences can you note from
the frequency representation of previous waveform.

Keeping all the previous code the same, except now, original function is changed to:
x = [0 0 0 0 0 0 0 0 1 1]; % 1 - 10

EE-232: Signals and Systems Page 10


Differences: Phase spectrum contains more non-zero values for distinct Fourier series coefficients and
the magnitude spectrum comprises a greater number of coefficients, but of less magnitude. (𝐴 = 0.2)

4 Conclusion
After the conduct of this lab, we have determined that MATLAB can be effectively used for
determining Fourier series of Discrete Time signals and any number of coefficients can be obtained.
However, a given DTFS only has a finite number of coefficients equal to the period of the signal. Also,
we proved the 2π relation between the frequency in Hertz and radians by studying and observing
MATLAB output plots.

EE-232: Signals and Systems Page 11

You might also like