Window functions

This sample implements several single-channel magnitude spectra and compares the use of different window functions. Three variants are presented: One with the overlap mechanism deactivated, an automatic calculation of the recommended overlap and a manual configuration using a suitable firmware function.

The source code for the sample is available for download from here: WindowFunctions_Sample.zip

Block diagram

Window functions 1:

Program parameters

The table below shows a list of important parameters for the configuration of the magnitude spectrum function blocks.

FFT length

4096

Window size

3200

Buffer size

3200 / 1600 / 767

Window type

eCM_RectangularWindow / eCM_HannWindow / eCM_FlatTopWindow

Decibel transformation

False

Calculation/specification of the overlap

Version 1: Use of the function F_CM_CalculateRecommendedOverlap

By means of the named function the recommended overlap can be calculated at runtime. After download/login, the necessary values are called in the MAIN_CM in the first cycle.


    IF bCalculateOverlap THEN
    // recommended overlap for window 1
    nOverlap1 := F_CM_CalculateRecommendedOverlap(eWindowType := cWindowType1, aWindowParameters := cWindowParameters1, nWindowLength := cWindowLength);

    // recommended overlap for window  2
    nOverlap2 := F_CM_CalculateRecommendedOverlap(eWindowType := cWindowType2, aWindowParameters := cWindowParameters2, nWindowLength := cWindowLength);

    // recommended overlap for window  3
    nOverlap3 := F_CM_CalculateRecommendedOverlap(eWindowType := cWindowType3, aWindowParameters := cWindowParameters3, nWindowLength := cWindowLength);

    bCalculateOverlap := FALSE;
END_IF

The lengths obtained in this way can subsequently be entered in the configuration of the analysis chains (parameters cOverlap1, cOverlap2, cOverlap3 in the GVL_Constants.). The dependencies in the buffer length must be observed here! After downloading/logging in again, the application is configured with regard to the overlap.

Version 2: Reading the initial parameters in the Online view

If the value nOverlap := cCM_OverlapRecommended is used with the initialization structure for the overlap, then the optimum overlap is calculated in the initialization phase of the function block, depending on the window parameters. This value can be read in the Online View of the function block in the node stInitPars after the download and login. With this variant it is not necessary to start the application!

Window functions 2:

Online View for Spectrum 2 (Hann window)

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4022.25

PC or CX (x86, x64)

Tc3_CM, Tc3_CM_Base, Tc3_MultiArray