1
$\begingroup$

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]
$\endgroup$
3
  • $\begingroup$ Are you still looking for an answer? $\endgroup$ – zhk Feb 9 '17 at 14:31
  • $\begingroup$ Yes, thanks for help! $\endgroup$ – Jonathan Feb 12 '17 at 13:15
  • $\begingroup$ Then accept my response as an answer $\endgroup$ – zhk Feb 12 '17 at 13:39
2
$\begingroup$

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]

enter image description here

For N1=1000

enter image description here

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]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.