FFT with Real Data

I have data corresponding to time and amplitude of a sound wave. The times are in even intervals (i.e. a measurement is taken every second). x[i] is the time of the ith measurement and y[i] is the corresponding amplitude at that time. How do I take the FFT of this data so that I have it in the frequency domain?

Any help would be greatly appreciated. Thank you in advance.

See the example of the FFTW interface at:

root.cern.ch/root/html/tutorials/fft/FFT.C.html

You want the ā€œR2Cā€ option. See FFTW documentation for the correspondence between the output bins and physically meaningful frequencies. I believe that you must also have FFTW installed and you have to have configured ROOT to use it when you installed ROOT (see ROOTā€™s installation instructions). Hope that helps.

Yes - thank you, I have already looked over that tutorial a great deal. It is difficult to understand because the tutorial does a number of different things all in the same code. Iā€™m not sure what applies directly to my problem. Could anyone please tell me which parts of the code specifically to use? Again, Iā€™m only trying to take the FFT of the data. Shouldnā€™t it be fairly straightforward?

Thanks again!

This may not be much simpler, but it is the simplest example I have that does a FFT like you want. I use it to transform time domain signals into frequency domain. It makes a simulated white noise time domain signal (or you can comment lines 55-60 and uncomment the lines above for a sawtooth wave). It will plot the original signal, the magnitude and phase of the complex transform and then do the inverse transform to show that you get back exactly the original signal (if you are careful about the way FFTW handles normalizations). The plots down the right column are some diagnostics that are likely not interesting to you (I wanted to diagnose the whiteness of my simulated noise). This file needs to be compiled, but I imaging you can easily run it in the CINT interpreter.
main.cpp (4.76 KB)

Thank you. That does help but I still canā€™t quite get it to work. Does anyone have anything simpler perhaps?

Hi,

What did you try? How did it fail?

Philippe.

1 Like

The step that fails is where I try to actually take the fft. Again, my data is in arrays called x and y where x is the time and y is the amplitude. If I try:

TH1 *funcfft = 0; funcfft = y->FFT(funcfft,"MAG R2C M");

the error is: non class,struct,union object y used with . or ->

What should I have there instead of simply y? I must admit Iā€™m a little confused with the syntax. Thanks again!

Hi,

What is ā€˜yā€™ in this context? In the example you gave I think it was ā€˜fft_invā€™?

Philippe.

In the example posted by Brent, fft_inv is used for the inverse transform. But the one I want is the regular transform (R2C). So in Brentā€™s example, fft is what corresponds to y in my code.

y is an array with the amplitudes corresponding to the times given by x. Remember, this data is just representing a sound wave. Iā€™m not sure what to do with my data to make the ->FFT work properly.

Any thoughts, comments, or ideas?

I recommend re-reading: root.cern.ch/root/html/TVirtualFFT.html

Cheers,
Philippe.