Signal quality when outputting signals with digital analog outputs – distortion factor

The modular Beckhoff I/O system IP20/IP67 features analog outputs in various designs, e.g. the EL41xx, EL47xx, EJ4xxx or EP4xxx series ("xx" or "xxx" stands for the respective specific product number).

What all devices have in common is that they

Overall, this means that a smooth signal curve cannot be produced, and instead a stepped (in terms of time and amplitude) signal curve is seen at the output (particularly if there is no internal or external signal smoothing):

Signal quality when outputting signals with digital analog outputs – distortion factor 1:
Analog signal (schematic, discretized)

The actually specified analog signal (blue) can only be electrically mapped by dedicated interpolation points (red dots). As a result of this, the real output signal is stepped both in the time dimension and in the amplitude dimension – it is discretized.

See the following example with the EL4732 (analog output ±10 V, max. 100 kSps, oversampling-capable):

     Declaration:

   FUNCTION_BLOCK FB_sine_generator
   VAR CONSTANT
       // TwinCAT / Terminal configuration:
       CnMaxIdx           : UDINT  :=10;    // Fixed amount for Oversampling
       tCycleTime         : LTIME  :=LTIME#1MS; // Configured task cycle time
       nOversampling      : UDINT  :=10;    // Used oversampling of the terminal
   END_VAR
   VAR_INPUT
       // Output configuration:
       rFreq_Hz           : LREAL   :=1;    // Destination frequency
       rAmplitude         : LREAL   :=1;    // Destination amplitude
   END_VAR
   VAR_OUTPUT
       bError             : BOOL;
       arOut              : ARRAY[1..CnMaxIdx] OF LREAL;
       aiOut_EL4732 AT%Q* : ARRAY[1..CnMaxIdx] OF INT; // 10 V max
   END_VAR
   VAR
      nIdx                : UDINT;
      rPosition            : LREAL := 0;   // Init, if for startup important
      rPeriod_Sec,
      rStep,
      rPositionPi,
      rValue              : LREAL;
   END_VAR

     Execution:

// This code generates values of a sinus for an EL4732 analog output terminal
   IF nOversampling > CnMaxIdx OR (nOversampling = 0) OR
    (tCycleTime = LTIME#0S) THEN
       bError := TRUE;
   ELSE
       bError := FALSE;
       rPeriod_Sec := 1 / rFreq_Hz;
       
       // Calculate a step width (percentual of 1):
       // Divide the cycletime by the destination periode and ovs factor:
       rStep := (1E-9 * LTIME_TO_LREAL(tCycleTime))
                  / (rPeriod_Sec * UDINT_TO_LREAL(nOversampling));
       // (Note:
       // factor of 1E-9 for value in seconds due to LTIME data type's unit is ns)
   
       // fill the array bound to oversampling output for one task cycle
       FOR nIdx := 1 TO nOversampling DO
   
           // Calculate next X-Position of the sine:
           rPosition := FRAC(rStep + rPosition);
           // (usage of FRAC for saturation of rPosition to < 1)
   
           // Calculate percent from 1 to an angle of radians:
           rPositionPi := (rPosition * 2 * PI);
           
           // Calculate next Y-Value:
           rValue := rAmplitude * SIN(rPositionPi);
           arOut[nIdx] := rValue; // allocate to array
   
           // Convert output to PDO of EL4732:
           aiOut_EL4732[nIdx] := LREAL_TO_INT((rValue / 10) * 16#7FFF);
       END_FOR
   END_IF
Signal quality when outputting signals with digital analog outputs – distortion factor 2:

Using the sample programs

This document contains sample applications of our products for certain areas of application. The application notes provided here are based on typical features of our products and only serve as examples. The notes contained in this document explicitly do not refer to specific applications. The customer is therefore responsible for assessing and deciding whether the product is suitable for a particular application. We accept no responsibility for the completeness and correctness of the source code contained in this document. We reserve the right to modify the content of this document at any time and accept no responsibility for errors and missing information.

Explanation of the example

So much for the theory. Now, in some tasks the question may arise as to the analog signal fidelity in relation to the theoretical signal. There are various evaluation criteria for this, for instance the distortion factor.

For sinusoidal signals, the distortion factor states the harmonic content of the real signal in relation to the total signal, in other words the magnitude of the contents in the signal that do not correspond to the ideal sine wave, i.e. that distort it. The distortion factor lies between 0 and 1; in general, a low distortion factor close to 0 shows a real signal that is very close to an ideal sine wave and contains few (undesirable) harmonics.

Signal quality when outputting signals with digital analog outputs – distortion factor 7:
Distortion factor: ideal sine, output, measurement and evaluation

Measurement and evaluation as follows:

In the following example, this distortion factor calculation is to be performed on the sinusoidal output of an EL4732 (±10 V, 10 kSps per channel), where f = 1 kHz and RLoad = 1 kΩ.

A simple oscilloscope with FFT function is used: the 1 kHz sinusoidal signal can be seen in the time range (blue) with 10-fold oversampling:

Signal quality when outputting signals with digital analog outputs – distortion factor 8:
Sinusoidal output signal of the EL4732 and FFT evaluation

The FFT evaluation is green. The RMS values [dBV] read from this (note: observe the base line "M") and converted to Vrms = 10-(dBV/20) are as follows:

Frequency [kHz]

RMS value [dBV]

RMS value [Vrms]

1

-4

0.630

2

-51

0.0028

3

-46

0.005

4

-60

0.001

5

-53

0.002

According to the equation:

Signal quality when outputting signals with digital analog outputs – distortion factor 9:

a distortion factor of 0.92% results.