function vtb3_3(N) %VTB3_3 Fourier Series approximation to a triangle wave. % VTB3_3(N) displays the N term Fourier approximation to a % triangular input. The approximation is plotted versus time % normalized by the period of the wave. The Fourier series is % the solid line and the actual wave is the dotted line. %Creates triangular wave tau1=0:.01:.5; Ftr1=(4*tau1-1); tau2=.51:.01:1; Ftr2=3-4*tau2; %Creates Fourier approximation tau=[tau1 tau2]; F=zeros(1,length(tau)); for i=1:N k=2*i-1; Ftmp=(1/k^2)*cos(k*2*pi*tau); F=F+Ftmp; end F=-(8/pi^2)*F; plot(tau1,Ftr1,'--',tau2,Ftr2,'--',tau,F,'-') title([int2str(N),' term Fourier series approximation to a triangular input']) ylabel('F(t)'); xlabel('time / period')