Fourierseries 1
Fourierseries 1
clc;
close all;
clear all;
T=2;
W=pi;
t=0:0.001:4;
sqr=[0.5*ones(1,1001) -0.5*ones(1,1000) 0.5*ones(1,1000) -0.5*ones(1,1000)];
Harmonic_1 = 2/pi*sin(W*t);
Harmonic_3 = 2/(3*pi)*sin(3*W*t);
Harmonic_5 = 2/(5*pi)*sin(5*W*t);
Harmonic_7 = 2/(7*pi)*sin(7*W*t);
figure(1)
subplot(2,2,1)
plot(t,sqr,t,Harmonic_1)
xlabel('Time')
ylabel('Amplitude')
grid
title('First non zero fourier component')
axis([ 0 4 -0.7 0.7])
subplot(2,2,2)
plot(t,sqr,t,Harmonic_3)
xlabel('Time')
ylabel('Ampiltude')
grid
title('Second non zero fourier component')
axis([ 0 4 -0.7 0.7])
subplot(2,2,3)
plot(t,sqr,t,Harmonic_5)
xlabel('Time')
ylabel('Ampiltude')
grid
title('Third non zero fourier component')
axis([ 0 4 -0.7 0.7])
subplot(2,2,4)
plot(t,sqr,t,Harmonic_7)
1
xlabel('Time')
ylabel('Ampiltude')
grid
title('Fourth non zero fourier component')
figure(2)
plot(t,sqr,t,Harmonic_1,t,Harmonic_3,t,Harmonic_5,t,Harmonic_7)
xlabel('Time')
ylabel('Amplitude')
grid
title('First four non zero fourier component 22071A1005')
axis([ 0 4 -0.7 0.7])
legend('Square','Harmonic-1','Harmonic-3','Harmonic-5','Harmonic-7')
2
%C. succesive approximation of sum of fse on seperate plots
Harmonic_13 = Harmonic_1+Harmonic_3;
Harmonic_135 = Harmonic_1+Harmonic_3+Harmonic_5;
Harmonic_1357 = Harmonic_1+Harmonic_3+Harmonic_5+Harmonic_7;
figure(3)
subplot(2,2,1)
plot(t,sqr,t,Harmonic_1)
xlabel('Time')
ylabel('amplitude')
grid
title('Sum of harmonics-1(22071a1005)')
axis([ 0 4 -0.7 0.7])
subplot(2,2,2)
plot(t,sqr,t,Harmonic_13)
xlabel('Time')
ylabel('amplitude')
grid
title('Sum of harmonics-1 and 3')
axis([ 0 4 -0.7 0.7])
subplot(2,2,3)
plot(t,sqr,t,Harmonic_135)
3
xlabel('Time')
ylabel('amplitude')
grid
title('Sum of harmonics-1,3 and 5')
axis([ 0 4 -0.7 0.7])
subplot(2,2,4)
plot(t,sqr,t,Harmonic_1357)
xlabel('Time')
ylabel('amplitude')
grid
title('Sum of harmonics-1,3,7 and 5')
axis([ 0 4 -0.7 0.7])
4
%E. plotting Errors
Error_1 = sqr-Harmonic_1;
Error_13 = sqr-Harmonic_13;
Error_135 = sqr-Harmonic_135;
Error_1357 = sqr-Harmonic_1357;
figure(5)
subplot(2,2,1)
plot(t,sqr,t,Error_1)
xlabel('Time')
ylabel('Amplitude')
grid
title('error due to the harmonic-1')
axis([ 0 4 -0.7 0.7])
subplot(2,2,2)
plot(t,sqr,t,Error_13)
xlabel('Time')
ylabel('Amplitude')
grid
title('error due to the harmonic-13')
axis([ 0 4 -0.7 0.7])
subplot(2,2,3)
5
plot(t,sqr,t,Error_135)
xlabel('Time')
ylabel('Amplitude')
grid
title('error due to the harmonic-135')
axis([ 0 4 -0.7 0.7])
subplot(2,2,4)
plot(t,sqr,t,Error_1357)
xlabel('Time')
ylabel('Amplitude')
grid
title('error due to the harmonic-1357')
axis([ 0 4 -0.7 0.7])
Error_1 = sqr-Harmonic_1;
Error_13 = sqr-Harmonic_13;
Error_135 = sqr-Harmonic_135;
Error_1357 = sqr-Harmonic_1357;
figure(6)
subplot(2,2,1)
area(t,Error_1)
xlabel('Time')
6
ylabel('Amplitude')
grid
title('Error due to the harmonic-1')
axis([ 0 4 -0.7 0.7])
subplot(2,2,2)
area(t,Error_13)
xlabel('Time')
ylabel('Amplitude')
grid
title('Error due to the harmonic-13')
axis([ 0 4 -0.7 0.7])
subplot(2,2,3)
area(t,Error_135)
xlabel('Time')
ylabel('Amplitude')
grid
title('Error due to the harmonic-135')
axis([ 0 4 -0.7 0.7])
subplot(2,2,4)
area(t,Error_1357)
xlabel('Time')
ylabel('Amplitude')
grid
title('Error due to the harmonic-1357')
axis([ 0 4 -0.7 0.7])
7
8