0% found this document useful (0 votes)
48 views19 pages

Technological University of The Philippines: Manila

This document describes an experiment on Fourier series and Fourier transforms. The objectives are to gain understanding of Fourier analysis techniques and learn how to implement them in MATLAB. As preparation, students review MATLAB basics like vector manipulation and plotting complex numbers. The lab work involves using GUI tools in MATLAB to demonstrate properties of Fourier series for different waveforms like square and sawtooth waves. It also involves calculating the discrete Fourier transform of periodic signals using the FFT function and analyzing the magnitude and phase spectra.

Uploaded by

Lea Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views19 pages

Technological University of The Philippines: Manila

This document describes an experiment on Fourier series and Fourier transforms. The objectives are to gain understanding of Fourier analysis techniques and learn how to implement them in MATLAB. As preparation, students review MATLAB basics like vector manipulation and plotting complex numbers. The lab work involves using GUI tools in MATLAB to demonstrate properties of Fourier series for different waveforms like square and sawtooth waves. It also involves calculating the discrete Fourier transform of periodic signals using the FFT function and analyzing the magnitude and phase spectra.

Uploaded by

Lea Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

TECHNOLOGICAL UNIVERSITY OF THE

PHILIPPINES
Manila
COLLEGE OF ENGINEERING
Electronics Engineering Department

Experiment No. 2:

Fourier Series and Fourier Transform

Submitted By:

Submitted To:
Engr. Gilfred Allen Madrigal

Instructor
Experiment 2: Fourier Series and Fourier Transform

I. OBJECTIVES

Fourier analysis plays an important role in communication theory. The main objectives
of this experiment are:

1. To gain a good understanding and practice with Fourier series and Fourier Transform
techniques, and their applications in communication theory.

2. Learn how to implement Fourier analysis techniques using MATLAB.

II. Pre-Lab Work

You are expected to do the following tasks in preparation for this lab:

 MATLAB is a user-friendly, widely used software for numerical computations (as you
learned in EE207). You should have a quick review of the basic commands and syntax for
this software. The following exercises will also help in this regard.

Note: it is important to remember that MATLAB is vector oriented. That is, you are mainly
dealing with vectors (or matrices).

1. Consider the following code: Y=3+5j

a. How do you get MATLAB to compute the magnitude of the complex number Y?

Ans.

abs(y)

b. How do you get MATLAB to compute the phase of the complex number Y?

Ans.

angle(y)
2. Vector manipulations are very easy to do in MATLAB. Consider the following:

xx=[ones(1,4), [2:2:11], zeros(1,3)]

xx(3:7)

length(xx)

xx(2:2:length(xx))

Explain the result obtained from the last three lines of this code. Now, the vector xx contains 12
elements. Observe the result of the following assignment:

xx(3,7)=pi*(1:5)

Ans.

The result of indices 3 to 7 of the variable xx has been change from the values of pi, 2pi, 3pi,
4pi, and 5pi.

Now, write a statement that will replace the odd-indexed elements of xx with the constant
-77(1.e., xx(1), xx(3), etc.). Use vector indexing and vector replacement.

Ans.

Xx(1:2:length(xx))=77
Consider the following file, named example.m:

F=200;

tt=[0:1/(20*f):1];

z=exp(j*2*pi*f*tt);

subplot(211)

plot(real(z))

title('REAL PART OF z')

subplot(212)

plot(imag(z))

title('IMAGINARY OF z')

a) How do you execute the file from the MATLAB prompt?

Ans.

Just type in the prompt the title of the file which is example then it will automatically run.

b) Suppose the file name was "example.cat". Would it run? How should you change it to make
in MATLAB?

Ans.

No the file did not run. In order for the file to run we need to rechange it’s file name
extension to *.m

c) Assuming that the M-file runs, what do you expect the plots to look like? If you're not sure,
type in the code and run it.

Ans.

The plot will look like a sine wave because on the third line of the code this is the
exponential form of the complex number, and basically when if we want to transform it
back to polar form we will use the formula rcis(θ)
III. Lab Work

Part A: Fourier Series

1.) In MATLAB, go to the command window and type Fourier_series_demo.m. This will
bring up a Graphical User Interface (GUI) that can used to test and demonstrate many
concepts and properties of the Fourier series expansion.
 Try different types of functions, starting with the square wave, fully rectified sine,
sawtooth, etc. Run different examples while changing the fundamental frequency and
number of harmonics in the FS expansion. Report your observations. In particular, explain
why the Fourier series for the square and sawtooth waves require many more harmonics
than the rectified sine waves in order to get a close match between the FS and the original
function?

Ans

Based on the GUI of the Fourier Series Demo, the student observed that the synthesized
signal became almost the same with the square wave, and sawtooth wave when the student
add the coefficients or the harmonics for the Fourier series. On the other hand, for the
rectified waves the it took k = 5 in order to have a match between the functions.

 Consider the plots for amplitude and phase spectra. State what kind of symmetry is present
in each type of spectrum, and why? The plots also indicate the presence of FS terms with
"negative" frequencies! What's the interpretation of that? Are there really negative
frequencies? Explain.

Ans.

Based on the GUI of for magnitude spectrum of the Fourier series for the square wave, it
almost forms a bell curve. Additionally, there is no such thing as the negative frequency.
This negative frequency only indicates that the rotation vector is in the opposite direction of
the positive axis.

2.) Now, consider a periodic signal x(t). Compute and plot the discrete magnitude and phase

spectra of this signal given by x(t)=e (-t/2) where t Є [0.π]. For this, you need to use the
Fast Fourier (FFT) function in MATLAB (refer to the notes below for more details). For the
expansion of the signal x(t), the number of harmonics N0 to be used should be 32, the
period T0 is π, and the step size is t= T0 I N0. The output should be in two figure windows.
The first window should contain x(t) while the second window should contain both the
magnitude and phase spectra versus a vector of harmonics indices (for example, n). You
also need to include labels and titles in all plots. What can you observe from these plots?

Ans.
N = 32
t = [0:(pi/N):pi]
x = exp(-t/2)
Xn = fft(x,N)/N;
Xn = [conj(Xn(N:-1:2)),Xn];
Xnmag = abs(Xn);
Xnangle = angle(Xn)
k =-N/2+1:N/2-1
f1=figure('Name','Graph','NumberTitle','off');
plot(t,x)
title("Graph of e^(^-^t^/^2^)")
xlabel("Period")
ylabel("Amplitude")
f2=figure('Name','Fourier Series','NumberTitle','off');
subplot(2,1,1)
stem(k, Xnmag(N/2+1:length(Xn)-N/2))
title("Magnitude Spectrum")
ylabel("Amplitude")
xlabel("Coefficients/Frequency")
subplot(2,1,2)
stem(k,Xnangle(N/2+1:length(Xn)-N/2))
title("Phase Angle")
ylabel("Phase")
xlabel("Coefficients/Frequency")
NOTES: In MATLAB, Fourier series computations are performed numerically using the
Discrete Fourier Transform (DFT), which in turn is implemented numerically using an efficient
algorithm known as the Fast Fourier Transform (FFT). Refer to the textbook (Sect.2.10 & 3.9)
for more theoretical details. You should also type: help fft at the MATLAB prompt and browse
through the online description of the FFT function. Because of all peculiar way MATLAB
implements the FFT algorithm, the fft MATLAB function will provide you with the positive
Fourier coefficients including the coefficient located at 0 Hz. You need to use the even
amplitude symmetry and odd phases symmetry properties of the Fourier series for real signals
(see the introduction to Fourier series to this experiment) in order to find the coefficients for
negative harmonics.

As an illustration, the following code shows how to use fft to obtain Fourier expansion
coefficients. You can study this code, and further enhance it to complete your work.

Xn = fft(x,No)/No;

Xn = [conj(Xn(No:-1:2)),Xn];

Xnmag = abs(Xn);

K=-N0/2+1:N0/2-1

stem(k, Xnmag(No/2+1:length(Xn)-No/2))

stem(k,Xnangle(No/2+1:length(Xn)-No/2))

Useful MATLAB Functions: exp, fft(x,No), length( ), conj, abs, angle, stern, figure, xlabel,
ylabel, title.
Part B: Fourier Transform

3.) In the MATLAB command window, type Fourier_trans_demo.m to launch a GUI that
will demonstrate and review the basic properties of the Fourier transform. The basic
function used is a rectangular unit phase.

 First, introduce a certain time delay in the function, and notice what happens to the
amplitude spectra. Explain why?

Ans.

 Next, introduce different scaling factors and comment on what you are observing.

Ans.

• Now, introduce a frequency shift, which means that the unit pulse is multiplied by a given
sine or cosine with some frequency (later, we will see this is known as Amplitude Modulation).
Referring tothe basic properties of the FT, explain what you are observing in the plots.

Insert Code and graph


4.) Now, consider the signal X1(t) and X2(t) described as follows:

t+1 ,−1 ≤ t ≤ 0
X 1 (t )=
{ 1 , 0<t ≤ 1
0. elsewhere

t , 0 ≤t ≤1
{
X 1 (t )= 1 , 0<t ≤ 2
0. elsewhere

Plot these signals and their relative spectra in MATLAB. What do you conclude from the results
you obtained? Are there any differences?

You need to plot both time signals in one figure window. Similarly, you need to plot the
magnitude and phase spectra for the both signals in one figure window, i.e, overlapping each
other. For the phase, display small values by using the axis command. You also need to
normalize the magnitude and phase values, and you should include the labels, titles, grid, etc.
Assume the x-axis to work as a ruler of units. Each unit contains 100 points and let the starting
point to be at -5 and the last point to be at 5.

Ans.

In the plot of the both time signals there is a huge difference in the signal. But once that the
student converted it using the Fourier transform the signals are somehow alike to each other.
See figure below.

Code

Ts=0.1;

t=[-5:Ts:5];

f1=figure('Name','Functions','NumberTitle','off');

syms t

pw1=piecewise(-1<=t<=0,t+1,0<t<=1,1,0)

pw2=piecewise(0<=t<=1,t,1<t<=2,1,0)

p1=fplot(pw1,'DisplayName','X_1(t)')
hold on

p2=fplot(pw2,'DisplayName','X_2(t)')

hold off

xlabel("Time(seconds)")

ylabel('Amplitude')

title("X_1(t) and X_2(t)")

lgd=legend;

lgd.NumColumns =2;

f2=figure('Name','Magnitude and Phase Spectra','NumberTitle','off');

y1=fft(p1.YData);

fs=1/Ts;

F1=[-length(y1)/2:(length(y1)/2)-1]*fs/length(y1);

plot(F1,abs(y1),'DisplayName','X_1(t) Magnitude')

hold on

plot(F1,angle(y1),'DisplayName','X_1(t) Phase Spectra')

hold off

xlabel('Frequency (Hz)')

ylabel('Magnitude')

title('Magnitude')

hold on

y2=fft(p2.YData);

F2=[-length(y2)/2:(length(y2)/2)-1]*fs/length(y2);

plot(F2,abs(y2),'DisplayName','X_2(t) Magnitude')

plot(F2,angle(y2),'DisplayName','X_2(t) Phase Spectra')

xlabel('Frequency (Hz)')

ylabel('Magnitude')

title('Magnitude')

hold off
lgd=legend;

lgd.NumColumns =2;

Graph of the Piecewise Function

Graph of Fourier Transform Function


Notes: Similar to Fourier series, Fourier transform computations in MATLAB are
easily„implemented using the fft function. The following code illustrates that Notice in
particular the function fftshift is very useful for presenting the Fourier spectrum in an
understandable format. The internal algorithm used in. MATLAB to find the FFT points spreads
the signals points in the frequency domain at the edges of the plotting area, and the function
fftshift centers the frequency plots back around the origin.

X=fft(X);

X=fftshift(X);

X mag=abs(X);

X mag=Xmag/max( X 1 mag );%Normalization

X angle=angle(X);

X angle=angle/max( X angle ¿;

F= [-length (X)/2:(length(X)/2)-1]*fs/length( X mag);

Plot(F, X mag),plot(F, X angle);


5.) Repeat the above for the following signals, and report your observations & conclusions.

x1(t)= 1, |t | ≤ 3

0, elsewhere

x2(t)= 1, |t |≤ 1

Codes

Ts=0.1;

t=[-5:Ts:5];

f1=figure('Name','Functions','NumberTitle','off');

syms t

pw1=piecewise(t<=3,1,0)

pw2=piecewise(t<=1,1)

p1=fplot(pw1,'DisplayName','X_1(t)')

hold on

p2=fplot(pw2,'DisplayName','X_2(t)')

hold off

xlabel("Time(seconds)")

ylabel('Amplitude')

title("X_1(t) and X_2(t)")

lgd=legend;

lgd.NumColumns =2;

f2=figure('Name','Magnitude and Phase Spectra','NumberTitle','off');

y1=fft(p1.YData);

fs=1/Ts;

F1=[-length(y1)/2:(length(y1)/2)-1]*fs/length(y1);

plot(F1,abs(y1),'DisplayName','X_1(t) Magnitude')

hold on
plot(F1,angle(y1),'DisplayName','X_1(t) Phase Spectra')

hold off

xlabel('Frequency (Hz)')

ylabel('Magnitude')

title('Magnitude')

hold on

y2=fft(p2.YData);

F2=[-length(y2)/2:(length(y2)/2)-1]*fs/length(y2);

plot(F2,abs(y2),'DisplayName','X_2(t) Magnitude')

plot(F2,angle(y2),'DisplayName','X_2(t) Phase Spectra')

xlabel('Frequency (Hz)')

ylabel('Magnitude')

title('Magnitude')

hold off

lgd=legend;

lgd.NumColumns =2;

Graph of Function
Graph of Magnitude and Phase Spectra
6.) In the MATLAB directory you are working in, you will find a MAT-file named
ExplPart4.mat. You need to load that file as follows:

Load ExplPart4.mat

press Enter. You will notice three stored variables fs (ampling frequency or 1/ts), t (time axis
vector) and m (speech signal). These correspond to a portion of speech recording.

window and a second window panel, display the magnitude spectrum of m (call it M). What is
the bandwidth of the signal? What can you notice in terms of the speech signal? In order to play
the signal properly, make sure that the speakers are turned on and write the following MATLAB
statement:

sound(m,fs)

Ans.

Insert graph
IV. DATA RESULTS

PRE-LAB WORK

Real Part of z

Imaginary of z

LAB WORK Part A. No.1

Square Wave with Negative Frequency


Sawtooth Wave with Negative Frequency

Full-wave Rectified with Negative Frequenc


LAB WORK Part A. No.2

V. CONCLUSION

This laboratory experiment is so fun and challenging. It really takes a lot of effort to understand
Fourier Series. In this activity the student was able to make a program that can define Fourier
Series. Sadly, the student was not able to perform the Fourier Transform because the file cannot
be found in the internet anymore. Nevertheless, in this experiment the students were able to
perform well in doing and creating a program in the Fourier Series and was able to understand
how Fourier Series and Fourier Transform is doing in the signal spectra.

You might also like