Example Code

Total Harmonic Distortion (THD)

Code and Documents

Attachment

Overview

A 1 kHz tone is generated, and its harmonic spectrum is shown for various types of distortion, with the Total Harmonic Distortion (THD) in % relative to the fundamental tones level.

Description

This example demonstrates the use of Signal Processing functions to introduce distortion and perform analysis on the resulting signal. A simulated sine wave of 1 kHz is used as the base signal, with various distortion options. The frequency power spectrum and harmonic levels on the distorted signal are then displayed along with the Total Harmonic Distortion. 

Hardware and Software Requirements

Software

  • LabVIEW NXG 1.0 (or compatible)

Steps to Implement or Execute Code

The code can be run as-is since all processing is done on a simulated signal.

1. Run the VI.
2. Try changing the Amplitude (V RMS) and notice the observe in the graphs.
3. Try changing the Distortion Type and observe the change in the graphs.
4. Try changing the Relative distortion (%) and observe the change in the graphs.
5. Click the Stop button to stop the VI.

Additional Information or References

Charlie J.
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors