# How to calculate a numerical multidimensional Fourier series

The Fourier series tutorial here describes a number of different commands for numerically finding Fourier series and their coefficients. However, they only seem to work for one dimensional Fourier series. Is there an extension which includes multidimensional Fourier series? Specifically, I'm interested in being able to calculate a number of two dimensional Fourier series coefficients numerically.

As an example, find the Fourier coefficients of

$$\ln(4(\cos(\theta)-\cos(\phi))^{2}+(\sin(\theta)-\sin(\phi))^{2})$$

on the rectangle $$0<\theta,\phi<2\pi$$.

Thanks in advance for any help.

• The added $\ln$ just made this question non-trivial, so I'd vote against closing. Aug 23, 2020 at 10:24
• Yes, sorry about that. I didn't mean to give an example that could be done analytically so I made the example more complicated. Aug 24, 2020 at 11:37

For your original example, TrigToExp does what you need:

4 (Cos[θ] - Cos[φ])^2 + (Sin[θ] - Sin[φ])^2 // TrigToExp

(*    5 + 3/4 E^(-2 I θ) + 3/4 E^(2 I θ) - 3/2 E^(-I θ - I φ) -
5/2 E^(I θ - I φ) - 5/2 E^(-I θ + I φ) - 3/2 E^(I θ + I φ) +
3/4 E^(-2 I φ) + 3/4 E^(2 I φ)                                  *)


For more complicated functions without an explicit exponential structure, you can evaluate the Fourier integrals explicitly:

f[θ_, φ_] = Log[4 (Cos[θ] - Cos[φ])^2 + (Sin[θ] - Sin[φ])^2 + 1];

F[a_?NumericQ, b_?NumericQ] := 1/(2 π)^2 * NIntegrate[
f[θ, φ] * E^(-I*{a, b}.{θ, φ}), {θ, 0, 2 π}, {φ, 0, 2 π}]


For example, sum up all Fourier components up to order 2:

g[θ_, φ_] = Sum[F[a, b]*E^(I*{a, b}.{θ, φ}), {a, -2, 2}, {b, -2, 2}] // Chop

(*    1.48242 +
0.0545782 E^(-2 I θ) +
0.0545782 E^(2 I θ) -
0.0291498 E^(I (-2 θ - 2 φ)) -
0.136866 E^(I (2 θ - 2 φ)) -
0.224188 E^(I (-θ - φ)) -
0.517258 E^(I (θ - φ)) +
0.0545782 E^(-2 I φ) +
0.0545782 E^(2 I φ) -
0.517258 E^(I (-θ + φ)) -
0.224188 E^(I (θ + φ)) -
0.136866 E^(I (-2 θ + 2 φ)) -
0.0291498 E^(I (2 θ + 2 φ))    *)

Plot3D[{f[θ, φ], Re[g[θ, φ]]}, {θ, 0, 2 π}, {φ, 0, 2 π}] • It is not so simple: you consider f[θ_, φ_] = Log[4 (Cos[θ] - Cos[φ])^2 + (Sin[θ] - Sin[φ])^2 + 1]; instead of f[θ_, φ_] = Log[4 (Cos[θ] - Cos[φ])^2 + (Sin[θ] - Sin[φ])^2 ];. Even very powerful mapleprimes.com/posts/89226-WithOrthogonalExpansions fails with the latter. Aug 25, 2020 at 20:38
• @user64494 did you try it out? Your example works just fine with my code. Aug 25, 2020 at 20:43
• I see what you've done, but one could just as easily obtain the one-dimensional Fourier coefficients numerically using NIntegrate rather than NFourierSeries. I'm really wondering why NFourierSeries exists only for one dimension. This is because I believe built-in Mathematica operations are meant to be faster like NFourierSeries are supposed to be quicker than doing all the NIntegrates separately and I'm wanting to calculate quite a few of these Fourier series. Aug 27, 2020 at 10:54