I have an assignment for a class where I have to calculate the thd of a signal using MATLAB.

I think I have a pretty good understanding of how this should be done, however, my professor instructed that we use only the first harmonic to calculate the thd.

Maybe my understanding is bad, but I thought the thd was calculated using the first harmonic (fundamental frequency) in relation to the magnitudes of the (other) harmonics. I have looked everywhere online and have not found anyways to calculate thd using only the first harmonic.

I have added the specific assignment phrasing below.

A .mat file is given with this project that contains one period of a periodic signal. Use the formulas of the exponential Fourier series and the definition of the total harmonic distortion (Audio engineer’s formula) to calculate the total harmonic distortion of the given signal.In your calculations, you have to just find thefirst harmonic. You need to manipulate the THD formula and represent it as a function of only the first harmonic.

Upon emailing my teacher to clarify if he wanted the thd with respect to the first "additional" harmonic he said he meant fundamental frequency when he said first harmonic.

  • 1
    \$\begingroup\$ Your professor probably means the first harmonic AFTER the fundamental. The fundamental isn't a harmonic. A harmonic is defined as an integer (whole number) multiple of the fundamental frequency. \$\endgroup\$
    – John D
    Apr 29, 2019 at 19:17
  • 1
    \$\begingroup\$ so then your professor uses very uncommon vocabulary. the first harmonic is a harmonic, not the fundamental; but anyways, I'm just mentally removing the words "first harmonic" from your question and replacing them with "fundamental", because you (and your professor) agree it's the fundamental, right? \$\endgroup\$ Apr 29, 2019 at 19:33
  • 1
    \$\begingroup\$ Because language and maybe the prof just wants the students to know that this is the process to calculate THD but he doesn't want to be tedious and therefore accepts a truncated form of the work. \$\endgroup\$
    – DKNguyen
    Apr 29, 2019 at 19:58
  • 1
    \$\begingroup\$ In my textbooks, the harmonic at frequency \$nf_0\$ was the nth harmonic. That means the fundamental and the "first harmonic" are two ways of saying the same thing. \$\endgroup\$
    – The Photon
    Apr 29, 2019 at 20:58
  • 1
    \$\begingroup\$ I remember this well because I had assumed once that the first harmonic was at \$2f_0\$ and got accused of cheating because I got the same wrong answer as other people who made the same terminology error. \$\endgroup\$
    – The Photon
    Apr 29, 2019 at 21:00

2 Answers 2


I'm rolling this up into an answer since it is important. Using a 1Hz square wave as an example, the frequency components are 1Hz, 3Hz, 5Hz, 7Hz, 9Hz, etc... all the way up to infinite.

Fundamental: 1Hz, by any definition. The lowest frequency. The period of the waveform.

Harmonic: The technically accurate definition for harmonic is an integer multiple of the fundamental. Therefore, the nth harmonic is n times the fundamental frequency. In the example, 3Hz is the third harmonic and 1Hz is the first harmonic (aka the fundamental).

However, you will find many engineers use "harmonic" when they mean to say overtone.

Overtone: An overtone refers to the most prominent frequency components in the spectrum of a signal in numerical sequence above the and NOT including the fundamental. Therefore, in the example, the first overtone is 3Hz, and the second overtone is 5Hz. 1Hz, the fundamental frequency, is not an overtone at all.

To make thing worse, you can also find engineers using both the technically correct, and commonly understood but incorrect definitions of "harmonic" where the meaning might changes based on context since we already know what we're talking about. For example, I say square waves are made up of only odd harmonics (technically correct), but then I might absentmindedly say that 3Hz is the first harmonic in in a 1Hz square wave, when I really should be saying first overtone or third harmonic.

For the record, I have never heard "overtone" used in any engineering class of mine. Ever. The only reason I know of it is from music classes. It needs to be a thing because those musicians have been talking about frequencies far longer than we have. They already figured it out.

  • \$\begingroup\$ @hackedhacker77 Now that I've said all that, you need to find out from your prof if he literally wants you to use only the fundamental/1st harmonic when calculating THD and pretend like no other frequency components exist...which would give a trivial answer of zero, or if he means for you take just the fundamental component as the only frequency component in your pristine signal, using that as a reference, and treating all other frequency components as noise/distortion. \$\endgroup\$
    – DKNguyen
    Apr 29, 2019 at 20:59
  • \$\begingroup\$ Thank you. Given this information and given what the professor has requested, is there a method that you would suggest using? \$\endgroup\$ Apr 29, 2019 at 21:00
  • \$\begingroup\$ I hadnt read your comment yet before responding. I think that is probably the best suggestion. My professor was very curt in my previous clarification email, so i was hesitant on sending another, but i should get clarification \$\endgroup\$ Apr 29, 2019 at 21:01
  • \$\begingroup\$ Just say that if you ONLY use the 1st harmonic/fundamental in the THD calculations, wouldn't the THD = 0 since there are no other frequency components being used in the calculation? Which frequencies should you treat as the pristine signal and which are the distortion and noise? \$\endgroup\$
    – DKNguyen
    Apr 29, 2019 at 21:04

contains one period of a periodic signal.

Means that you know the period, let's call it \$N\$, and thus, the frequency \$f=\frac1N\$, of your fundamental.

You know that all the higher-order harmonics have frequencies that are multiples of that frequency.

Now, if you had the power of the fundamental signal only, you could simply subtract that power from the total signal power (which is really just the sum of the magnitude squares of your signal), and had the power in the noise + harmonics. If noise is absent, you'd only have the total harmonic power, and divided by the signal power that becomes your THD.

So, filter out with a low pass filter that cuts off between \$f\$ and \$2f\$, and calculate energy before and after. Done!

With @Toor's comment:

Yeah, what your professor might mean (contrary to her/him using total harmonic distortion) is that for the distortion calculation, you should only use the fundamental relative to the first harmonic; so, same idea: filter with a cutoff after \$2f\$, and do your THD calculations on that.

  • \$\begingroup\$ Thank you for your reply. This is a little bit what I had initially thought, but wouldnt using the total signal power be "using" the other harmonics in my calculation? \$\endgroup\$ Apr 29, 2019 at 20:13
  • \$\begingroup\$ hence the filtering. \$\endgroup\$ Apr 29, 2019 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.