Phys 238
Fourier Series Representation of a Square Wave

f[t_] := Piecewise[{
{-A,-T/2 ≤ t ≤ 0},
{ A , 0 < t ≤ T/2}
}]

A = 5.0;
T = 10.0;

Plot[f[t], {t, -T/2, T/2}]

Fourier Transform

Nmax = 20;

ω[n_] := n * (2 π/T)

a[n_] := (2/T) Integrate[f[t] Sin[ω[n] t], {t, -T/2, T/2}]

a[1]

a[1] / (A 4/π)

as = Table[a[n], {n, 1, Nmax}]

as / (A 4/π)

ListPlot[as, Joined->True, Mesh->All, PlotRange->All]

fs[nmax_, t_] :=  Sum[as[[n]] Sin[ω[n] t], {n, 1, nmax}]

fs[3, t]

Manipulate[Plot[{f[t],fs[nmax, t], as[[nmax]] Sin[ω[nmax] t]}, {t, -T/2, T/2}, 
LabelStyle->Larger, AxesLabel -> {"t", "f(t)"}, ImageSize -> Scaled[0.8]], {nmax, 1, Nmax, 2, Appearance->"Open"}]

Analytic Result

fsum[nmax_, t_] := Sum[(4 A /π) (1/n) Sin[ω[n] t], {n, 1, nmax, 2}]

Plot[fsum[999, t], {t, -T/2, T/2}]