# Python FFT outptut

I have a (real) array of data and am trying to analyze its frequency components. I've been using NumPy's FFT routines, but I realized there is something I don't quite understand: why does the output give me an imaginary part?

Of course I know that in general the Fourier transform is complex-valued, but it seems to me that the DFT is sampling frequencies that are integer multiples of the timestep of my original data trace. Shouldn't I then be getting results that lie only on the real axis?

What am I missing here?

• It's still about the basic Fourier transform. If all of your sinusoidal components were cosine, not sine, (which means that $x[N-n]=x[n]$), then all of your frequency components would be purely real, whether they are exactly an integer FFT bin location or not. if all of the sinusoidal components were sine, not cosine, (which means that $x[N-n]=-x[n]$) then every frequency component in the FFT would be purely imaginary. if the phase was somewhere between a cosine and a sine, then you will have non-zero real and imaginary parts. – robert bristow-johnson Jun 11 '19 at 20:40
• Thanks for the reply. I'm trying to analyze correlation/anti-correlation (in the frequency domain) of two different sets of data, so I am taking the Fourier transform of the cross-correlation function to try to get at cross-spectra, but I want to preserve potential anti-correlation so I don't want to simply take the magnitude of the FT. Are you suggesting there is a way I can modify the numpy function to get purely real frequency components? My data is very much non-periodic, so maybe what I'm trying to do is not even possible? – Dario Rosenstock Jun 11 '19 at 20:48
• as rbj said, if your signal (in this case, the crosscorrelation) isn't even-symmetrical, then you get a complex spectrum; just looking at the real part of that is simply dropping half of the information. So, to answer your question: No, the result should not only lie on the real axis. – Marcus Müller Jun 11 '19 at 22:26
• This article should give you an intuitive understanding of what a bin value means for a pure real tone in a DFT: dsprelated.com/showarticle/768.php If you "get it", and "it" follows directly from the definition, then you will understand why the imaginary part is intrinsic. Note, this is not a common understanding, but it is a good one. – Cedron Dawg Jun 11 '19 at 22:30
• @robertbristow-johnson but look at this: fft(cos(2*pi*[0:3]/20)) ans = 3.3479 (0.1910 - 0.3633i) 0.2702 (0.1910 + 0.3633i) So non integer DFT bin of cos yields complex result... – Fat32 Jun 12 '19 at 8:52