Respuesta :
Explanation:
With the Fourier series approximation we can represent any function with just sine and cosine waves having different frequencies. As we increase the number of harmonics the approximation gets closer and closer to the real function.
Matlab Code:
% time vector
t=0:0.001:6;
f=0;
% run a for loop for the summation of harmonics, it will skip for n = even because the Fourier coefficients of a square wave are zero for n = even
for n=1:2:15;
% the Fourier representation of square wave you can change this function as required
f=f+((2/(n*pi))*sin(n*pi*t));
% plot a graph when number of harmonics are 3
if n==3
f1=f;
% 2 rows and 2 columns total 4 plots
subplot(2,2,1);
% increased line width with red color
plot(t,f1,'r','Linewidth',2)
grid on
title('n = 3')
xlabel('Time')
ylabel('Amplitude')
axis tight
end
% plot a graph when number of harmonics are 5
if n==5
f1=f;
subplot(2,2,2);
% increased line width with blue color
plot(t,f1,'b','Linewidth',2)
grid on
title('n = 5 ')
xlabel('Time')
ylabel('Amplitude')
axis tight
end
% plot a graph when number of harmonics are 7
if n==7
f1=f;
subplot(2,2,3);
% increased line width with magenta color
plot(t,f1,'m','Linewidth',2)
grid on
title('n = 7')
xlabel('Time')
ylabel('Amplitude')
axis tight
end
% plot a graph when number of harmonics are 15
if n==15
f1=f;
subplot(2,2,4);
% increased line width with black color
plot(t,f1,'k','Linewidth',2)
grid on
title('n = 15')
xlabel('Time')
ylabel('Amplitude')
axis tight
end
end
Output:
Please refer to the attached plot, as you can see in the attached graph as we are increasing the number of harmonics, the plot is getting more and more closer to a square wave. This is the beauty of Fourier series.