Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

AREEBA NUSRAT

TC-21015 LAB SESSION 2

LABORATORY TASK:
1. Write the code on MATLAB to carry out Fourier synthesis of square wave and analyze
its spectrum.

SOURCE CODE
clear all;
tm=5000;
F=1/500;
out = zeros(1,tm);
for t=1:1:tm
x = sin(2*pi*F*t) + (1/3)*(sin(2*3*pi*F*t)) + (1/5)*(sin(2*5*pi*F*t)) +
(1/7)*(sin(2*7*pi*F*t)) + (1/9)*(sin(2*9*pi*F*t));
out(t)= x ;
end

subplot(2,1,1);
plot(1:tm,out,'b');
xlabel('Time');
ylabel('Amplitude');
title('SQUARE WAVE FOURIER SERIES');
for t=1:1:tm
y=fft(out);
a=abs(y);
end
subplot(3,1,3);
plot(1:tm,a,'m');
xlabel('Frequency');
ylabel('Amplitude');
title('SQUARE WAVE FAST FOURIER TRANSFORM')

OUTPUT

NOOR US SABAH(TC-042)

You might also like