Learning Content and Theses

Platform for digital learning at HSHL

FFT

The FFT (“Fast Fourier Transform”) is an algorithm for analysing signals in the frequency domain.

Splitting the signal by frequency

From now on we assume that the digital signal contains several superimposed signals of different frequency, amplitude and phase. This can look like this, for example, when the numbers in memory (120 memory locations) are plotted:

Number stream of a signal consisting of several superimposed components, plotted against the memory location
Zahl = number · Speicherstelle = memory location

This number stream is available to the FFT algorithm as an input quantity. As a result, the FFT algorithm outputs the peak value and phase at defined frequencies. We assume that the frequency of a signal component does not change over time. This allows us to identify components of the signal by their frequency. The frequency is much better suited than the time waveform for separating the signals from each other and then analysing them. Separated by frequency, the time waveform above looks like this:

Two sampled signals of different frequency and amplitude plotted against the memory location
Zahl = number · Speicherstelle = memory location

If these two signals are added, we obtain the original signal again. Once the FFT algorithm has split the signal into the different frequencies, the signal parameters peak value and phase can be determined more easily. You specify the frequencies to the algorithm. How does that work?

Determining the peak value

The FFT algorithm is optimised for low computing time and is therefore difficult to follow from its code. Instead, we get to the bottom of the basic operating principle of the Fourier transform.
If two signals A(t) = A0 ∙ sin (2π ∙ fA ∙ t) and B(t) = B0 ∙ sin (2π ∙ fB ∙ t) of the same frequency fA = fB are multiplied together, the result looks like this:

Signal A, signal B of the same frequency and their product A·B, which is always positive
Zeit = time · Produkt A * B = product A * B · Produkt = product

If two signals A(t) = A0 ∙ sin (2π ∙ fA ∙ t) and B(t) = B0 ∙ sin (2π ∙ fB ∙ t) of different frequency fA ≠ fB are multiplied together, the result looks like this:

Signal A, signal B of different frequency and their product A·B with mean value 0
Zeit = time · Produkt A * B = product A * B · Produkt = product

The grey signal A ∙ B is only positive in the upper of the two figures. In the lower figure it is sometimes positive and sometimes negative. The mean value of the product of the signals in the upper figure is a positive number. At all times the product A ∙ B is positive. In the lower figure, positive and negative signal components in A ∙ B cancel each other out exactly, so that the mean value is 0. For now we simplify by assuming that both signals have the same phase, i.e. are not shifted in time relative to each other.

The central statement is:


The mean value of the product of two signals with different frequencies is equal to 0.

The mean value of the product of two signals with the same frequency equals the term A0 ∙ B0 / 2.

As a formula:

\[ \begin{gathered} \frac{1}{z} \sum_{n=1}^{z} \left[A_0 \cdot \sin(2\pi f_A \cdot t) \cdot B_0 \cdot \sin(2\pi f_B \cdot t)\right] = 0 \text{ for } f_A \neq f_B \\[8pt] \frac{1}{z} \sum_{n=1}^{z} \left[A_0 \cdot \sin(2\pi f_A \cdot t) \cdot B_0 \cdot \sin(2\pi f_B \cdot t)\right] = \frac{A_0 \cdot B_0}{2} \text{ for } f_A = f_B \end{gathered} \]

The parameter t for time in analogue signals becomes a counter n in digital signals. The sinusoidal, sampled, time-discrete signal A(t) is read from memory as A(n). A sinusoidal signal that has been digitised with 20 samples per period is stored in memory as follows:

nA(n)
0128
1167
2202
3231
4249
5255
6249
7231
8202
9167
10128
1188
1253
1324
146
150
166
1724
1853
1988

So the following applies

\[ \begin{gathered} \frac{1}{z} \sum_{n=1}^{z} \left[A(n) \cdot B(n)\right] = 0 \text{ for } f_A \neq f_B \\[8pt] \frac{1}{z} \sum_{n=1}^{z} \left[A(n) \cdot B(n)\right] = \frac{A_0 \cdot B_0}{2} \text{ for } f_A = f_B \end{gathered} \]

In many applications we know in which range the frequencies present in the signal lie. If, for example, we measure the voltage at a socket, we know that the frequency is f = 50 Hz. In the conductivity measurement from the previous chapter, we generate a signal with f = 1 kHz. There too we know that voltage and current both have the frequency f = 1 kHz. So we can test whether a signal is present at a certain frequency and how high its peak value is. To do this, we only have to multiply the signal by a test signal with the frequency at which we expect a signal.

Back to the example of the conductivity measurement: to determine which peak value at 1 kHz is contained in the digital data stream of the voltage U, we multiply the data stream by a test signal T with the frequency fT = 1 kHz and the peak value T0 = 1:

\[ \begin{gathered} T = T_0 \cdot \sin(2\pi \cdot 1\,\mathrm{kHz} \cdot t) \\[8pt] \frac{T_0 \cdot U_0}{2} = \frac{1}{z} \sum_{n=1}^{z} \left[T(n) \cdot U(n)\right] \end{gathered} \]

The voltage signal U(n) comes from the ADC. We specify the test signal ourselves, so we can optimise it. With T0 = 1 the result simplifies to

\[ \begin{gathered} \frac{U_0}{2} = \frac{1}{z} \sum_{n=1}^{z} \left[T(n) \cdot U(n)\right] \\[8pt] U_0 = 2 \cdot \frac{1}{z} \sum_{n=1}^{z} \left[T(n) \cdot U(n)\right] \end{gathered} \]

With this formula we can determine the peak value U0 of the signal stored in memory as a data stream.

As an example, we consider 20 numbers for U(n) that were sampled one after the other by the ADC. The peak value of U (blue) here is 5. In addition, we consider the test signal T(n) with peak value 1 (red). The frequencies of U and T are chosen to be equal.

Voltage U, test signal T, product U·T and its mean value 2.5 over 20 memory locations
Werte = values · Speicherstelle = memory location · Spannung U = voltage U · Testsignal T = test signal T · Mittelwert = mean value · Spannung = voltage

In grey you see the waveform of U(n) ∙ T(n) and in yellow the mean value of the grey signal. The following applies

\[ U_0 = 2 \cdot \frac{1}{20} \sum_{n=1}^{20} \left[\textcolor{#c00000}{T(n)} \cdot \textcolor{#4472c4}{U(n)}\right] = 2 \cdot \textcolor{#ffc000}{2.5} = 5 \]

The table below shows the corresponding data from Excel. The mean value at the very bottom is the mean of the numbers in the right column.

nU(n)T(n)U(n) · T(n)
0000
11.545084970.309016990.47745751
22.938926260.587785251.72745751
34.045084970.809016993.27254249
44.755282580.951056524.52254249
5515
64.755282580.951056524.52254249
74.045084970.809016993.27254249
82.938926260.587785251.72745751
91.545084970.309016990.47745751
106.1257E-161.2251E-167.5049E-32
11-1.54508497-0.309016990.47745751
12-2.93892626-0.587785251.72745751
13-4.04508497-0.809016993.27254249
14-4.75528258-0.951056524.52254249
15-5-15
16-4.75528258-0.951056524.52254249
17-4.04508497-0.809016993.27254249
18-2.93892626-0.587785251.72745751
19-1.54508497-0.309016990.47745751
Mean value2.5

Application to many frequencies

The FFT carries out this calculation (very highly optimised) for many frequencies with a constant spacing between them. You specify the lowest frequency, the highest frequency and the number of equally spaced frequencies in between. The following example shows a signal with two frequency components:

Input data: periodic signal of two sine components with a peak value of about 2.8 V
Eingangsdaten = input data · Zeit [ms] = time [ms] · Zeit = time

The following applies


U (n) = 3 ∙ sin(2π 100Hz ∙ n) + 1 ∙ sin(2π 300Hz ∙ n)

One after the other, we multiply test signals

T1 (n) = 1 ∙ sin(2π 100Hz ∙ n)

T2 (n) = 1 ∙ sin(2π 200Hz ∙ n)

T3 (n) = 1 ∙ sin(2π 300Hz ∙ n)

T4 (n) = 1 ∙ sin(2π 400Hz ∙ n)


by the voltage signal U(n). The result is:

\[ \begin{gathered} U_0@100\,\mathrm{Hz} = 2 \cdot \frac{1}{20} \sum_{n=1}^{20} \left[T_1(n) \cdot U(n)\right] = 3 \\[8pt] U_0@200\,\mathrm{Hz} = 2 \cdot \frac{1}{20} \sum_{n=1}^{20} \left[T_2(n) \cdot U(n)\right] = 0 \\[8pt] U_0@300\,\mathrm{Hz} = 2 \cdot \frac{1}{20} \sum_{n=1}^{20} \left[T_3(n) \cdot U(n)\right] = 1 \\[8pt] U_0@400\,\mathrm{Hz} = 2 \cdot \frac{1}{20} \sum_{n=1}^{20} \left[T_4(n) \cdot U(n)\right] = 0 \end{gathered} \]

So the peak values are determined correctly. The classic representation of the peak values at different discrete frequencies looks like this:

Peak values against frequency: 3 at 100 Hz and 1 at 300 Hz
Spitzenwert = peak value · Frequenz [Hz] = frequency [Hz] · Frequenz = frequency

In the Excel sheet below you can try to program this frequency analysis yourself.

Exercise on the Fourier transform (Excel)

Phases

So far we have simplified by assuming that the phases of all signals are 0. So all signal components are not shifted in time relative to each other. In real measurement signals, however, this is not the case. That is why we need a more general solution. To determine peak values and phases, we multiply the input signal, for each test frequency, by two test signals that are phase-shifted by 90° or π / 2 relative to each other:


TSin = 1 ∙ sin(2π ∙ f ∙ t)

TCos = 1 ∙ cos(2π ∙ f ∙ t)

This gives you the real part and imaginary part of the input signal relative to the phase of the test signal. The following applies

\[ \begin{gathered} RE = 2 \cdot \frac{1}{z} \sum_{n=1}^{z} \left[T_{\mathrm{Cos}}(n) \cdot U(n)\right] \\[8pt] IM = 2 \cdot \frac{1}{z} \sum_{n=1}^{z} \left[T_{\mathrm{Sin}}(n) \cdot U(n)\right] \end{gathered} \]

You calculate the peak value and phase with

\[ \begin{gathered} U_0 = \sqrt{RE^2 + IM^2} \\[6pt] \varphi = \arctan\left(\frac{IM}{RE}\right) \end{gathered} \]

Exercise: shift one frequency component of the signal in phase in the Excel example. Program the evaluation so that the phase and peak value of all frequency components are calculated correctly.

Download course as PDF

The PDF contains all pages of the course. Interactive content is only available on the website.