Plot[Sin[t],{t,0,4 Pi},PlotRange -> {-1.1,1.1},AxesLabel->None, PlotStyle -> Thick]

Plot[Sin[2t],{t,0,4 Pi},PlotRange -> {-1.1,1.1},AxesLabel->None, PlotStyle -> Thick]

f1[x_] = If[x<0,-1,+1];
a[n_] = If[n>0,Integrate[f1[x] Cos[n *Pi* x] ,{x,-1,1}],2*Integrate[f1[x],{x,-1,1}]]
b[n_] =Integrate[f1[x] Sin[n*Pi*x],{x,-1,1}]

fourier[nmax_,x_]:= a[0]+Sum[a[nn]*Cos[nn*Pi*x]+b[nn]*Sin[nn*Pi*x],{nn,1,nmax}]

fourierfast[nmax_,x_] := Sum[((2-2 Cos[nn π])/(nn π))*Sin[nn*Pi*x],{nn,1,nmax}]

Manipulate[Plot[fourierfast[nmax,x],{x,-1,1}],{nmax,1,150}]

f2[x_] = x;
a[n_] = If[n>0,Integrate[f2[x] Cos[n *Pi* x] ,{x,-1,1}],2*Integrate[f2[x],{x,-1,1}]]
b[n_] =Integrate[f2[x] Sin[n*Pi*x],{x,-1,1}]

fourierfast2[nmax_,x_] := Sum[((-2 nn π Cos[nn π]+2 Sin[nn π])/((nn^2) (π^2)))*Sin[nn*Pi*x],{nn,1,nmax}]

Manipulate[Plot[fourierfast2[nmax,x],{x,-1,1}],{nmax,1,150}]