Why do I get two frequency spikes from a simple sin function through FFT in R?

I learned about the Fourier transform in math classes and thought I understood them. Now I am trying to play with R (statistical language) and in practice interpret the results of a discrete FFT. This is what I did:

x = seq(0,1,by=0.1) y = sin(2*pi*(x)) calcenergy <- function(x) Im(x) * Im(x) + Re(x) * Re(x) fy <- fft(y) plot(x, calcenergy(fy)) 

and get this plot:

energy density spectrum of sin (2 * pi * (x)) from 0 to 1 with a 0.1 step

If I understand this right, this represents "half" of the energy density spectrum. Since the transformation is symmetrical, I could just flip all the values โ€‹โ€‹to negative x values โ€‹โ€‹to get the full spectrum.

However, I donโ€™t understand why I get two spikes? There is only one sine frequency here. Is this a smoothing effect?

In addition, I do not know how to get frequencies from this plot. Assume that the units of the sinus function were seconds, this is a peak at 1.0 in the density spectrum of 1 Hz, then?

Again: I understand the FFT theory; practical application is a problem :).

Thanks for any help!

+7
source share
2 answers

For a purely real input signal of N points, you get a complex output of N points with complex conjugate symmetry near N / 2. You can ignore output points above N / 2, since they do not provide any useful additional information for the real input signal, but if you close them, you will see the above symmetry, and for one sinusoidal wave you will see peaks on the bunkers n and N - n . (Note: you can think of the upper N / 2 cells as negative frequencies.) Thus, for a real N point input, you get N / 2 useful complex output FFT trays that represent frequencies from DC (0 Hz) to Nyquist (Fs / 2).

+10
source

To get the frequencies from the FFT result, you need to know the sample rate of the data that was entered into the FFT and the length of the FFT. The center frequency of each hopper is the hopper index multiplied by the sampling frequency divided by the length of the FFT. This way you get frequencies from DC (0 Hz) to Fs / 2 halfway.

The second half of the FFT results is simply a complex pairing of the first for real data inputs. The reason is that the imaginary part of complex conjugations is canceled, which is required to represent a summed result with zero imaginary content, for example. strictly real.

+2
source

All Articles