Fourier transform. The fast and the furious

When I was faced with the task of writing a program for analyzing the transfer functions of sound systems in real time, I, like everyone else, first turned to fast conversion. Everything was fine, but with a large time window, the CPU load became indecently large and we had to do something about it. It was decided to pause and study the transformation again, and at the same time to look for ways to solve the problem. Returning to the original Joseph Fourier transform 2 :
Let's look carefully what is happening here. Each output value in the frequency domain
Getting rid of n
Let me remind you that initially there was the task of analyzing audio data in real time. For this, the selected time window (essentially a buffer) of size N is filled with data with a frequency f d corresponding to the sampling frequency. With the period T, the input data are converted from the time window to the frequency one. If you look at real numbers, then N varies from 2 14 (16 384) to 2 16 (65 536) samples (the values are inherited from the FFT, where the window size must be a power of two). The time is T = 80ms (12.5 times per second), which allows you to see quite conveniently the changes and not overload the CPU and GPU. F sampling rate dstandard and is 48kHz. Let's calculate how much data in the time window changes between measurements. During T, the buffer enters.
At this moment, the attentive reader will raise his hand and say: “Wait, what about the coefficient
For clarity, you can write in a table as the buffer will change:
| t = 0 | f (0) | f (1) | f (2) | f (3) | f (4) | f (5) | f (6) | f (7) | f (8) | f (9) |
| t = 1 | f (10) | f (1) | f (2) | f (3) | f (4) | f (5) | f (6) | f (7) | f (8) | f (9) |
| t = 2 | f (10) | f (11) | f (2) | f (3) | f (4) | f (5) | f (6) | f (7) | f (8) | f (9) |
| t = 3 | f (10) | f (11) | f (12) | f (3) | f (4) | f (5) | f (6) | f (7) | f (8) | f (9) |
| t = 4 | f (10) | f (11) | f (12) | f (13) | f (4) | f (5) | f (6) | f (7) | f (8) | f (9) |
You can write how the transformation in time changes from t 1 to t 2 :
Value
For completeness, it remains only to indicate the initial state, but everything is simple:
* - of course, the ultimate complexity of the whole transformation will remain
And what if you dig deeper. Or get rid of the second n
I just want to make a reservation that the further steps are applicable only if you do not plan to reverse the result for the result (in order to correct the signal or obtain an impulse response). First of all, I want to remind you that as a result of the transformation, we get a symmetric array of data, which immediately reduces the number of transformations in half.
Now let's analyze the resulting data set, taking into account the conditions of the problem. We have a set of complex numbers, each of which describes the amplitude and phase of the oscillations at a certain frequency. Frequency can be determined by the formula:
Experimentally, you can find out that it is enough to have only 48 points per octave, and in order to have data a little more smooth and averaged, I suggest staying at 96. In the audio frequency range from 20 Hz to 20 kHz, it is easy to count only 10 octaves: 20, 40, 80 , 160, 320, 640, 1280, 2560, 5120, 10240, 20480, each of which can be divided into a given number of subranges (do not forget that the division should be performed geometrically, not arithmetically), therefore, it is more than enough to perform the conversion only for 960 frequencies to get Performan that in 16 ... 65 times smaller than the original version.
Thus, combining both approaches, we obtain the constant complexity of the execution of the data update algorithm.
Honey squared and fly in the ointment
Now we can safely say that the complexity
- after analyzing the task, we noticed that the data is added gradually, and the period of complete updating of the time window is much higher than the period of transformations and went on to calculate the difference of the Fourier transform.
- left from the arithmetic step in the frequency window to limited only by given values, which allows to drastically reduce the number of conversions.
But, of course, life would really be a fairy tale, if not for one thing. The use of these two approaches allowed us to really unload the CPU so that it guesses that it calculates the Fourier transform and displays the results on the screen even with
I also refused from the second step and returned to the FFT, since the gain in this problem was already small.
Finally
The first approach can be used if your data has a pronounced periodic nature and needs to be analyzed over time using a large time window, which, I recall, does not have to be a power of 2, i.e. any natural number.
The second approach is applicable (even taking into account window functions), if only a certain, small set of frequencies are analyzed in the data.
Alas, for me in this problem, it remains only a little mathematical entertainment, but I hope that it will inspire you to study other algorithms on holidays in terms of input data changes over time :)
Literature
The image was taken from the manio of Michio Shibuya. “Entertaining mathematics. ANALYSIS OF FOURIER