function [y coeff] = sawtooth(x,M) % SAWTOOTH % % Finite Fourier Series evaluation of sawtooth wave % % [y coeff] = sawtooth(x,M) % % where x are the values to evaluate (-0.5<x<0.5) % M is the number of terms to use % p = (1:M)'; coeff = -cos(pi*p)./(pi*p); c = coeff*ones(size(x)); d = sin(2*pi*p*x); y = 2.0*sum(c.*d); end