Fast Fourier Transform in Real Time

In summary, the conversation discusses the issue of performing a DFFT on real-time streaming sensor data, and the challenges that come with it such as speed and accuracy. Various approaches are suggested, including performing the DFT once and modifying each element using a formula, or doing a completely new DFT every few samples. The importance of windowing and the feasibility of doing this on a desktop computer are also mentioned.
  • #1
olbert
3
0
I guess this is programming and physics all combined into one but hopefully I can get some help anyway.

I am doing some signal analysis of real-time streaming sensor data. I would like to do a DFFT on the data in real time as it streams in. So far pretty easy, however, there are a number of issues that make it more complicated - not the least of which is that I haven't dealt with FFT's since university.

Firstly I only want to do a transform on the most recent block of data, ie, I only want to know the frequencies from the last 10 seconds. Any data older than that is already out of date and useless.

Speed is a major issue as I want the spectrum of the data to be always up to date. Every new sample that comes in I want a new spectrum.

I was hoping that there was a function that calculate the transform one sample at a time and also remove a sample once it's too old. So in other words, in my program call the function 'FFT = FFT_Add_New_Sample(newSample);' and then call the function 'FFT = FFT_Remove_Old_Sample(oldSample);' once a sample becomes to old.

The idea would be that the whole FFT would not be recalculated with every new sample, just modified speedily with the new data coming in and old data going out.

I have no idea if this is even mathematically possible but if it was, it would be a great help!
 
Physics news on Phys.org
  • #2
I wouldn't use FFT for this, except maybe for the first block of samples. Once you have a DFT of N elements, you can compute contribution from the 1st element, and subtract it from each component of DFT. You can then shift samples back, which will be rotation by 2nPi/N in complex plane, and and add a new Nth sample by computing its contribution for each component. Of course, it's easier to do this for each component at a time, so your overall operation of removing an old sample and adding a new one is just order O(N), which is probably not too bad for real time, depending on your sample rate and value of N.
 
  • #3
You haven't told us the most important thing: what is the sampling rate and how many samples are in the "10 seconds" of data for your FFT.

If you are taking 1 sample per second doing this is trivial. For 1 million samples per second it's impossible.

Another question is how you are going to use with each set up updated frequencies, and whether you really need an update for every sample, or whether an update every n samples is good enough (where n might be smaller than the number of samples in each FFT, but not 1)
 
  • #4
At the moment, the data is coming in at 120Hz, and there is a possibility I might want to do it on multiple 120Hz streams of data.

It should be possible to perform the calculation on every few samples or a summary of a few sample rather than every single new sample.

The problem is that this isn't the only calculation I will be doing, I am doing a bunch of things concurrently, so that even if I can do what I want to with the FFT in a reasonable time, it might still be too much.

In other words, I am looking towards speed rather than accuracy (though clearly there has to be some level of accuracy to be useful).
 
  • #5
Ok, so here is my summation:

Do the DFT properly once to get the sequence X. Then modify each element of X using the following formula:

Xk,t+1 = Xk,t e-i2Pi(k/N) - xt-tN + xt+1 e-i2Pi(k/N)

Where:
- X is the spectrum of x.
- N is the number of elements in both X and x (and also in the time period tN)
- t is the time instant that this occurs.
- t+1 is the next time instant that a new element is received from the sensor.
- Xk is the kth element of the sequence X.

Is this correct? Is this a reasonable approach? Am I reinventing the wheel?
 
Last edited:
  • #6
You could do something like that, but it takes O(n) operations for each new data point where n is the length of the FFT.

But doing a completely new DFT only takes O(n log n) operations, so you aren't saving much.

You are also ingnoring windowing. If you don't use a windowing function your DFT will contain a lot of "noise", becuse effectively you are taking a set of data samples and sticking an infinite number of copies end to end to make a periodic function, but ignoring the fact that the arbitrary end points don't "match up" properly. If you include a simple window (e.g. Hanning or Hamming) the FFT data will look nicer, but trying to add and remove one sample at a time is more complicated.

I would consider just doing a new DFT every "k" samples, where k is the smallest number you can use depending on your computer. For your low sampling rate k won't be very big, and it might even be 1.
 
  • #7
Are you constrained to using a desktop computer?
 
  • #8
120Hz? Forget the fancy talk. That's so slow that you can even do this in Matlab on a PC and still keep up in real time!

10 seconds of data have 1200 samples, and you have 8.3 ms to take the transform before the next sample arrives. A 2048 point FFT takes an average of 35 us to compute in Matlab on my PC, even with Outlook, Excel, Firefox and everything else running in the background. (I just tried it.)
 
  • #9
marcusl said:
10 seconds of data have 1200 samples

For some reason I mis-remembered the OP as saying 10 minutes of data not 10 seconds - which would make it a bit more challenging, but not obviously impossible.
 

Related to Fast Fourier Transform in Real Time

1. What is the Fast Fourier Transform (FFT)?

The Fast Fourier Transform is a mathematical algorithm used to quickly and efficiently calculate the frequency components of a signal or set of data. It converts a signal from its original time domain into a frequency domain representation, making it easier to analyze for specific frequencies and patterns.

2. How does the FFT work?

The FFT works by breaking down a signal into smaller segments, known as sub-signals, and calculating the frequency components of each sub-signal. These components are then combined to create a complete frequency spectrum of the original signal. This process greatly reduces the number of computations required compared to traditional methods, making it much faster and more efficient.

3. What is real-time FFT?

Real-time FFT refers to the ability to perform the FFT algorithm in real-time, meaning it can process and analyze data as it is being generated. This is important in many applications, such as audio and video processing, where a continuous stream of data is being analyzed and processed in real-time.

4. What are the benefits of using FFT in real-time?

The main benefit of using FFT in real-time is the speed and efficiency it provides. Real-time FFT allows for the quick and accurate analysis of data as it is being generated, making it ideal for applications that require fast processing, such as real-time audio and video analysis. It also allows for real-time adjustments and feedback based on the analyzed data.

5. What are some applications of real-time FFT?

Real-time FFT has numerous applications in various fields, including audio and video processing, signal processing, telecommunications, and medical imaging. It is used in speech and sound recognition, noise cancellation, data compression, and many other areas where real-time analysis and processing of data is necessary.

Similar threads

Replies
3
Views
4K
Replies
3
Views
534
  • Other Physics Topics
Replies
1
Views
1K
  • General Math
Replies
12
Views
1K
  • Other Physics Topics
Replies
1
Views
3K
Replies
2
Views
2K
Replies
6
Views
1K
Replies
2
Views
2K
  • Classical Physics
2
Replies
47
Views
2K
  • Other Physics Topics
Replies
4
Views
7K
Back
Top