image thumbnail

Computes the Total Harmonic Distortion (THD) of a signal

version (2.72 KB) by yoash levron
Useful in power systems and audio systems


Updated 22 Feb 2013

View License

function [ THD, ph, amp ] = compute_THD( t,x, freq )

Written by Dr. Yoash Levron
February 2013.

Computes the Total-Harmonic-Distortion (THD)
of a signal x(t). The amplitude and phase of the basic harmonic are also computed. These values are typically useful in power systems, audio signal processing, and other related fields.

The function computes the basic harmonic
of the signal, in the form:
x(t) = amp*cos(w*t - ph) + (higher Harmonics)
where : w = 2*pi*freq
so 'amp' and 'ph' are the phase and amplitude
of the basic harmonic.
DC offset does not affect THD.

t - [sec] time vector. (should be periodical with basic harmonic 'freq')
x - signal vector.
freq - [Hz] frequency of the basic harmonic.

THD - total harmonic distortion (the scale is 1 = 100%).
ph - [rad] phase of the basic harmonic.
amp - Amplitude of the basic harmonic.

Cite As

yoash levron (2021). Computes the Total Harmonic Distortion (THD) of a signal (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!