MATLAB and Mathematica have different FFT normalization parameters. This is easy to change in Mathematica with the FourierParameters -> argument, but anything having to do with this in MATLAB seems to have been deprecated, or only working for the non-discrete case. So, I want to try and perform operations on my MATLAB FFT function to have it match the Mathematica one.

I start with fft([1 1 2 2 1 1 0 0]) in MATLAB: enter image description here

Then, exploring with the parameters in Mathematica:

enter image description here

Aha! So, the Mathematica parameters, {1, 1}, give me the values I got from MATLAB, while the Mathematica parameters {0, 1}, that are used for default Mathematica FFT behavior, seem to be scaling those of {1, 1} by a factor of (sqrt(2/pi)/2).

But oh no, applying that factor in MATLAB gives me enter image description here

which is close to, but not quite, the data I want. How can I replicate this correctly in MATLAB?


From the documentation, Mathematica defaults to defining y = Fourier[x] as:

$$ y_k = \frac1{\sqrt{n}} \sum_{j=1}^n x_j e^{2 \pi i (j-1) (k-1)/n} $$

From the documentation, MATLAB defaults to defining y = fft(x) as:

$$ y_k = \sum_{j=1}^n x_j e^{-2 \pi i (j-1) (k-1)/n} $$

MATLAB further defines x = ifft(y) as:

$$ x_k = \frac1n \sum_{j=1}^n y_j e^{2 \pi i (j-1) (k-1)/n} $$

As we can see, MATLAB's fft differs in the sign of the exponent from Mathematica's definition which makes it slightly more annoying to use as a substitute (you have to either time reverse things, or conjugate the answer and only work for real valued data), but MATLAB's ifft matches the Mathematica definition in all but normalization.

Thus we can make MATLAB emulate Mathematica's y = Fourier[x] for arbitrary complex data x via:

y = sqrt(length(x)) ifft(x)

We can equivalently also make Mathematica emulate MATLAB's y = fft(x) for real data via:

y = Sqrt[Length[x]] Conjugate[Fourier[x]]

... or, perhaps more idiomatically, and also for complex data:

y = Fourier[x, FourierParameters -> {1, -1}]
| improve this answer | |
  • $\begingroup$ For MATLAB, you would actually use ifft() instead if you want to emulate the Mathematica default: sqrt(length(x)) ifft(x). $\endgroup$ – J. M.'s discontentment Oct 24 '17 at 23:25
  • $\begingroup$ Sounds better. That also has the right behavior for complex data. I'm not familiar with MATLAB, so I literally just pieced together something that worked from the definitions in the documentation and seemed to work in Octave. I'll edit it. $\endgroup$ – user3047059 Oct 26 '17 at 9:11

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