0% found this document useful (0 votes)
45 views8 pages

SNS Lab 08 SP 2020

This lab manual document describes how to find Fourier series coefficients and plot magnitude and phase spectra using MATLAB. It contains 4 practice tasks - computing coefficients and plotting for a sinusoidal signal, computing coefficients for a sum of sinusoids signal, numerically computing coefficients using the trapezoidal rule, and demonstrating Gibbs phenomenon by plotting truncated Fourier series for different numbers of terms. The document provides MATLAB code examples and expected output plots for each task.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

SNS Lab 08 SP 2020

This lab manual document describes how to find Fourier series coefficients and plot magnitude and phase spectra using MATLAB. It contains 4 practice tasks - computing coefficients and plotting for a sinusoidal signal, computing coefficients for a sum of sinusoids signal, numerically computing coefficients using the trapezoidal rule, and demonstrating Gibbs phenomenon by plotting truncated Fourier series for different numbers of terms. The document provides MATLAB code examples and expected output plots for each task.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Signals and Systems

(EL-223)

LABORATORY MANUAL
Spring 2020

Dr. Shahzad Saleem


Engr. Fakhar Abbas

FINDING FOURIER SERIES AND COEFFICIENTS USING


MATLAB
LAB # 08 – (March 09, 11, 12 2020)

Prepared by: Engr. Fakhar Abbas Version:2.00


Verified by: Dr. Waqas Bin Abbas, Dr. Shahzad Saleem Updated: Spring 2020
Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB

Objective: In this lab, you will learn:


Computing Fourier series coefficients using MATLAB
Implementing Gibbs phenomenon using MATLAB
Plotting the magnitude and phase spectrum of Fourier series

Tools Used: MATLAB

1. Introduction:

Computing Fourier Series Coefficients:


1- Exponential Form:
Fourier coefficients { } are found according to

1
=

where:
= fundamental period of (in seconds)
π
= fundamental frequency of x(t) (in rad/second) = =2π where is in Hz
= any time point (you pick = 0 to ease calculations)
∈ all integers … – 3, – 2, – 1, 0, 1, 2, 3, … used for Coefficients of Fourier Series (FS)
for = 0 this gives
1
=

Which is the “DC offset”, i.e., the time-average over one period.

2- Sine-Cosine Form of FS Coefficients


# =
# = 2$ { }
% = −2 '({ }
3- Magnitude-Phase Form of FS Coefficients
) =
) = 2| |
+ = ∠

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 2 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB

2. Computing Fourier Coefficients and Plotting Magnitude and Phase Spectrum


using MATLAB:

Practice Task # 01: Modify the following code to find Fourier series coefficients of the signal
- = sin 21100 . Plot its magnitude and phase spectra over range [−200 200] for 4 = 2
coefficients.
Note: Magnitude spectrum is symmetric/even but phase spectrum is asymmetric/odd.

Incomplete Matlab Code:


clear all; clc;close all
syms t
y=sin(2*pi*100*t);% f= 100 Hz
T0=1/100;% Since T anf f are inversely proportional: T= 1/f, So, T0 = 1/100 = 0.01
N=2; % N Coefficients
%%%%%%%%%%%
%Write code here to plot y, please ensure that your code should
%produce the plot y(t) shown in above figure
%%%%%%%%%%%%%%%%
set(h,'linewidth',2)
grid on;
xlabel('t (sec)','fontweight','bold');
ylabel('y(t)','fontweight','bold')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Write Matlab Code here for the computation of Fourier Coefficients

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%
%Write code here to plot magnitude Spectrum of Yk shown in above
%figure: Note: abs command is used to find magnitude
%%%%%%%%%%%%%%%%
set(gca,'Xtick',0:25:200,'fontweight','bold')
set(h,'linewidth',2)
grid on;
xlabel('f (Hz)','fontweight','bold');
ylabel('|Y_k|','fontweight','bold')
subplot(224)
h=stem(f,angle(Y));
set(h,'linewidth',2)
set(gca,'Xtick',0:25:200,'fontweight','bold')
grid on;
xlabel('f (Hz)','fontweight','bold');
ylabel('\angle{Y_k}','fontweight','bold')

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 3 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB

Practice Task # 02: Compute the Fourier series coefficients of given signals. Plot its magnitude and
phase line spectra over range [−5 5] for 4 = 5 Coefficients.
= 2 + cos 21 + cos 41 + 1/3 + cos 81 + 1/2

3. Numerically Finding Coefficients using MATLAB Trapz command:


Q = trapz(Y) computes the approximate integral of Y via the trapezoidal method with unit spacing. The size
of Y determines the dimension to integrate along:
1- If Y is a vector, then trapz(Y) is the approximate integral of Y.
2- If Y is a matrix, then trapz(Y) integrates over each column and returns a row vector of integration
values.
3- If Y is a multidimensional array, then trapz(Y) integrates over the first dimension whose size does not
equal 1. The size of this dimension becomes 1, and the sizes of other dimensions remain unchanged.
Example:
Suppose you have a periodic signal and you want to find the FS coefficients, but it does not have a nice
mathematical function that defines it (or it does but it is hard or impossible to do the integral). In this case, we
can numerically compute the integral.
1- Use samples to define trapezoid.
2- Then find the areas of all the trapezoids.
We can use samples of the integrand to compute all the trapezoid areas and then use those to approximate the
integral. MATLAB has a command called “trapz” that does just this.

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 4 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB

x is the vector that holds the signal samples over one period
t is a vector that holds the time values spaced Ts seconds apart
T is the period of the signal
wo is the fundamental frequency in rad/sec

Practice Task # 03:


T = 4; % Specify period in seconds
wo = 2*pi/T; % Compute fund. freq. in rad/sec
K = 10; % specify largest k value
Ts = 0.05; % Specify sample spacing
t = 0:Ts:T; % Compute vector of time samples
x =(20/T)*t; % Compute vector of signal samples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Write Matlab code to compute all Fourier coefficients using Trapz command

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 5 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB

4. Gibbs Phenomenon

Practice Task # 04:


Write a Matlab code to generate < and plot following cases. Consider = −3: 6/1000: 3; where DC constant
is 1/2. These plots are only for confirmation of your code.
For ? = @, plot of < will be as follows:

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 6 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB
For ? =3, plot of < will be as follows:

For ? = A, plot of < will be as follows:

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 7 of 8


Lab 8 - Finding Fourier Series and Fourier Coefficients using MATLAB
For ? = B@, plot of < will be as follows:

For ? = CD, plot of < will be as follows:

SIGNALS AND SYSTEMS LAB NUCES, ISLAMABAD Page 8 of 8

You might also like