A DLP example. I did this to quickly check how harmonics are affecting the wideband power measurement.

The analyser should be set up so the signal and it's harmonics are visible in a single sweep. The DLP takes power of the highest peak (HIPK), then it adds power of all harmonics above 26 dBc. Then it reports the difference between HIPK and the summed power.

`FUNCDEF THD_DB,@`

LCLVAR NP,0 ;; number of peaks

LCLVAR HIPK,0 ;; highest peak amplitude

LCLVAR I,0 ;; peak number

LCLVAR P,0

LCLVAR P1,0

LCLVAR YPOS,700 ;; current vertical display position

LCLVAR PWR,0 ;; total power

LCLVAR FFR,0 ;; fundamental frequency in display units

SNGLS

EM

TS

MKPK

MOV HIPK,MKA

SUB MKPT,HIPK,26 ;; harmonic level > 26dBc increases total power by more than 0.01dB

MOV MKPX,3

HD

MOV NP,PEAKS TRB,TRA,AMP

PA 100,YPOS

IF NP,GE,25;THEN

TEXT %TOO MANY PEAKS: %

DSPLY NP,3,0

ABORT

ENDIF

IF NP,EQ,0;THEN

TEXT %NO PEAKS FOUND%

ABORT

ENDIF

SUB FFR,TRB[1],1

TEXT %NPEAKS = %

DSPLY NP,2,0

SUB YPOS,YPOS,40

REPEAT

ADD I,I,1

MOV P,TRB[I]

SUB P1,P,2

IF TRA[P],GE,TRA[P1];THEN

ADD P1,P,2

IF TRA[P],GT,TRA[P1];THEN

IF P,LT,FFR;THEN

TEXT %NON HARMONIC PEAK: %

DSPLY P,3,0

ABORT

ENDIF

SUB P,TRA[P],600

MPY P,P,LG

DIV P,P,60.0

ADD P,RL,P

IF I,LE,12;THEN

PA 150,YPOS

SUB P1,P1,3

DIV P1,P1,600.0

MPY P1,P1,SP

ADD P1,FA,P1

DIV P1,P1,1E6

DSPLY P1,4,0

TEXT %MHz = %

DSPLY P,5,2

SUB YPOS,YPOS,40

ENDIF

EXP P,P,10

ADD PWR,PWR,P

ENDIF

ENDIF

UNTIL I,GE,NP

LOG PWR,PWR,10

PA 100,YPOS

TEXT %SUM POWER = %

DSPLY PWR,5,2

SUB YPOS,YPOS,40

SUB PWR,PWR,HIPK

PA 100,YPOS

TEXT %DISTORTION = %

DSPLY PWR,5,2

TEXT %dB%

@

DLPs do not allow comments. ";;" comments are removed by the script I use for uploading.