FC_FourierCoefficients - General Information
Type: |
Function |
Available as of: |
V1.0.3.0 |
Versions: |
Current version |
Calculation of Fourier coefficients
A periodic function f which is defined on an interval [a, b] can be represented as a Fourier series under suitable conditions:
Here, the Fourier coefficients ak and bk are provided by:
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_plrFourierCoefficientsA (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).
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 |
General library-independent statement on the diagnostic. A value not equal to ET_Diag.Ok corresponds to an diagnostic message. |
|
q_etDiagExt |
POU-specific output on the diagnostic. q_etDiag = ET_Diag.Ok -> Status message q_etDiag <> ET_Diag.Ok -> Diagnostic message |
q_etDiag |
q_etDiagExt |
Enumeration value |
Description |
---|---|---|---|
OK |
0 |
Ok |
|
InputParameterInvalid |
61 |
MaxIndex is outside the valid range. |
|
InputParameterInvalid |
59 |
NumberOfIntervals is outside the valid range. |
|
InputParameterInvalid |
62 |
The pointer VourierCoefficientsA is invalid. |
|
InputParameterInvalid |
63 |
The pointer VourierCoefficientsB is invalid. |
|
InputParameterInvalid |
60 |
The pointer FunctionValues is invalid. |
|
InputParameterInvalid |
58 |
XPeriod is outside the valid range. |
(* 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[]. *)
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. |
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. |
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. |
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. |
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. |