Wednesday, March 31, 2010

Real Time 1D FFT

Another project using FFT, this time I need to have a 1-D FFT transform for analyzing frequency component of a signal. I have an idea to do this FFT real time and show it using my previous technique for GUI using openCV.

I found the reference for making 1D FFT from this website and I modified the source code to work with my compiler and highgui library from OpenCV for showing the result.

For the data buffer, I created a circular buffer using std::deque, continuously updating the buffer using timer and show it into the screen. Currently my FFT class needs an array as the input, so there's an overhead for converting the std::deque to array, so I'm planning to modify my source code for handling std::deque directly for saving processing time.

The data is generated by using a TTimer (not really accurate though.. :( ) and it is sampled by another TTimer. I am planning to move to multimedia timer instead because it is faster and more accurate. The screenshot of the output from this circular buffer is as follow:

And the output of the frequency spectrum is as follow:

The sampling frequency is 250 Hz and the signal source is 50Hz. I am going to use multimedia timer instead for faster sampling time. One thing that I found is that the update rate of my real time viewer is limited to several milliseconds (2-3 ms).

The detail of the FFT source code can be found in this website so I won't post it here and also you can read the "Numerical Recipes in C" book which is quite a good book for programmers.

Labels: , , ,

Monday, March 29, 2010

Real Time FFT using OpenCV

Recently I tried to combine Fast Fourier Transform with my previous webcam project with OpenCV. I use cvDFT() function to generate forward FFT of the image.

The result is surprising, it's quite fast. I tried using my Logitech Quickcam and I can generate the FFT of the image in real time. I will post the details later because I combined it from several sources and had to do some modification to make it run real time without having memory leak issues.

Here's a screenshot:

Another screenshot with a sine grating as the object. If you understand how 2D FFT works, you might have an idea whether this is correct or not.

My webcam runs 15fps and the size of the image is 320x240. I'm going for a faster and larger camera, and doing IFFT, just wait and see, hehehe... :D

Actually this is not directly related to my job, I did this mainly for fun and curiosity :D.

Labels: , , ,