SNS___Lab__Report__7(Fourier)
SNS___Lab__Report__7(Fourier)
Objectives
The goal of this laboratory is to be able to calculate the fourier series of approximately continuous time and
discrete time signals and plot the real part of the spectrum / Fourier series coefficients.
Lab Instructions
This lab activity comprises of three parts: Pre-lab, Lab Exercises, and Post-Lab Viva session.
The Pre-lab tasks should be completed before coming to the lab. The reports are to be submitted on
LMS.
The students should perform and demonstrate each lab task separately for step-wise evaluation
Only those tasks that completed during the allocated lab time will be credited to the students.
Students are however encouraged to practice on their own in spare time for enhancing their skills.
Lab Report 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
1.1 Pre-Lab
1.1.1 Introduction
CTFS
2𝜋
For a CT signal 𝑥(𝑡) with fundamental period 𝑇 and fundamental frequency 𝑤0 = , the CTFS synthesis
𝑇
and analysis equations are given by (1) and (2), respectively.
2𝜋
𝑗𝑘( )𝑡
𝑥(𝑡) = ∑∞
𝑘=−∞ 𝑎𝑘 𝑒
𝑇 (1)
2𝜋
1
𝑎𝑘 = 𝑇 ∫𝑇 𝑥(𝑡)𝑒 −𝑗𝑘( 𝑇 )𝑡 𝑑𝑡 (2)
DTFS
For a DT signal 𝑥[𝑛] with fundamental period 𝑁, the DTFS synthesis and analysis equations are given by
(3) and (4), respectively.
2𝜋
𝑥[𝑛] = ∑𝑘=<𝑁> 𝑎𝑘 𝑒 𝑗𝑘( 𝑁 )𝑛 (3)
2𝜋
1
𝑎𝑘 = 𝑁 ∑𝑛=<𝑁> 𝑥[𝑛]𝑒 −𝑗𝑘( 𝑁 )𝑛 (4)
Remember that 𝑥[𝑛] has period 𝑁, so that the summation in (4) can be replaced with a sum over any 𝑁
consecutive values of 𝑛. Similarly, 𝑎𝑘 is periodic in 𝑘 with period 𝑁 so that the summation in (3) can be
replaced with a sum over any 𝑁 consecutive values of 𝑘.
fseriesdemo: FourierSeriesDemo is a GUI that shows Fourier Series synthesis for different number
of Fourier coefficients. Different signals can be selected: square wave, sawtooth, triangle and
rectified sinusoids.
sinesum demo: Sinesum demo helps us to take the sum of sinusoids to create more complex signals.
You have been provided the zip files for both. Extract them to the MATLAB working directory or extract
them to any directory of choice and include the path in MATLAB. We can run the demos by writing the
following commands on the Command Window.
>> fseriesdemo
Your task is to create a sawtooth waveform with T=10sec and increase the number of Fourier coefficients.
Observe and state the significance of increasing number of coefficients. Also provide the screenshot.
>> sinesum2
Your task is to increase the number of harmonics to 5. Change the amplitude of these harmonics. Explain
the effect of changing the number of harmonics in the sinesum demo. Also provide the screenshot.
Determine the Fourier series coefficients and plot the magnitude and phase of the fourier series coefficients
NOTE:
For calculating the fourier series coefficients use (1).
Note that (1) involves solving an integration. Use MATLAB built in function integral() to
numerically evaluate the integral. For example, for a value of 𝑘 = 4, the function will be evaluated
as
a = integral(@(z) 𝐴 ∗ sin((2 ∗ 𝑝𝑖/𝑇) ∗ 𝑧).*exp(-j*4*(2*pi/T)*z)/T,0,T)
Above code will return the value of the 4th CTFS coefficient. For remaining coefficients, replace 4
and follow similar procedure. You may use a loop to iterate over values of 𝑘.
Add the figures of both the time domain and frequency domain representation of the singals with
appropriate axes, labels and titles.
Code:
The function specified by this code generates a sine wave with specified amplitude (A) and period (T), plots
the wave, and then calculates and displays its Fourier series coefficients, magnitude spectrum, and phase
spectrum.This function provides a visual representation of the decomposition of a sine wave into its
constituent frequency components, offering insights into the harmonic content of the signal. Adjustments to
parameters and plotting options can be made to tailor the analysis to specific needs.
Result:
……………. ……………………….
0 1 2 3 4 5
t
Code:
Result:
For the signals in Tasks 1.2.1.1 and 1.2.1.2, reconstruct the signal using the obtained FS coefficients 𝑎𝑘 . The
CT signal can be generated from the FS coefficients 𝑎𝑘 using (1).
𝑁1
2𝜋
𝑥𝑟 (𝑡) = ∑ 𝑎𝑘 𝑒 𝑗𝑘( 𝑇 )𝑡
𝑘=−𝑁1
Choose an appropriate value of ‘time_increment/sampling time’ during the generation of complex
exponential signal. Plot the reconstructed signal 𝑥𝑟 (𝑡) for 𝑁1 = 3, 10, 50 . Compare with original signal
𝑥(𝑡).
Use of fft and ifft
MATLAB contains efficient routines for computing CTFS and DTFS. If x is an N-point vector for the period
0 ≤ n ≤ N - 1, then the DTFS of x[n]can be computed by ak=(l/N)*fft(x), where the N-point vector a contains
ak for 0 ≤ k ≤ N - 1. The function fft is simply an efficient implementation of (2) scaled by N. Thus,
DTFS can by computed by typing ak=(l/N)*fft(x). The function will return both real and imaginary parts
of the DTFS coefficients.
Given a vector containing the DTFS coefficients ak for 0 ≤ k ≤ N - 1, the function ifft can be used to construct
a vector x containing x[n] for 0 ≤ n ≤ N – 1 as x=N*ifft (a). The function ifft is an efficient realization of the
DTFS synthesis equation, scaled by 1/N.
Using the function ‘ifft’ and knowledge of FS coefficents of a Cosine waveform determine the signal x[n].
For the lab report plot both the fourier coefficients and time domain signal.
Now assuming that the DTFT was N Point DTFT or FFT. Then the fourier Series Coefficients of x[n]
= cos (pi/4) n will have impulses at locations k and N-k.
ωk = 2 pi k /N If ωk = pi/4 Then k = N/8 Where N is the N point DTFT or FFT. Assuming that N =1024
locations k and N-k can be calculated. So the coeff_array will be an array of size N with fourier series
coefficients of a cosine waveform at locations k and N-k.
Code:
Explanation:
A sine wave was generated and reconstructed using Fourier coefficients through an Inverse Fourier Transform.
Harmonic contributions were iteratively added to rebuild the original signal, showing the role of each component.
10
50
Code:
Explanation:
A square wave was analyzed and reconstructed using Fourier series coefficients. The iterative process highlighted
how harmonics contribute to rebuilding the wave.
10
50
This lab focused on analyzing and reconstructing periodic signals using Fourier series and transforms. Sine
and square waves were decomposed into their harmonic components, illustrating the frequency domain
representation. The iterative reconstruction process demonstrated how signals can be synthesized from
Fourier coefficients. MATLAB functions and tools were effectively used for visualization and analysis.
These techniques provide a deeper understanding of signal decomposition and synthesis, with practical
applications in engineering.