Fourier Series

Periodic function

f(t)={({{0  (N + 0.5  <  t  <  N)}, {1 (N  <  t  <  N + 0.5)}})

f[t_] := 
        If[OddQ[Floor[2  t + 1]], 1, 0];
Plot[f[t], {t, -2, 2}, 
      PlotRange -> {{-2, 2}, {-0.5, 1.5}}, 
      AspectRatio -> 1/2, 
      PlotStyle -> RGBColor[1, 0, 0]]

Express  this function with a Fourier series:

f (t)=(lim_(M → +∞))(1/(Sqrt[T])) (∑_(n = -M)^(+M))(Subscript[f, n]) (e^(2  nπit/T))

Approximation at M=0

M = 0; 
    Plot[{f[t], 
        1/2 + Sum[2/Pi/M Sin[2  Pi n t]* If[OddQ[n], 1, 0], {n, 1, 
              M}]}, {t, -3, 3}, AspectRatio -> 2/4, 
      PlotRange -> {{-2, 2}, {-0.5, 1.5}}, 
      PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]

Approximation at M = 1

M = 1; 
    Plot[{f[t], 
        1/2 + Sum[2/Pi/n Sin[2  Pi n t]* If[OddQ[n], 1, 0], {n, 1, 
              M}]}, {t, -3, 3}, AspectRatio -> 2/4, 
      PlotRange -> {{-2, 2}, {-0.5, 1.5}}, 
      PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]

Approximation at M = 3

M = 3; 
    Plot[{f[t], 
        1/2 + Sum[2/Pi/n Sin[2  Pi n t]* If[OddQ[n], 1, 0], {n, 1, 
              M}]}, {t, -3, 3}, AspectRatio -> 2/4, 
      PlotRange -> {{-2, 2}, {-0.5, 1.5}}, 
      PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]

Approximation at M = 5

M = 5; 
    Plot[{f[t], 
        1/2 + Sum[2/Pi/n Sin[2  Pi n t]* If[OddQ[n], 1, 0], {n, 1, 
              M}]}, {t, -3, 3}, AspectRatio -> 2/4, 
      PlotRange -> {{-2, 2}, {-0.5, 1.5}}, 
      PlotStyle -> {RGBColor[1, 0, 0], RGBColor[0, 1, 0]}]

ShowAnimation[fourierinput, AnimationDisplayTime -> 50]

A Solution to the differential equation:

fourieroutput = 
        Table[Plot[
            1/2 + Sum[
                1/(1 - (2  Pi (2  n + 1))^2)*2/
                      Pi/(2  n + 1) Sin[2  Pi (2  n + 1) t], {n, 
                  0, M}], {t, -3, 3}, 
            PlotRange -> {{-3, 3}, {0, 1}}, 
            DisplayFunction -> Identity], {M, -1, 50, 
            2}];

ShowAnimation[fourieroutput]

Animate[Plot[Sin[n x], {x, -10, 10}], {n, 1, 10}]