FB_PMA_Spectrum_Quantiles_1Ph

The function block FB_PMA_Spectrum_Quantiles_1Ph calculates the magnitude spectra of the current and voltage values like the function block FB_PMA_Spectrum_1Ph. In addition, p-quantiles of the spectrum distribution can be calculated. The quantiles and their number can be configured individually.

The input buffer is provided via the function block FB_PMA_Source_1Ph. The size of the input buffer is half the window length.

By way of example, possible FFT and window lengths are shown in the following table:

FFT length

Window length

Buffer length

512

29

400

200

1024

210

800

400

2048

211

1600

800

4096

212

3200

1600

8192

213

6400

3200

16384

214

12800

6400

Memory properties

The function block takes into account all input values since the instantiation. If the Reset method has been called since the start, all input values since its last call will be taken into account.

Syntax

Definition:

FUNCTION BLOCK FB_PMA_Spectrum_Quantiles_1Ph
VAR_INPUT
    nOwnID             : UDINT;
    tTransferTimeout   : LTIME := LTIME#500US;
    stInitPars         : ST_PMA_Spectrum_Quantiles_InitPars;
END_VAR
VAR_OUTPUT
    bError             : BOOL;
    ipResultMessage    : I_TcMessage;
    bNewResult         : BOOL;
    nCntResults        : ULINT;
END_VAR

FB_PMA_Spectrum_Quantiles_1Ph 1: Inputs

The input parameters of this function block represent initialization parameters and have to be assigned during the declaration of the function block instance (alternatively: Init method). They may only be assigned once. A change at runtime is not possible.

Name

Type

Description

nOwnID

UDINT

Identifies the function block instance with a unique ID. This must always be greater than zero. A proven approach is to define an enumeration for this purpose.

tTransferTimeout

LTIME

Setting of the synchronous timeout for internal multi-array forwardings. See Parallel Processing in Transfer Tray.

stInitPars

ST_PMA_Spectrum_Quantiles_InitPars

Function block-specific structure with initialization parameters. The parameters must match the definition of the input and output buffers.

FB_PMA_Spectrum_Quantiles_1Ph 2: Outputs

Name

Type

Description

bError

BOOL

TRUE if an error occurs.

ipResultMessage

I_TcMessage

The interface offers detailed information about the return value.

bNewResult

BOOL

TRUE once new results have been calculated.

nCntResults

ULINT

Count value is incremented with new output data.

FB_PMA_Spectrum_Quantiles_1Ph 3: Methods

Name

Description

Call

The method is called in each cycle to execute the calculations from the input buffer when new data is present.

CallEx

To minimize CPU usage, it may be necessary to use the CallEx method. In contrast to the Call method, the quantiles are not calculated after each spectrum calculation, but only after a configurable number of calculations.

Init

Alternative to the function block initialization

PassInputs

As an alternative to the Call method, the method can be called in each cycle if no calculation is to take place. The incoming input buffer is then forwarded accordingly.

Reconfigure

The method is called in order to reconfigure the function block during the runtime.

Reset

This method deletes all the data sets already added. Alternatively, automatic resetting can be used on the CallEx method.

Sample

VAR CONSTANT
    cOversamples : UDINT := 10;
    cFFT_Length : UDINT := 4096;
    cWindowLength : UDINT := 3200;
    cSourceInitPars: ST_PMA_Source_InitPars := (
        nBufferLength := cWindowLength/2);
    cSpectrumQuantilesInitPars : ST_PMA_Spectrum_Quantiles_InitPars := (
        nFFT_Length := cFFT_Length,
        nWindowLength := cWindowLength,
        fSampleRate := cOversamples * 1000,
        eScalingType := E_PMA_ScalingType.PeakAmplitude,
        eWindowType := E_PMA_WindowType.HannWindow,
        bTransformToDecibel := FALSE,
        fDecibelThreshold := GVL_PMA.cMinArgLog10,
        fMinBinnedVoltage := 0.0,
        fMaxBinnedVoltage := 300,
        fMinBinnedCurrent := 0.0,
        fMaxBinnedCurrent := 2,    
        nBins := 10,
        nNumQuantiles := 2,
        aQuantiles := [0.5, 0.9]);
END_VAR
VAR
    aVoltage AT%I* : ARRAY[1..cOversamples] OF LREAL;
    aCurrent AT%I* : ARRAY[1..cOversamples] OF LREAL;
    fbSource : FB_PMA_Source_1Ph := (nOwnID := 1, aDestIDs := [2], stInitPars := cSourceInitPars);
    fbSpectrumQuantiles : FB_PMA_Spectrum_Quantiles_1Ph := (nOwnID := 2, stInitPars := cSpectrumQuantilesInitPars);
    aSpectrumVoltage : ARRAY[1..cFFT_Length/2 + 1] OF LREAL;
    aSpectrumCurrent : ARRAY[1..cFFT_Length/2 + 1] OF LREAL;
    aSpectrumQuantilesVoltage : ARRAY[1..cFFT_Length/2 + 1, 1..2] OF LREAL;
    aSpectrumQuantilesCurrent : ARRAY[1..cFFT_Length/2 + 1, 1..2] OF LREAL;
    bNewResult_Spectrum : BOOL;
    bNewResult_Quantiles : BOOL;
END_VAR
// Call source
fbSource.Call(ADR(aVoltage), ADR(aCurrent), SIZEOF(aVoltage), 0);

// Call algorithm
fbSpectrumQuantiles.CallEx(
    5,
    FALSE,
    ADR(aSpectrumVoltage),
    ADR(aSpectrumCurrent),
    SIZEOF(aSpectrumVoltage),
    ADR(aSpectrumQuantilesVoltage),
    ADR(aSpectrumQuantilesCurrent),
    SIZEOF(aSpectrumQuantilesVoltage),
    ADR(bNewResult_Spectrum),
    ADR(bNewResult_Quantiles));

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.0

PC or CX (x86, x64)

Tc3_PowerMonitoring