0% found this document useful (0 votes)
12 views

2021_MC_42_Lab 10

Uploaded by

abeerasif233
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)
12 views

2021_MC_42_Lab 10

Uploaded by

abeerasif233
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/ 3

LAB 10: FOURIER SERIES

CLO1: USE MODERN TOOL (E.G. MATLAB) FOR SIGNAL REPRESENTATION, VISUALIZATION
AND PROCESSING IN BOTH TIME AND FREQUENCY DOMAIN.

Trigonometric Fourier Series


Find for the Fourier Series of following signal:

The formula for Fourier Series is:


(𝑡) = 𝑎0 + ∑(𝑎𝑛 cos 𝑛𝜔𝑜𝑡 + 𝑏𝑛 sin 𝑛𝜔𝑜𝑡)


𝑛=1

1
For the above signal Fourier co-efficient are calculated in the book as:

𝑎0 =
2
𝑎 𝑛
= 𝑛 sin ( ) and 𝑛 = 0
2 𝜋
𝑛
𝜋 2

There are infinite co-efficient for the above signal. But you can add finite sinusoids to get the signal
which will be somewhat different depending upon number of co-efficient you are selecting.
Task 1:
Create a MATLAB function LS10_1 which will take number of co-efficient as input from the user
and will plot the original signal and approximate signal (by adding sinusoids) on the same axis (not
using subplot) and with different colors. The range should be from -4𝜋 to 4𝜋.
The original square wave can be plotted using the MATLAB command ‘square’. See help to find
further detail.
Take number of co-efficient from user. Use a for loop to calculate 𝑎𝑛 from 1 to user’s entered input.
Also calculate cos 𝑛𝜔𝑜𝑡 (𝜔𝑜 is 1 in this case) and keep on adding them within the same loop. At
the end of the loop add 𝑎0 and this will be the approximate signal of the above signal.
Write down the code of the function and paste the outputs for three different number of co-efficient
e.g. 9, 80 and 900.

MCT-342L: Signals and Systems


Department of Mechatronics and Control Engineering, U.E.T Lahore
numCoefficients = input('Enter the number of coefficients: ');

% Ensure the input is a positive integer


if ~isnumeric(numCoefficients) || numCoefficients <= 0 || mod(numCoefficients, 1) ~= 0
error('Input must be a positive integer.');
end

% Call the function with the user's input


LS10_1(numCoefficients);

function LS10_1(n_coefficients)
t = linspace(-4*pi, 4*pi, 1000);
a0 = 1/2;
w0 = 1; % fundamental frequency
y = a0;

for n = 1:n_coefficients
an = (2/(n*pi)) * sin(n*pi/2);
y = y + an * cos(n*w0*t);
end

figure;
hold on;
plot(t, square(t+1.5), 'r', 'LineWidth', 2); % Original signal
plot(t, y, 'b', 'LineWidth', 2); % Approximate signal
legend('Original Signal', 'Approximate Signal');
title('Fourier Series Approximation');
xlabel('Time');
ylabel('Amplitude');
grid on;
hold off;
end

You might also like