PDA

View Full Version : Fast Fourier Transform with Qt



giarandrea
7th May 2012, 22:58
Hello gurus,
I'm trying to implement FFT on my Qt program in order to find Fundamental frequencies (spectrum) of a time series..
So I have a Qvector<double> and i want to obtain some couples: <double,double> (frequency, amplitude).

Since it is "a bit long" to create the whole library, could you please suggest me some easy one? (and possible some tutorial/explanation on how to use it?)

thanks guys

d_stranz
7th May 2012, 23:29
Unless you are writing your own FFT, you probably can't easily use QVector<double> in a routine that expects double pairs. However, if all you need is a pointer to a C++-style array to pass to a library function, then use the QVector::data() method to obtain a double * pointer.

Most FFT libraries I have seen expect a single double * array of amplitude values and have an implied frequency that starts at zero. (The frequency array is in fact irrelevant in this case - the FFT expects the amplitude array to represent values at equal frequency intervals).

But maybe I don't understand your question.

ChrisW67
8th May 2012, 00:03
I you do not want to implement your own FFT routine in C or C++ then a couple of FFT libraries (http://lmgtfy.com/?q=fft+library) with different licenses can be trivially found.

giarandrea
9th May 2012, 22:56
thanks for your answers,
also a single double * array may be useful for my purpose, as explained above (right, the frequencies will not be stored in an array because they'll taken at regular intervals).
I've tried with both FFTW (which I was not able to import) and FFT Kiss, (also FFTReal). But i would like to know (since I'm quite new with Qt programming) if you know a simple tutorial, or a simple program which uses one of them to find the spectrum..
thanks again

P.S.: for FFT for example, when i do in my .cpp:
#include <fftw3.h>
my class myclass::function
{
fftw_complex *in, *out;
fftw_plan p;
}

fftw_plan is not automatically inherited as a type (purple colour)..so no plan can be defined..

ChrisW67
10th May 2012, 01:28
You do realise that this has nothing to do with Qt right? Qt is not a programming language, it is a set of libraries just like FFTW, Kiss FFT, OpenCV and multitudes of others are sets of libraries. C++ is the programming language. You need to understand C++, and the compiler/linker that allow you to create programs from source, before you can do much else. A little bit of effort in understanding now will save you much blind, thrashing about trying to make things work later.

If your compiler pre-processor cannot find headers you have included then code that depends on them will fail to compile. Note that this is a different thing to your text editor, which purple-ifies code, not being able to find the headers; the two may not agree but the code may still compile. You have assumed the fftw3.h file is in a system default location and that is not the case as far as the text editor is concerned. You have not said if the code compiles or not so I cannot say if the compiler is happy but I would guess it is not.

All compilers have ways to supplement their include and library search path. Qt's qmake has mechanisms to assist with this in a cross-platform fashion: INCLUDEPATH and LIBS. Qt even has information on how to use third-party libraries with qmake.