Fourier series of Sawtooth wave
[code matlab]
% xN(t)=sum(ak*exp(j*2*pi*k*t)), k=-N:N
clear cla
N=[1,5,10,20]; % test value list
t=[-1:0.001:1]; % time range
xn=zeros(size(N,2),size(t,2)); % initialize value
for i=1:size(t,2) % x(t) – Original Sawtooth wave
if t(i) < 0
xt(i)=-2*t(i)-1;
else
xt(i)=-2*t(i)+1;
end
end
figure(1)
plot(t,xt)
grid on
title(‘Sawtooth wave’)
figure(2)
for i=1:4
for k=1:N(i) % when k=0, a0=0
xn(i,:)=xn(i,:)+2*sin(2*pi*k*t)/(pi*k);
end
subplot(2,2,i)
%hold on
plot(t,xn(i,:))
title(sprintf(‘N=%.d’,N(i)))
grid on
axis([-1 1 -1.5 1.5])
end
[/code]