View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Computes the Total Harmonic Distortion (THD) of a signal

5.0 | 3 ratings Rate this file 36 Downloads (last 30 days) File Size: 2.72 KB File ID: #40455 Version: 1.0
image thumbnail

Computes the Total Harmonic Distortion (THD) of a signal


yoash levron (view profile)


Useful in power systems and audio systems

| Watch this File

File Information

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.

Required Products MATLAB
MATLAB release MATLAB 7.2 (R2006a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
05 Dec 2016 jing zhang

02 Oct 2016 Mehdi Safaeian

12 Nov 2014 Teodor Laurentiu

I do have a common question regarding the distortion of a product.
In the technical paper of the product is written the following:

Distortion: less than 0.08% (at 1 kHz, reference level)

So neither the reference level nor the gain Setting is given. Assuming that the gain is 1, is there a plausible way to calculate the reference level from the given data.

PS: Sampling rate is 48 kHz

Thank you in advance for answering!!

Comment only
13 Aug 2014 Limory

Limory (view profile)

Contact us