# 13. Fast Fourier transform (FFT)

The discrete Fourier transform (DFT) computes the Fourier transform of the discrete data numerically. The inverse transform of DFT is called as the inverse discrete Fourier transform (IDFT). The algorithm called as the fast Fourier transform (FFT) allows us to compute DFT/IDFT very fast.

Examples of FFT computations by XLPack are shown below.

### Example 1

The following signal is the mixture of the 400Hz sine wave and the 1.4kHz sine wave.

We will compute DFT of the data of the above wave of 1/10000 second interval (refer to the manual on the data format of the transformed data), and then confirm the consistency of the transform by comparing the IDT of the DFT with original data.

WRfft1f worksheet function is used to compute DFT. The following is the example of DFT of 50 data points.

When DFT values are computed, IDT of those values are computed by WRfft1b worksheet function.

It has been confirmed as below that the original data are correctly restored.

### Example 2 (Power spectrum)

One of the typical applications of FFT is the power spectrum analysis.

Using the DFT result of N data f_{j}, the power at frequency f_{k} is computed as follows. Where f_{k} = (k/N) f_{s} , f_{s} is the sampling frequency.

P_{0}= P(f_{0}) = N |F_{0}|^{2}= N a_{k}^{2}P_{k}= P(f_{k}) = N (|F_{k}|^{2}+ |F_{N-k}|^{2}) = (N/2)(a_{k}^{2}+ b_{k}^{2}) (k=1 to N/2-1) P_{N/2}= P(f_{N/2}) = N |F_{N/2}|^{2}= N a_{N/2}^{2}(if N is the even number)

The total energy is computed as the sum of the power over all time.

E = Σ P_{k}(Σ for k=0 to N/2)

Now, let’s compute the power spectrum of the DFT values of the above example.

The following VBA function is used to compute the power.

Function PsdR(N As Long, VR As Variant) As Variant Dim R() As Double, P() As Double, I As Long ReDim R(N - 1), P(N / 2, 0) For I = 1 To N R(I - 1) = VR(I) Next P(0, 0) = N * R(0) ^ 2 For I = 1 To N - 3 Step 2 P((I + 1) / 2, 0) = (N / 2) * (R(I) ^ 2 + R(I + 1) ^ 2) Next P(N / 2, 0) = N * R(N - 1) ^ 2 PsdR = P End Function

The input data is set to this function as below.

A plot of power versus frequency is as follows (this is called the periodogram).

We see that the signal consists of 400Hz and 1.4kHz sine waves.