0% found this document useful (0 votes)
10 views3 pages

Experiment 6 SS

The document outlines Experiment 6, which involves calculating Fourier series coefficients for a periodic square wave and reconstructing it using a compact trigonometric Fourier series. Part 1 includes generating a square wave, calculating its Fourier coefficients, and displaying them. Part 2 focuses on synthesizing the square wave by summing harmonics based on user input for the number of harmonics, and visualizing the results.

Uploaded by

Renuka Bhavsar
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)
10 views3 pages

Experiment 6 SS

The document outlines Experiment 6, which involves calculating Fourier series coefficients for a periodic square wave and reconstructing it using a compact trigonometric Fourier series. Part 1 includes generating a square wave, calculating its Fourier coefficients, and displaying them. Part 2 focuses on synthesizing the square wave by summing harmonics based on user input for the number of harmonics, and visualizing the results.

Uploaded by

Renuka Bhavsar
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/ 3

Experiment 5:

Code and Output:


Part 1:
%% Experiment No. 6
%% Part a: Calcultion of Fourier Series Coefficients
%% of a periodic square wave
clc ;
clear all;
close all;

%% Generation and plotting of a periodic square wave


T0 =6;
t = -5.99:0.01:6;
x =[];
%x=(2.*(t>-4)-2.*(t>-2)+2.*(t>0)-2.*(t>2)+2.*(t>4));
x=(1.*(t>-7.5)-1.*(t>-4.5)+1.*(t>-1.5)-1.*(t>1.5)+1.*(t>4.5)-1.*(t>7.5));
plot (t,x,' r ');
xlabel('Time -->');
ylabel('Amplitude -->')
title('Peridic Signal');
axis([-8,8,-0.5,1.5]);
w0=pi/3;

%% Calcultion of Fourier Series Coefficients


for k = -10:10
cc(k+11 ,:) = exp (-i*k*w0*t);
ck(k +11) = x*cc(k+11 ,:)'/ length(t);
if abs (ck(k +11) ) <0.01
ck(k +11) =0;
end
if imag(ck(k +11)) < 0.01
ck(k +11) = real(ck(k+11));
end
if k ==0
C0=ck(k +11) ;
end
end
Cn=ck;
printf('The Fourier Coefficients are: \n')
C0
Cn

Part 2:

%% Experiment No. 6

%% Part b: Reconstruction of even symmetric square wave using compact trigonometric Fourier
series

% Consider the time period, T=2*pi and the amplitude,A=1 and 50 % Duty cycle.

% input: Enter the number of harmonics through keyboard

% output: Plot of synthesized suqare wav


clc

close all

clear all

No_harmonics = input ('Enter the number of harmonics = ');

t = linspace(-2*pi, 2*pi, 1000);

Total_terms = zeros(No_harmonics, length(t));

Total_terms(1,:) = 1/2;

for n=1:No_harmonics

Total_terms(n+1,:) = (2/(n*pi)*sin(n*pi/2))*cos(n*t);

end

figure(1)

for i=1:No_harmonics

x_synthesized = sum(Total_terms(1:i, :));

plot(t, x_synthesized), grid on

title('Fourier series synthesis')

pause(0.5);

disp(i)

end

You might also like