MATLAB CODE:
%Fourier series of rectangular 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=50;
j=1;
for k=-N:1:N
if(k==0)
c(j)=2*tau/T; % fourier series coefficients of
rectangular 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 rectangular 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 rectangular pulse
grid on;
xlabel('time');
ylabel('rectangular
pulse');
No comments:
Post a Comment