How to calculate the complex Fourier coefficients and its partial sum?

Using complex exponentials (without FourierTrigSeries):

\begin{align*} f(x) &= \sum\limits_{ - \infty}^{ + \infty} {{c_n}{e^{2 \cdot \pi \cdot i \cdot n \cdot t/T}} = } \sum\limits_{ - \infty}^{ + \infty} {{c_n}{e^{i \cdot n \cdot w \cdot t}}} \\ {c_n} &= \frac{1}{T}\int_{ - T/2}^{T/2} {f(t){e^{ - i \cdot n \cdot w \cdot t}}dt} \end{align*}

find the coefficients and plot one partial sum of this.

We have function

f[x_] := Which[-1 < x < 0, 1, 0 < x < 1, 0]


Which of the following are correct?

c[n_] := (1/T)*Integrate[f[t]*Exp[(-I*n*w*t)/T], {x, -T/2, T/2}]

c[0] := (1/(2*T))*Integrate[f[x], {x, -T/2, T/2}]

T=2;
c[n]

F[x_, N_] := Sum[c[n]*Exp[(I*n*w*t)/T], {n, 1, N}]

p[N_, c_]:=Plot[Evaluate[F[x, N]], {x, -10, 10}, PlotRange -> All, PlotPoints -> 200, PlotRange -> All, Frame -> True]

p[10, 5]

• Are you still looking for an answer? – zhk Feb 9 '17 at 14:31
• Yes, thanks for help! – Jonathan Feb 12 '17 at 13:15
• Then accept my response as an answer – zhk Feb 12 '17 at 13:39

Apart from some random issues, you were on the right track.

f[x_] := Which[-1 < x < 0, 1, 0 < x < 1, 0];
T = 2*Pi;
c[n_] := (1/T)*Integrate[f[x]*Exp[(-I*n*w*x)], {x, -T/2, T/2},Assumptions ->
Element[n, Integers]];
F[x_, N1_] := Sum[c[n]*Exp[(I*n*w*x)], {n, -N1, N1}];
w=1;
Plot[{Piecewise[{{1, -1 < x < 0}, {0, 0 < x < 1}}],Evaluate[F[x, 55]]}, {x, -1, 1},
PlotRange -> All,Frame -> True]


For N1=1000

You can also use Mathematica built-in function FourierSeries to generate complex Fourier series,

FSbuiltin = FourierSeries[f[x], x, 55];
Plot[{FSbuiltin,Piecewise[{{1, -1 < x < 0},{0, 0 < x < 1}}],Evaluate[F[x, 55]]},{x, -1, 1},
PlotRange -> All,PlotStyle -> {Blue, Green, Directive[Red, Dashed]}, Frame -> True]