Sliding DFT

This sample implements examples of the possible uses of the function block FB_CMA_SlidingDFT, where the function block is configured in such a way that all spectral values are calculated and the results are compared to those from the calculation using the function block FB_CMA_RealFFT. Furthermore, to improve the calculated spectrum, a Hanning window is applied in the spectral range.

The source code for this sample can be downloaded here: SlidingDFT_Sample.zip

Block diagram

Sliding DFT 1:

Program parameters

The table below shows a list of the important parameters for configuring the function blocks.

FFT-length

512 / 512

Buffer size

10 / 512

FFT result length

257 / 257

Explanations

The scope project included in the sample visualizes the calculated spectra over their magnitude in the range of 0 to 1 kHz. On the one hand, the influence of the side lobes in the spectrum of the function block FB_CMA_SlidingDFT (blue line) is noticeable. The deviations essentially depend on the chosen damping parameter fDampingFactor. The deviations become smaller with values above 0.995, but the calculation becomes unstable with too little attenuation (>0.999). Due to the definition of the recursion rule for the spectral line k = 0, the calculation for the DC component, on the other hand, is more accurate. An improvement of the calculated values can be achieved by applying the Hanning window in the spectral range (fig. below).

Sliding DFT 2:

A significant difference between the two function blocks is the utilization in the respective task. This is illustrated in the following graphic.

Sliding DFT 3:

In contrast to the utilization peaks of the RealFFT (fig. below), the utilization of the SDFT (fig. above) is more constant. The latter value is significantly higher on average, but is subject to fewer fluctuations.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4022.25

PC or CX (x86, x64)

Tc3_CM, Tc3_CM_Base