1
$\begingroup$

I am trying to get the coefficients of the classical Fourier Series from Mathematica's Fourier Transform.

Now as I understand, Mathematica provides the Fourier Series coefficients:

f[x_]:=Cos[t]

Table[{n, FourierCoefficient[f[t], t, n]}, {n, 0, 3}]

{{0, 0}, {1, 1/2}, {2, 0}, {3, 0}}

I should be able to retrieve the coefficients from the Discrete Fourier Transform:

NN = 10
dt = (2 Pi/NN)
min = -Pi
max = Pi - dt

(* samples *)
fd = Table[N[{t, f[t]}], {t, min, max, dt}]

(* DFT *)
Fd = Chop[Fourier[fd[[All, 2]], FourierParameters -> {-1, 1}]]

{0, -0.5, 0, 0, 0, 0, 0, 0, 0, -0.5}

How can I write a function that gives as an output something similar to the Table of FourierCoefficient?

$\endgroup$

1 Answer 1

1
$\begingroup$

There are several pitfalls here. First, plot the data you use for the Fourier coefficients (note, only the y values are used. The x values are assumed to be 0,1,2,..):

f[x_] := Cos[t];
NN = 10;
dt = (2 Pi/NN);
min = -Pi;
max = Pi - dt;
fd = Table[N[f[t]], {t, min, max, dt}];
ListPlot[fd]

enter image description here

You see, this is -Cos not Cos. Therefore, for a comparison, you need to Fourier transform of -Cos:

f[t_] := -Cos[t];
Fd = Chop[Fourier[fd, FourierParameters -> {-1, 1}]]

{0, -0.5, 0, 0, 0, 0, 0, 0, 0, -0.5}

Note that the firs coefficient belongs to the constant part (zero frequency), the second to the pos. lowest freq.,.., the sixth to the highest freq. and the last to the negative lowest frequency)

Second, for a Fourier series, you not only need the positive frequencies, but also the negative ones. That means you need the coefficients from -3,-2...0..3:

f[t_] := Cos[t];    
Table[{n, FourierCoefficient[f[t], t, n]}, {n, -3, 3}]
    
{{-3, 0}, {-2, 0}, {-1, -(1/2)}, {0, 0}, {1, -(1/2)}, {2, 0}, {3, 0}}

Now you see that the coefficients No. -1 and 1 correspond to the neg. and pos. freq. coefficients of the Fourier transform.

Addendum

Note that Fourier with FourierParameters {-1,1} is defined with base sequence Exp[2Pi I r s] and FourierCoefficient with default parameters with base functions Exp[-2Pi I n t]. Note the minus sign. For a comparision, you must use matching base functions.

$\endgroup$
9
  • 1
    $\begingroup$ Did you mean f[t_]:=Cos[t]. It didn’t make any difference in your table because t wasn’t defined—but I’m guessing that that was a typo. $\endgroup$ Jul 20, 2023 at 21:04
  • $\begingroup$ Thanks, it is corrected. $\endgroup$ Jul 21, 2023 at 6:50
  • 1
    $\begingroup$ But it is correct: {0, 0. + 0.5 I, 0, 0, 0, 0, 0, 0, 0, 0. - 0.5 I}{-1., 0. + 0.5 I} corresponds to {{-3, 0}, {-2, 0}, {-1, I/2}, {0, 0}, {1, -(I/2)}, {2, 0}, {3, 0}} $\endgroup$ Jul 21, 2023 at 13:17
  • 1
    $\begingroup$ Fourier with FourierParameters {-1,1} is defined with base sequence Exp[2Pi I r s] and FourierCoefficient with default parameters with base functions Exp[-2Pi I n t]. Note the minus sign. $\endgroup$ Jul 22, 2023 at 18:29
  • 1
    $\begingroup$ Yes, you must match the base functions, either both with a neg. sign or pos. $\endgroup$ Jul 23, 2023 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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