Vous êtes sur la page 1sur 4

1

5 harmonics
t = linspace(-40,40,1000);
a0 = 0.25;
an = a0;
N=5;
for n = 1:N;
an=an+((2/n*pi)*sin((n*pi)/5)*cos((2*pi*n*t)/5));
end;
plot(t,an,'b','linewidth',2.0);
grid on;
title('Show the plot signal for the first 5 harmonics')
2
10 harmonics
t = linspace(-40,40,1000);
a0 = 0.25;
an = a0;
N=10;
for n = 1:N;
an=an+((2/n*pi)*sin((n*pi)/5)*cos((2*pi*n*t)/5));
end;
plot(t,an,'b','linewidth',2.0);
grid on;
title('Show the plot signal for the first 10 harmonics')
3
20 harmonic
t = linspace(-40,40,1000);
a0 = 0.25;
an = a0;
N=20;
for n = 1:N;
an=an+((2/n*pi)*sin((n*pi)/5)*cos((2*pi*n*t)/5));
end;
plot(t,an,'b','linewidth',2.0);
grid on;
title('Show the plot signal for the sum of these 20 harmonics')

4
For time domain and frequency domain (5 harmonic)
%Fourier series of square wave
clc;
close all;
clear all;
j=1;
T=4;
%Time period of square wave
tau=1; %2tau= On time of the square wave
w0=2*pi/T;
N=5;

j=1;
for k=-N:1:N
if(k==0)
c(j)=2*tau/T; % fourier series coefficients of square pulse
else
c(j)=2*sin(k*w0*tau)/(k*w0*T);
end
j=j+1;
end
k=-N:1:N;
subplot(2,1,1);
stem(k,c);
%plot fourier series coefficients
grid on;
xlabel('k');
ylabel('fourier series coefficient of square pulse');
%%---------------------------------------------------l=1;
time=10;
for t=-time:0.01:time
sum=0;
j=1;
for k=-N:1:N
sum=sum+c(j)*exp(i*k*w0*t); %synthesis equation
j=j+1;
end
s(l)=sum;
l=l+1;
end
t=-time:0.01:time
subplot(2,1,2);
plot(t,s);
% plot square pulse
grid on;
xlabel('time');
ylabel('square pulse');

5(10 harmonic)
%Fourier series of square wave
clc;
close all;
clear all;
j=1;
T=4;
%Time period of square wave
tau=1; %2tau= On time of the square wave
w0=2*pi/T;
N=10;
j=1;
for k=-N:1:N
if(k==0)
c(j)=2*tau/T; % fourier series coefficients of square pulse
else
c(j)=2*sin(k*w0*tau)/(k*w0*T);

end
j=j+1;
end
k=-N:1:N;
subplot(2,1,1);
stem(k,c);
%plot fourier series coefficients
grid on;
xlabel('k');
ylabel('fourier series coefficient of square pulse');
%%---------------------------------------------------l=1;
time=10;
for t=-time:0.01:time
sum=0;
j=1;
for k=-N:1:N
sum=sum+c(j)*exp(i*k*w0*t); %synthesis equation
j=j+1;
end
s(l)=sum;
l=l+1;
end
t=-time:0.01:time
subplot(2,1,2);
plot(t,s);
% plot square pulse
grid on;
xlabel('time');
ylabel('square pulse');

6 (For 20 harmonic)
%Fourier series of square wave
clc;
close all;
clear all;
j=1;
T=4;
%Time period of square wave
tau=1; %2tau= On time of the square wave
w0=2*pi/T;
N=20;
j=1;
for k=-N:1:N
if(k==0)
c(j)=2*tau/T; % fourier series coefficients of square pulse
else
c(j)=2*sin(k*w0*tau)/(k*w0*T);
end
j=j+1;
end
k=-N:1:N;
subplot(2,1,1);
stem(k,c);
%plot fourier series coefficients
grid on;

xlabel('k');
ylabel('fourier series coefficient of square pulse');
%%---------------------------------------------------l=1;
time=10;
for t=-time:0.01:time
sum=0;
j=1;
for k=-N:1:N
sum=sum+c(j)*exp(i*k*w0*t); %synthesis equation
j=j+1;
end
s(l)=sum;
l=l+1;
end
t=-time:0.01:time
subplot(2,1,2);
plot(t,s);
% plot square pulse
grid on;
xlabel('time');
ylabel('square pulse');

Vous aimerez peut-être aussi