# Fourier Coefficients in Mathematica [duplicate]

I'm calculating Fourier Coefficients by hand and trying to verify them in Mathematica.

However, in Mathematica I get them wrong by a factor of 2. Is there some part of the Mathematica functions I'm missing or am I doing something else wrong?

What almost makes me think there is something wrong with Mathematica is that $c_0$ should be equal to $1/2 a_0$. When computing by hand $c_0$ is indeed $1/4$ but $a_0$ should be $1/2$ (as I get by hand) and not 1 as Mathematica tells me.

Here is my code:

g[x_] := Piecewise[{{0, -Pi < x < 0}, {1, 0 < x < Pi/2}, {0,
Pi/2 < x < Pi}}]

makeper[f_, L_, offset_] := f[Mod[#, L, offset]] &

gTest = makeper[g, 2*Pi, -Pi]

Plot[gTest[x], {x, -4*Pi, 4*Pi}, PlotRange -> {0, 1},
Ticks -> {{-4 Pi, -3 Pi, -2 Pi, -Pi, 0, Pi, 2 Pi, 3 Pi, 4 Pi}, {-1,
0, 1}}, Filling -> Axis]

FourierCoefficient[gTest[x], x, n]

FourierCoefficient[gTest[x], x, 0]

FourierSinCoefficient[gTest[x], x, n]

FourierCosCoefficient[gTest[x], x, n]

FourierCosCoefficient[gTest[x], x, 0]


Any help would be appreciated!

• Check the documentation for the setting of FourierParameters option. – Daniel Lichtblau Nov 6 '12 at 21:58
• This is answered in the docs for every one of the Fourier functions you've used – Rojo Nov 6 '12 at 23:31
• Reading the docs I think I want to use FourierParameters -> {-1, 1/(2 Pi) but that gives me really strange answers. Any help with the parameters? @Rojo – user48441 Nov 6 '12 at 23:38
• Can you share either by link or simply writing it, the definition you are using to get the coefficients by hand? – Rojo Nov 6 '12 at 23:45
• As already noted, FourierParameters is there, since each field that uses Fourier series has a favorite convention. If you'll mention what convention you're using, we could be more helpful... – J. M. is in limbo Nov 7 '12 at 3:54