% Fourier Series Expansion: All All
% Fourier Series Expansion: All All
clc
clear all
close all
t = 0:0.01:4;
T = 2;
w = pi;
sqr = [0.5*ones(1,101) -0.5*ones(1,100) 0.5*ones(1,100)
-0.5*ones(1,100)];
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)
grid
xlabel('Time')
ylabel('Amplitude')
title('first harmonic 21075A1008')
axis([0 4 -0.75 0.75])
subplot(2,2,2)
plot(t,sqr,t,Harmonic_3)
grid
xlabel('Time')
ylabel('Amplitude')
title('third harmonic 21075A1008')
axis([0 4 -0.75 0.75])
subplot(2,2,3)
plot(t,sqr,t,Harmonic_5)
grid
xlabel('Time')
ylabel('Amplitude')
title('fifth harmonic 21075A1008')
axis([0 4 -0.75 0.75])
subplot(2,2,4)
plot(t,sqr,t,Harmonic_7)
grid
xlabel('Time')
ylabel('Amplitude')
title('seventh harmonic 21075A1008')
axis([0 4 -0.75 0.75])
figure(2)
plot(t,sqr,t,Harmonic_1,t,Harmonic_3,t,Harmonic_5,t,Harmonic_7)
1
grid
xlabel('Time')
ylabel('Amplitude')
title('ALL Harmonic 21075A1008')
axis([0 4 -0.75 0.75])
legend('square','Harmonic1','Harmonic3','Harmonic5','Harmonic7')
figure(3)
Harmonic_13 = Harmonic_1+Harmonic_3;
Harmonic_135 = Harmonic_1+Harmonic_3+Harmonic_5;
Harmonic_1357 = Harmonic_1+Harmonic_3+Harmonic_5+Harmonic_7;
subplot(2,2,1)
plot(t,sqr,t,Harmonic_1)
grid
xlabel('Time')
ylabel('Amplitude')
title('Approximation SUM of 1')
axis([0 4 -0.75 0.75])
subplot(2,2,2)
plot(t,sqr,t,Harmonic_13)
grid
xlabel('Time')
ylabel('Amplitude')
title('Approximation SUM of 13')
axis([0 4 -0.75 0.75])
subplot(2,2,3)
plot(t,sqr,t,Harmonic_135)
grid
xlabel('Time')
ylabel('Amplitude')
title('Approximation SUM of 135')
axis([0 4 -0.75 0.75])
subplot(2,2,4)
plot(t,sqr,t,Harmonic_1357)
grid
xlabel('Time')
ylabel('Amplitude')
title('Approximation SUM of 1357')
axis([0 4 -0.75 0.75])
figure(4)
plot(t,sqr,t,Harmonic_1,t,Harmonic_13,t,Harmonic_135,t,Harmonic_1357)
grid
xlabel('Time')
ylabel('Amplitude')
title('ALL Approximation SUMS 21075A1008')
axis([0 4 -0.75 0.75])
legend('square','Harmonic1','Harmonic13','Harmonic135','Harmonic1357')
figure(5)
2
Error_1 = sqr-Harmonic_1;
Error_13 = sqr-Harmonic_13;
Error_135 = sqr-Harmonic_135;
Error_1357 = sqr-Harmonic_1357;
subplot(2,2,1)
plot(t,sqr,t,Error_1)
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation sum of 1')
axis([0 4 -0.75 0.75])
subplot(2,2,2)
plot(t,sqr,t,Error_13)
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation sum of 13')
axis([0 4 -0.75 0.75])
subplot(2,2,3)
plot(t,sqr,t,Error_135)
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation sum of 135')
axis([0 4 -0.75 0.75])
subplot(2,2,4)
plot(t,sqr,t,Error_1357)
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation sum of 1357')
axis([0 4 -0.75 0.75])
figure(6)
subplot(2,2,1)
area(t(1:100),Error_1(1:100))
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation SUM of 1')
axis([0 4 -0.75 0.75])
subplot(2,2,2)
area(t(1:200),Error_13(1:200))
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation SUM of 13')
axis([0 4 -0.75 0.75])
3
subplot(2,2,3)
area(t(1:300),Error_135(1:300))
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation SUM of 135')
axis([0 4 -0.75 0.75])
subplot(2,2,4)
area(t(1:400),Error_1357(1:400))
grid
xlabel('Time')
ylabel('Amplitude')
title('Error due to approximation SUM of 1357')
axis([0 4 -0.75 0.75])
4
5
6
Published with MATLAB® R2020a