FC_FourierCoefficients

 

FC_FourierCoefficients - General Information

Overview

Type:

Function

Available as of:

V1.0.3.0

Versions:

Current version

Task

Calculation of Fourier coefficients

Description

A periodic function f which is defined on an interval [a, b] can be represented as a Fourier series under suitable conditions:

G-SE-0068553.1.gif-high.gif

 

 

G-SE-0068554.1.gif-high.gif

 

 

Here, the Fourier coefficients ak and bk are provided by:

G-SE-0068555.1.gif-high.gif

 

 

The function FC_FourierCoefficients calculates the Fourier coefficients defined above up to index k = i_diMaxIndex ("k-th harmonic"). The calculated Fourier coefficients are entered into arrays whose start will be communicated to the function by means of the pointers i_plrFou­rierCoefficientsA (Array for ak) and i_plrFourierCoefficientsB (Array for bk).

The function f is transferred by a value table. As a definition range the interval 0.0 ... i_lrXPeriod is assumed. i_diNumberOfIntervals contains the length of the value table (number of partial intervals, into which the definition range [0.0, i_lrXPeriod] is split.

The calculated Fourier coefficients are used by the function FC_FourierPartialSum to calculate finite Fourier partial sums. A possible use is the blanking of higher harmonics (filtering).

Interface

Input

Data type

Description

i_lrXPeriod

LREAL

Period of the function / length of the definition range

i_diNumberOfIntervals

DINT

Number of partial intervals into which the definition range is split / length of the value table used for defining the function.

i_plrFunctionValues

POINTER TO LREAL

Pointer to the start of the value table which defines the function.

i_diMaxIndex

DINT

Index up to which the Fourier coefficients are to be calculated (Caution: the arrays, which i_plrFourierCoefficientsA and i_plrFourierCoefficientsB point to, must have at least i_diMaxIndex entries).

i_plrFourierCoefficientsA

POINTER TO LREAL

Pointer on the start of the array into which the Fourier coefficients ak are to be entered.

i_plrFourierCoefficientsB

POINTER TO LREAL

Pointer on the start of the array into which the Fourier coefficients bk are to be entered.

Output

Data type

Description

q_etDiag

GD.ET_Diag

General library-independent statement on the diagnostic.

A value not equal to ET_Diag.Ok corresponds to an diagnostic message.

q_etDiagExt

ET_DiagExt

POU-specific output on the diagnostic.

q_etDiag = ET_Diag.Ok -> Status message

q_etDiag <> ET_Diag.Ok -> Diagnostic message

Diagnostic Messages

q_etDiag

q_etDiagExt

Enumeration value

Description

OK

Ok

0

Ok

InputParameterInvalid

MaxIndexRange

61

MaxIndex is outside the valid range.

InputParameterInvalid

NumberOfIntervalsRange

59

NumberOfIntervals is outside the valid range.

InputParameterInvalid

PointerFourierCoefficientsAInvalid

62

The pointer VourierCoefficientsA is invalid.

InputParameterInvalid

PointerFourierCoefficientsBInvalid

63

The pointer VourierCoefficientsB is invalid.

InputParameterInvalid

PointerFunctionValuesInvalid

60

The pointer FunctionValues is invalid.

InputParameterInvalid

XPeriodRange

58

XPeriod is outside the valid range.

Example

(* Calculate the Fourier-Coefficients of a user defined function FC_TestFunction, defined on the interval 0.0 ... 360.0 *)

(* Declarations *)

VAR
alrFunctionValues: ARRAY[0..360] of LREAL;
alrFourierCoeffsA: ARRAY[0..100] of LREAL;
alrFourierCoeffsB: ARRAY[0..100] of LREAL;
etDiag: PD_GlobalDiagnostic.ET_Diag;
etDiagExt: PD_PacDriveLib.ET_DiagExt;
END_VAR

(* Prepare table with function values *)

FOR diJ: = 0 TO 359 DO
alrFunctionValues[diJ]: = FC_TestFunction(DINT_TO_LREAL(diJ) + 0.5);
END_FOR

(* Calculate Fourier Coefficients *)

FC_FourierCoefficients(
i_lrXPeriod: = 360.0,
i_diNumberOfIntervals: = 360,
i_plrFunctionValues: = ADR(alrFunctionValues[0]),
i_diMaxIndex: = 50,
i_plrFourierCoefficientsA: = ADR(alrFourierCoeffsA[0]),
i_plrFourierCoefficientsB: = ADR(alrFourierCoeffsB[0]),
q_etDiag => etDiag,
q_etDiagExt => etDiagExt);

(* Now the Fourier Coefficients till the 50th harmonic have been calculated and copied to the arrays alrFourierCoeffsA[] and alrFourierCoeffsB[]. *)

MaxIndexRange

Enumeration name:

MaxIndexRange

Enumeration value:

61

Description:

MaxIndex is outside the valid range.

Issue

Cause

Solution

-

At the input i_diMaxIndex, an invalid value has been applied.

At the input i_diMaxIndex, a value greater than or equal to 1 must be transferred.

NumberOfIntervalsRange

Enumeration name:

NumberOfIntervalsRange

Enumeration value:

59

Description:

NumberOfIntervals is outside the valid range.

Issue

Cause

Solution

-

At the input i_diNumberOfIntervals, an invalid value has been applied.

At the input i_diNumberOfIntervals, a value greater than or equal to 2 must be transferred.

Ok

Enumeration name:

Ok

Enumeration value:

0

Description:

Ok

The coefficients have been calculated successfully.

PointerFourierCoefficientsAInvalid

Enumeration name:

PointerFourierCoefficientsAInvalid

Enumeration value:

62

Description:

The pointer VourierCoefficientsA is invalid.

Issue

Cause

Solution

-

At the input i_plrFourierCoefficientsA, an invalid value has been applied.

At the input i_plrFourierCoefficientsA, a value not equal to 0 must be transferred.

PointerFourierCoefficientsBInvalid

Enumeration name:

PointerFourierCoefficientsBInvalid

Enumeration value:

63

Description:

The pointer VourierCoefficientsB is invalid.

Issue

Cause

Solution

-

At the input i_plrFourierCoefficientsB, an invalid value has been applied.

At the input i_plrFourierCoefficientsB, a value not equal to 0 must be transferred.

PointerFunctionValuesInvalid

Enumeration name:

PointerFunctionValuesInvalid

Enumeration value:

60

Description:

The pointer FunctionValues is invalid.

Issue

Cause

Solution

-

At the input i_plrFunctionValues, a null pointer has been transferred.

At the input i_plrFunctionValues, the address of the memory containing the value table must be transferred.

XPeriodRange

Enumeration name:

XPeriodRange

Enumeration value:

58

Description:

XPeriod is outside the valid range.

Issue

Cause

Solution

-

At the input i_lrXPeriod, a number smaller than Gc_lrZeroTolerance has been applied.

i_lrXPeriod must be greater than 0.