I came by this post when searching for a way to plot a amplitude spectrum. This helped me out.
I noticed that the plot showed amplitudes that are to large. They fit when looking at S, however not to f. I would expect amplitudes of 1/Pi for all the components (as shown in the results below where I used a bit messy code to show the same information using the complex fourier coefficient). What am I missing here?
q := proc (n) options operator, arrow; (int(f*exp(-(2*I)*n*Pi*t/T), t = -(1/2)*T .. (1/2)*T))/T end proc;
A := evalf(`<,>`(seq(2*q(n), n = -10 .. 10)));
DiscretePlot(A, -10, 1, style = stem, gridlines = true);