Should `fourier transform of real data` be complex data?

84 Views Asked by At

I am using mathematica and python to fourier transform the same list. Result as below:

##python

t = np.arange(10)
s = np.sin(0.15*2*np.pi*t)
S = np.fft.fft(s)
print(S)

[ 1.96261051+0.00000000e+00j  3.65687576-4.44089210e-16j
 -2.90211303+6.58456965e-16j -0.90211303+2.77704128e-16j
 -0.57919222+1.15109392e-16j -0.50952545-5.24550760e-18j
 -0.57919222-1.15109392e-16j -0.90211303-2.69216718e-16j
 -2.90211303-6.58456965e-16j  3.65687576+4.40847308e-16j]

##mathematica

t = Range[0, 9]
s = Sin[0.15*2*Pi*t]
Fourier[s,FourierParameters-> {1,-1}]
{1.96261, 3.65688, -2.90211, -0.902113, -0.579192, -0.509525, \
-0.579192, -0.902113, -2.90211, 3.65688}

I am not sure which one is correct.Should fourier transform of real data be complex data?

1

There are 1 best solutions below

0
On BEST ANSWER

In general, the Fourier transform of real data can be complex. Any odd integrable function will do the trick; for example, if $$f(x)=\begin{cases}1&0<x<1\\-1&-1<x<0\\0\text{ otherwise}\end{cases}$$ then $$\mathcal{F}(f)(\omega)=i\frac{\cos{\!(\omega)}-1}{\omega}$$ (up to a constant normalization factor; see e.g. this MSE question) which is purely imaginary.

With that said, in your case, both Fourier transforms are real! The reason Python and Mathematica are giving superficially different answers is just roundoff: the imaginary part of 3.65687576-4.44089210e-16j is $$-4.44089210\cdot10^{-16}\approx 2^{-51}$$ IEEE 754 uses 53 bits of precision, so this is about four roundoff errors that did not cancel out.