Andrei Shelkovenko. One of the developers and founder of Vibromera.

The translation of the article may contain inaccuracies.

- Fourier transform and signal spectrum

In many cases the task of obtaining (calculating) the spectrum of a signal is as follows. There is an ADC, which with sampling frequency Fd transforms continuous signal, which comes to its input during time T, into digital samples – N pieces. Then this array of samples is fed to some program (for example FourierScope) which outputs N/2 some numeric values.

To check if the program works correctly, we form an array of samples as a sum of two sin(10*2*pi*x)+0.5*sin(5*2*pi*x) and feed it into the program. The program drew the following:

There are two harmonics on the spectrum graph – 5 Hz with amplitude of 0.5 V and 10 Hz with amplitude of 1 V, everything is as in the formula of the original signal. Everything is fine, the grogram works correctly.

This means that if we feed a real signal from a mixture of two sinusoids to the ADC input, we will get a similar spectrum consisting of two harmonics.

So, our ** real **measured signal

**, digitized by ADC, i.e. represented**

**of 5 sec. duration****samples, has a**

**by discrete****spectrum.**

**discrete non-periodic**

*From a mathematical point of view – how many errors in this phrase?*Now let’s try to measure the same signal for 0.5 sec.

Something is wrong here! The harmonic at 10 Hz is drawn normally, and instead of the harmonic at 5 Hz there are some unclear harmonics.

On the Internet they say that it is necessary to add zeros to the end of the sample and the spectrum will be drawn normally.

That’s not it at all. I will have to deal with the theory. Let’s go to ** wikipedia** – the source of knowledge.

2. Continuous function and its Fourier series representation

Mathematically, our signal with duration of T seconds is some function f(x) given on the interval {0, T} (X in this case is time). Such a function can always be represented as a sum of harmonic functions (sine or cosine) of the form:

k is the number of the trigonometric function ( the number of the harmonic component, the number of the harmonic)

T – segment where the function is defined (the duration of the signal)

Ak- amplitude of the k-th harmonic component,

θk- the initial phase of the kth harmonic component

What does it mean to “represent the function as the sum of the series”? It means that by adding the values of the harmonic components of the Fourier series at each point, we get the value of our function at that point.

(More strictly, the mean square deviation of the series from the function f(x) will tend to zero, but despite the mean square convergence, the Fourier series of a function need not, generally speaking, converge to it point by point. )

This series can also be written in the form:

where , the kth complex amplitude.

hoặc

The relationship between the coefficients (1) and (3) is expressed by the following formulas:

Note that all these three representations of Fourier series are perfectly equivalent. Sometimes when working with Fourier series, it is more convenient to use exponents of imaginary argument instead of sines and cosines, i.e. to use Fourier transform in complex form. But it is convenient for us to use formula (1), where the Fourier series is represented as a sum of cosines with corresponding amplitudes and phases. In any case, it is wrong to say that the result of the Fourier transform of the real signal will be complex harmonic amplitudes. As Wiki correctly says, “The Fourier transform (ℱ) is an operation that maps one function of a real variable to another function also of a real variable.”

**Bottom line:**

**The mathematical basis for spectral analysis of signals is the Fourier transform.**

**The Fourier transform allows to represent a continuous function f(x) (signal) defined on the interval {0, T} as a sum of infinite number (infinite series) of trigonometric functions (sine and/ or cosine) with definite amplitudes and phases also considered on the interval {0, T}. Such series is called a Fourier series.**

Note some more points, the understanding of which is required for correct application of the Fourier transform to signal analysis. If we consider the Fourier series (sum of sinusoids) on the entire X-axis we will see that outside the interval {0, T} the Fourier series function will periodically repeat our function.

For example, in the graph in Fig. 7, the original function is defined on the interval {-T\2, +T\2}, and the Fourier series represents a periodic function defined on the entire x-axis.

This is because the sinusoids themselves are periodic functions, so their sum will also be a periodic function.

Thus:

Our original function is a continuous, non-periodic function defined on some segment of length T.

The spectrum of this function is discrete, i.e. it is represented as an infinite series of harmonic components – a Fourier series.

In fact, Fourier series defines some periodic function, which coincides with our function on the interval {0, T}, but for us this periodicity is not essential.

Next.

The periods of harmonic components are multiples of the interval {0, T}, on which the initial function f(x) is defined. In other words, the periods of harmonics are multiples of the duration of the signal measurement. For example, the period of the first harmonic in a Fourier series is equal to the interval T in which the function f(x) is defined. The period of the second harmonic in a Fourier series is equal to the interval T/2. And so on (see Figure 8).

Accordingly, the frequencies of harmonic components are multiples of 1/T. That is, frequencies of harmonic components Fk are Fk= k\T, where k runs values from 0 to ∞, for example, k=0 F0=0; k=1 F1=1\T; k=2 F2=2\T;k=3 F3=3\T;…. Fk= k\T (at zero frequency, a constant component).

Let our initial function, is a signal recorded during T=1 sec. Then the period of the first harmonic will be equal to the duration of our signal T1=T=1 sec and the frequency of the harmonic is equal to 1 Hz. The period of the second harmonic will be equal to the duration of our signal divided by 2 (T2=T/2=0.5 sec.) and the frequency is equal to 2 Hz. For the third harmonic, T3=T/3 sec and the frequency is 3 Hz. And so on.

The step between harmonics in this case is 1 Hz.

Thus, a signal with a duration of 1 sec can be decomposed into harmonic components (to obtain a spectrum) with a frequency resolution of 1 Hz.

To increase the resolution by a factor of 2 to 0.5 Hz, it is necessary to increase the duration of measurement by a factor of 2 to 2 sec. A 10-second signal can be decomposed into harmonic components (spectrum) with a frequency resolution of 0.1 Hz. There are no other ways to increase frequency resolution.

There is a way to artificially increase the signal duration by adding zeros to the array of samples. But it does not increase the real frequency resolution.

3. Discrete signals and discrete Fourier transform

With the development of digital technology the ways of measurement data (signals) storage have changed. Whereas previously a signal could be recorded on a tape recorder and stored on a tape in analog form, now signals are digitized and stored in files in computer memory as a set of numbers (counts).

The usual scheme of signal measurement and digitization looks as follows.

Measuring transducer —- Signal normalizer —- ADC —– Computer

(*Fig.9 Schematic of the measuring channel)*

The signal from the measuring transducer goes to the ADC for a period of time T. The signal readings (sampling) received during time T are transmitted to the computer and saved in the memory.

What are the requirements to signal digitization parameters? A device which converts the input analog signal into a discrete code (digital signal) is called an analog-to-digital converter (ADC) (© Wiki).

One of the basic parameters of ADC is the maximum sampling rate – the frequency of sampling of a signal which is continuous in time. Sample rate is measured in hertz. ((© Wiki))

According to Kotelnikov’s theorem, if a continuous signal has a spectrum limited by the frequency Fmax, it can be fully and uniquely reconstructed from its discrete samples taken at time intervals T = 1/2*Fmax, ie with a frequency Fd ≥ 2*Fmax, where Fd – sampling frequency; Fmax – the maximum frequency of the signal spectrum. In other words, the frequency of signal digitization (sampling frequency of ADC) must be at least 2 times higher than the maximum frequency of the signal we want to measure.

And what will happen if we take samples with lower frequency than required by Kotelnikov’s theorem?

In this case there is an “aliasing” effect (aka stroboscopic effect, moiré effect), in which a high frequency signal after digitization turns into a low frequency signal, which in fact does not exist. In Fig. 11 the red sine wave of high frequency is the real signal. The blue sine wave of lower frequency is a fictitious signal, arising due to the fact that during the sampling time has time to pass more than half a period of the high-frequency signal.

To avoid the aliasing effect, a special anti-alias filter (low-pass filter) is placed before the ADC. It passes frequencies lower than half of the ADC sampling frequency and cuts off higher frequencies.

In order to calculate signal spectrum by its discrete samples the discrete Fourier transform (DFT) is used. Note again that the spectrum of a discrete signal is “by definition” limited to a frequency Fmax smaller than half the sampling frequency Fd. Therefore, the spectrum of a discrete signal can be represented by the sum of __a finite __number of harmonics, in contrast to the infinite sum for the Fourier series of a continuous signal, whose spectrum can be unlimited. According to Kotelnikov’s theorem, the maximum frequency of a harmonic must be such that it accounts for at least two samples, so the number of harmonics is equal to half the number of samples of a discrete signal. That is, if there are N samples in the sample, the number of harmonics in the spectrum will be N/2.

Consider now the discrete Fourier transform (DFT).

Comparing it with the Fourier series

As we can see, they coincide, except for the fact that time in the FFT is discrete and the number of harmonics is limited to N/2, which is half the number of samples.

DFT formulas are written in dimensionless integer variables k, s, where k is the number of signal samples, s is the number of spectral components.

The value s shows the number of full harmonic oscillations per period T (signal measurement duration). The discrete Fourier transform is used to find the amplitudes and phases of harmonics numerically, i.e. “on the computer”.

As it was already said above, when decomposing a non-periodic function (our signal) into Fourier series, the resulting Fourier series actually corresponds to a periodic function with period T (Fig.12).

As can be seen in Fig. 12, the function f(x) is periodic with period T0. However, due to the fact that the measuring sample length T is not equal to the function period T0, the function obtained as a Fourier series has a discontinuity at point T. As a result, the spectrum of this function will contain a large number of high-frequency harmonics. If the duration of measuring sample T coincided with the period of function T0, then the spectrum obtained after the Fourier transform would contain only the first harmonic (a sinusoid with a period equal to the duration of the sample), because the function f(x) is a sinusoid.

In other words, the DFT program “does not know” that our signal is a “slice of a sine wave”, but tries to represent as a series a periodic function which has a discontinuity due to the discontinuity of separate pieces of the sine wave.

As a result, harmonics appear in the spectrum, which should, in total, represent the shape of the function, including this discontinuity.

Thus, to get a “correct” spectrum of a signal which is a sum of several sinusoids with different periods, it is necessary that an __integer number of periods of __each sinusoid should be present on the measuring period of the signal. In practice, this condition can be met with a sufficiently long duration of signal measurement.

At shorter duration the picture will look “worse”:

In practice, it can be difficult to understand where the “real components” and where the “artifacts” caused by inconsistency of component periods and signal sampling durations or “jumps and breaks” in the waveform. Of course, the words “real components” and “artifacts” are put in quotes for a reason. The presence of many harmonics on the spectrum graph does not mean that our signal actually consists of them. It is like thinking that number 7 “consists” of numbers 3 and 4. The number 7 can be thought of as the sum of 3 and 4 – that is correct.

So also our signal… or rather not even “our signal”, but a periodic function composed by repeating our signal (sample) can be represented as a sum of harmonics (sine waves) with certain amplitudes and phases. But in many cases important for practice (see figures above) it is indeed possible to relate the harmonics obtained in the spectrum also to real processes having cyclic character and contributing significantly to the form of the signal.

Some results

1. A real measured signal with T sec. duration digitized by ADC, i.e. represented by a set of discrete samples (N pieces), has a discrete non-periodic spectrum represented by a set of harmonics (N/2 pieces).

2. The signal is represented by a set of valid values and its spectrum is represented by a set of valid values. The frequencies of the harmonics are positive. Just because it is mathematically more convenient to represent the spectrum in complex form using negative frequencies does not mean that “this is right” and “this is how you should always do it”.

3. The signal measured at time T is determined only at time T. What happened before we started measuring the signal and what will happen after that is unknown to science. And in our case it is not interesting. FFT of the time-limited signal gives its “real” spectrum, in the sense that under certain conditions it allows to calculate the amplitude and frequency of its components.