Analysis of data streams
Block-by-block FFT analysis from a data stream
The DFT/FFT is defined on a continued cyclic, periodic signal. This leads to an initially surprising conclusion: If an FFT analysis for a long signal is required, the input signal cannot simply be subdivided into sections and transformed with DFT. Because if the last value in such a section does not match the first, the FFT interprets this as a discontinuity in the cyclic sequence, which clearly shows up in the spectrum (spectral leakage). The following diagram illustrates the principle. A partial signal (blue) is cut from the total signal (black). The FFT implies a cyclic continuation of the partial signal (lower diagram) and assumes step changes in the signal to be transformed, as clearly indicated in the spectrum.
The situation can be rectified by weighting the signal sections before the transformation with a suitable window function (for details see next section). In a suitable window, time values near the start and the end are multiplied with a factor zero or closed to zero. The following diagram shows the same scenario, but now with a window function (red). Windowing removes the step changes in the cyclic continuation, although please note that the properties of the window show up in the spectrum of the windowed partial signal. However, the window property generally affects the spectrum to a significantly lower degree.
A problematic aspect of windowing is that values at the edge of the window are hardly taken into account in the spectrum. In situations where this region contains signal characteristics that indicate possible damage, key information may be lost. In order to prevent the loss of information, the TwinCAT Condition Monitoring Library uses overlapping signal sections for the windowing procedure. A 50% overlap is recommended with the Hann window, which is used as standard. As a result, samples that are at the edge of one window section are in the center of the next window section.
The following picture schematically illustrates the procedure for an FFT analysis from a data stream with 50% overlap.
Initially, buffers with a defined length of 1600 values are filled from the data stream. The previous buffer is included in the evaluation of the data from buffer n, so that the data packet that is windowed now contains 3200 values. The maximum of the window function is precisely in the middle between the two buffers and falls to zero towards the edges of the two buffers. Zero padding extends the data packet to a length of 4096 values, so that the length is a power of 2 and can therefore be efficiently calculated with an FFT algorithm. The result of the FFT is a data packet with 4096 values, which can be reduced to 2049 values if required, provided the input data are all real-valued (see Image frequencies).
During the evaluation of buffer n, buffer n+1 is filled, and buffer n is included in its evaluation. This approach always results in a 50% overlap of the windowed time ranges.
Analysis of a data stream in TwinCAT 3 The signal analysis scheme shown in the diagram above is implemented in the Condition Monitoring Library through FB_CMA_MagnitudeSpectrum and FB_CMA_PowerSpectrum. As user, only a configuration of the parameters (length of the buffer, length of the FFT, window function, overlap, etc.) and the provision of the data buffer are necessary. See for example: ST_CM_PowerSpectrum_InitPars. |
Window functions
The properties of the window functions used are shown in the result of the transformation. It is not the signal x[n] that is Fourier-transformed, but the signal x[n].w[n], with w[n] as time values of the window function. Note the basic characteristics of window functions.
If "no" window function is used, i.e. if a signal section is taken from a longer overall signal, this corresponds to the application of a rectangular window. An example is used to compare the properties of window functions with a rectangular window: A harmonic sine with an amplitude of 13 and a frequency of 500 Hz is sampled with a rate of 10 kHz and windowed with a window function with a length of 3200 samples, followed by calculation of the magnitude spectrum (with the Spectrum Scaling Options eCM_PeakAmplitude
). In the following illustration, the magnitude spectrum is compared when using the available window functions.
A sample for the reconstruction of the following graphic can be found here: Window functions
It illustrates two key features of window functions:
- The width of the main lobe, in this case around 500 Hz.
- The attenuation of the side lobes, relative to the maximum of the main lobe.
- The amplitude accuracy of harmonic signals, compare the maximum values when specifying a vibration with an amplitude of 13.
The different window types each form a trade-off between these three essential properties.
The width of the main lobe affects the achievable frequency resolution. The height of the side lobes indicates the spectral leakage, since it is caused solely by the window and not by the signal to be analyzed. The curvature of the mainlobes in the range -0.5 bins to +0.5 bins around the maximum characterizes the maximum amplitude error that can occur with harmonic signals (scalloping losses).
Note that the rectangular window enables very good frequency resolution but results in strong spectral leakage, which becomes problematic if a frequency component with an amplitude of 0.5 occurs at 550 Hz, in addition to the peak at 500 Hz, for example. In addition, the maximum possible amplitude error is very high at -36.34%. The Hann window considerably reduces the sidelobes, but it also reduces the attainable frequency resolution, which nevertheless represents a good compromise as long as no exact determination of the amplitudes of sinusoidal signals is required. The maximum possible amplitude error here is -15.12%. The Hann window is one of the best-known window functions and is therefore set by default in the Condition Monitoring library. If amplitude accuracy is required with harmonic signals, a flat-top window (SFT5M) is to be used with the flattest possible curvature in the central main lobe area (maximum amplitude error -0.045%). However, the mainlobe is very wide here, as a result of which this window is only recommended for the analysis of purely harmonic signals.
An important parameter of the frequency resolution, if a window function is used, is the equivalent noise bandwidth (ENBW).
The value Δf is derived from the FFT-length N and the sampling rate fs (see Fourier analysis). The expression in the equation before the Δf is defined via the properties of the window and is 1 for a rectangular window and, for example, 1.5 for the Hann window and 3.885 for the SFT5M.
The selection of the window to be used, the associated parameters and the overlap to be used is realized for the function block concerned via the respective function block-specific structure with initialization parameters, e.g. ST_CM_MagnitudeSpectrum_InitPars.
Available window functions
For a window of the length N, the following window functions are available in the Condition Monitoring library. Here, I0 designates the modified Bessel function of the first type and zero order. The eCM_KaiserWindow
and the eCM_FlatTopWindow
are parameterized via T_CM_WindowParameters in the initPars structures. The last column specifies the recommended overlap in percent of the window length. By way of example, the Kaiser-4 window with has been selected for eCM_KaiserWindow
and the SFT5M window with
for eCM_FlatTopWindow
.
Identifier | PID | Definition | Overlapping |
---|---|---|---|
| 16#05300901 | 50% | |
| 16#05300902 | 0% | |
| 16#05300905 | 50% | |
| 16#05300906 | 50% | |
| 16#05300907 | 67% (Kaiser-4) | |
| 16#05300917 | 76% (SFT5M) |
Calculation of the recommended overlap
The recommended overlap of the windowed signal sections results from the consideration of the following properties of the window function:
- amplitude flatness: flatness of the overlapping window function. i.e. the weighting of the individual samples.
- overlap correlation: correlation between the individual samples of the overlapping functions.
The recommended overlap lies at the point where the difference between the two properties is largest. In other words, the best possible flatness is achieved with the smallest possible correlation. This is shown in the following graphic for the SFT5M window (eCM_FlatTopWindow
).
Window function (black), amplitude flatness (red), overlap correlation (green), recommended overlap (blue).
For further information, see:
- G. Heinzel et.al.: Spectrum and spectral density estimation by the Discrete Fourier transform (DFT), including a comprehensive list of window functions and some new flat-top windows. 2002.
- In the Condition Monitoring library the calculation of the recommended overlap takes place via F_CM_CalculateRecommendedOverlap. The function can be used explicitly; if configured appropriately, the algorithms also use it implicitly depending on the set window function. Of course, a freely selectable overlap can also be set. Compare, for example, eWindowType, eWindowTypeParameters and nOverlap in ST_CM_PowerSpectrum_InitPars.
Overlap-Add Method
Some function blocks of the Condition Monitoring library work by manipulating the spectrum of the input signal, i.e. as described above, the input signal is first decomposed into overlapping partial signals and Fourier-transformed. A manipulation of the spectrum is then carried out and an inverse Fourier transformation is calculated. Depending on the window function used, a correction function is required to compensate for the influence of the window. The individual results, which also overlap, are then summed at the output of the function block, so that a data stream is created again at the output of the function block. This procedure is called the overlap-add method and is shown in the following graphic as an example on the basis of the calculation of the signal envelope (FB_CMA_Envelope).
Overlap-Add in TwinCAT 3 The procedure is used within some function blocks of the library and does not have to be implemented by the user himself. All that is required is a configuration of the parameters (length of the buffers, length of the FFT, …) and provision of the data buffers. |