You are on page 1of 12

Laboratory 7 - Fourier Series

Representation of Continuous-time
Periodic Signals
Signals and Systems
Department of Computer Engineering
College of Computer and Information Sciences
King Saud University
Student Name:

Student ID:

Instructions

1. Read this document before coming to the laboratory.

2. Print this document and bring it with you to the laboratory.

3. Mobile phones are not allowed.

4. Do not copy paste the code - type it.

5. Use only the front side of the sheets.

Marking Scheme

Task Points Obtained


1 30
2 40
3 30
Total 100

1
Laboratory 7 - Fourier Series
Representation of Continuous-time
Periodic Signals
Contents
7.1 Fourier series - complex exponentials . . . . . . . . . . . . . . 3
7.2 Student Task 1 - Fourier series - sinusoidals . . . . . . . . . . 5
7.3 Fourier series - magnitude and phase . . . . . . . . . . . . . . 6
7.4 Student Task 2 - Magnitude and phase . . . . . . . . . . . . . 8
7.5 Periodic square wave . . . . . . . . . . . . . . . . . . . . . . . 9
7.6 Student Task 3 - Fourier series approximation . . . . . . . . . 12

2
7.1 Fourier series - complex exponentials
The Fourier series representation of a continuous-time periodic signal is a
set of harmonically related complex exponentials. Such a signal is given by
Equations 1.

1 1 1
x(t) = 1 + (ej2πt + e−j2πt ) + (ej4πt + e−j4πt ) + (ej6πt + e−j6πt ) (1)
4 2 3
Let us plot and see each of these harmonically related complex exponentials.
The first subplot of Figure 1 shows

x(t) = 1

the second shows

x(t) = 1 + 41 (ej2πt + e−j2πt )

the third subplot shows

x(t) = 1 + 14 (ej2πt + e−j2πt ) + 21 (ej4πt + e−j4πt )

and the last one shows

x(t) = 1 + 14 (ej2πt + e−j2πt ) + 21 (ej4πt + e−j4πt ) + 13 (ej6πt + e−j6πt )

for −2π ≤ t ≤ 2π.

The following code is used to generate x(t), shown in Figure 1.

clear all
close all
t=-2*pi:pi/100:2*pi;
ti=1:length(t);

x(ti)=1;
subplot(4,1,1), plot(t,x)
axis([-2*pi 2*pi 0 2])
xlabel('x(t)=1');

x(ti)=x(ti)+1/4*(exp(j*2*pi*t)+exp(j*-2*pi*t));
subplot(4,1,2), plot(t,x)
axis([-2*pi 2*pi 0 2]), ...
xlabel('x(t)=1+1/4(eˆ{j2\pit}+eˆ{-j2\pit})');

3
x(ti)=x(ti)+1/2*(exp(j*4*pi*t)+exp(j*-4*pi*t));
subplot(4,1,3), plot(t,x)
axis([-2*pi 2*pi -1 4])
xlabel('x(t)=1+1/4(eˆ{j2\pit}+eˆ{-j2\pit})+1/2(eˆ{j4\pit}+eˆ{-j4\pit})');

x(ti)=x(ti)+1/3*(exp(j*6*pi*t)+exp(j*-6*pi*t));
subplot(4,1,4), plot(t,x)
axis([-2*pi 2*pi -1 4]),
xlabel('x(t)=1+1/4(eˆ{j2\pit}+eˆ{-j2\pit})+1/2(eˆ{j4\pit}+eˆ{-j4\pit})
+1/3(eˆ{j6\pit}+eˆ{-j6\pit})');

Figure 1: Fourier series - complex exponentials

4
7.2 Student Task 1 - Fourier series - sinusoidals
Euler’s formula allows us to express x(t) given in Equation 1 as
1 2
x(t) = 1 + cos 2πt + cos 4πt + cos 6πt (2)
2 3
Task 1. Plot x(t) similar to the previous section using the sinusoidal rep-
resentation of x(t) given by Equation 2. Add appropriate labels and title.
Write the code, print and paste the figure here.

5
7.3 Fourier series - magnitude and phase
The Fourier series coefficients of x(t) represented in Equation 1 and Equation
2 are given by

a0 = 1
a1 = 14
a−1 = 14
a2 = 12
a−2 = 12
a3 = 13
a−3 = 13

The magnitude and phase of the Fourier series coefficients can be calculated
and plotted through the following code. Figure 2 shows the magnitude and
phase plot of the Fourier series coefficients corresponding to x(t) represented
in Equation 1 and Equation 2. Note that phase is 0 for all the Fourier series
coefficients as the Fourier series coefficients do not contain an imaginary part.

clear all
close all
a=[1/3 1/2 1/4 1 1/4 1/2 1/3];
for i=1:length(a)
magnitude a(i)=abs(a(i));
phase a(i)=angle(a(i));
end
k=-3:3;
subplot(2,1,1),
h1=stem(k,magnitude a,'-k','LineWidth',2);
axis([-4 4 0 1.1])
set(h1, 'Marker', 'none')
xlabel('k')
title(' | a k | ')
subplot(2,1,2),
h2=stem(k,phase a,'-k','LineWidth',2);
axis([-4 4 0 1.1])
set(h2, 'Marker', 'none')
xlabel('k')
title('\angle a k')

6
Figure 2: Fourier series - magnitude and phase

7
7.4 Student Task 2 - Magnitude and phase
For x1 (t) given in Equation 3
π
x1 (t) = 1 + sin 2πt + 2 cos 2πt + cos (4πt + ) (3)
4
The Fourier series coefficients are
a0 = 1
a1 = 1 − 12 j
a−1 =√1 + 12 j
2
a2 = 4√ (1 + j)
a−2 = 42 (1 − j)

Task 2. Calculate and plot the magnitude and phase of the Fourier series
coefficients corresponding to x1 (t). Add appropriate labels and title. Write
the code, print and paste the figure here.

8
7.5 Periodic square wave
Consider the periodic square wave, x(t), given by
(
−1, −1 ≤ t ≤ 0
x(t) =
1, 0 ≤ t ≤ 1
The Fourier series coefficients can be calculated from one period of the pe-
riodic square wave. One period of x(t) is generated through the following
code and shown in Figure 3. The fundamental period, T0 of x(t) is 2 and the
fundamental frequency, w0 = 2π T0
.

clear all
close all
syms t
t=0:0.01:2;
x=heaviside(t)-2*heaviside(t-1);
plot(t,x,'-k','LineWidth',2);
axis([0 2 -1.1 1.1])
xlabel('time t')
ylabel('x(t)')

Figure 3: Periodic square wave

We can also show more periods of the periodic square wave, just by repeating
the signal for the desired number of times. This is achieved through the

9
following code. The periodic square wave for 3 periods is shown in Figure 4.

clear all
close all
syms t
t=0:0.01:2;
x=heaviside(t)-2*heaviside(t-1);
xrep = repmat(x,1,3);
t2=linspace(0,6,length(xrep));
plot(t2,xrep,'-k','LineWidth',2);
axis([0 6 -1.1 1.1])
xlabel('time t')
ylabel('x(t)')

Here repmat repeats the x(t) 3 times and linspace generates equally spaced
points in between 0 and 6. The number of points is equal to the length of
the repeated signal, xrep.

Figure 4: Periodic square wave - repeated

The corresponding Fourier series coefficients can be calculated through Equa-


tion 4.
Z
1
ak = x(t)e−jkw0 t dt (4)
T T
We can now approximate the signal x(t) using the Fourier series coefficients
calculated using Equation 4. The approximation is calculated using Equation

10
5.

X
x(t) = ak ejkw0 t (5)
−∞

The approximation is calculated for using only 3 Fourier series coefficients -


k = −1 : 1. The approximation is plotted using the f plot, generally used to
plot functions. This approximation is shown in Figure 5.

clear all
close all
syms t
x=heaviside(t)-2*heaviside(t-1);
k=-1:1;
T 1=0;
T 0=2;
w 0=2*pi/T 0;
a k=(1/T 0)*int(x*exp(-j*k* w 0 *t),t,T 1,T 1+T 0); % Equation 4
x approx=sum(a k. *exp(j*k* w 0 *t)); % Equation 5
fplot(x approx,[0 6])
xlabel('time t')
title('Fourier Series Approximation')

Figure 5: Periodic square wave - Approximation

11
7.6 Student Task 3 - Fourier series approximation
Task 3. Approximate x(t) similar to the previous section using 11, 31 and
91 Fourier series coefficients. Add appropriate labels and title. Write the
code, print and paste the figure here. Comment on your results.

12

You might also like