function [t,imp] = train(T,N) % Function [T,IMP] = TRAIN(T,N) creates a Fourier series approximation to a % train of impulses with period T using N harmonic terms each side of zero. % Three periods of the function are generated. ws = (2*pi)/T; % Sampling frequency in rad/s t = [0:0.001*T:3*T]'; % Create a column time vector over 3 periods with 1000 points/period imp = zeros(length(t),1); % Dummy array to hold impulse train for n = -N:N % FOR loop over the number of coefficients imp = imp + real(exp(j*n*ws*t)); % Ignore imag part (should be zero anyway) end;