Author Topic: Roughly computing harmonic distortion from fft display.  (Read 4860 times)

0 Members and 1 Guest are viewing this topic.

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Roughly computing harmonic distortion from fft display.
« on: December 31, 2016, 09:14:59 pm »
I'm curious if I can roughly ball park % harmonic distortion of a sine wave using my fft on the scope.

For instance, let's say I have my fundamental tone reading -10 db on the scope, and my second harmonic is at -20. Assuming no other harmonics, can I compute a percentage? I'm not really clear how to do this. Also, what if there are more than one harmonics?

I'm not looking for super accuracy, just a rough notion.
 

Offline barry14

  • Regular Contributor
  • *
  • Posts: 102
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #1 on: December 31, 2016, 10:26:48 pm »
Yes you can.  In your example if the second harmonic is 10 dB less than the fundamental (-20 is 10 dB less than -10), then in magnitude, the second harmonic magnitude is 0.316 of the fundamental.  That would mean an harmonic distortion of 31.6%.  If there are more harmonics, they should be combined as a square root of the sum of the squares and then divided by the fundamental.  For example, if the third harmonic was -30 db (or 20 dB less than the fundamental), then its magnitude is 0.1 of the fundamental.  Combining the second and third harmonics in the root-sum-square method yields a value of 0.331.  Thus the harmonic distortion is 33.1%.  Note that this value is approximate because the FFT does not give the phase relationship between the harmonics.  However, this method will give you a reasonable approximation.
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #2 on: December 31, 2016, 10:55:29 pm »
Care to elaborate on this root sum square thing? Sorry if it's noob question!
 

Offline barry14

  • Regular Contributor
  • *
  • Posts: 102
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #3 on: January 01, 2017, 02:23:01 am »
For the example given:
    Take the square of 0.31 (magnitude of the 1st harmonic) = 0.099856
     Take the square of 0.1 (magnitude of the 2nd harmonic) = 0.01
    Add to get total of the squares: 0.109856
    Take the square root of the total: 0.331
    Divide by the fundamental (=1): 0.331
    Convert to percentage (X100): 33.1%

If more than 2 harmonics, simply square each harmonic and add to the previous total, then take square root of the new total to get the new value of harmonic distortion.  This procedure is usually designated as RSS (root-sum-square) where the operations are done in reverse order: first square, then sum, then take square root.  Hope this helps.
« Last Edit: January 01, 2017, 02:24:52 am by barry14 »
 
The following users thanked this post: Dan Moos

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11632
  • Country: my
  • reassessing directives...
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 8646
  • Country: gb
Re: Roughly computing harmonic distortion from fft display.
« Reply #5 on: January 01, 2017, 08:13:59 pm »
https://en.wikipedia.org/wiki/Total_harmonic_distortion

That's one definition of THD (THDF), but there are several others. Some use an amplitude ratio, and some use a power ratio. Some reach a maximum of 100%, when the signal is all harmonics with no fundamental at all. Most can go way above 100%, when the harmonics are stronger than the fundamental. You need to take care that the definition of THD you are using matches the application.
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #6 on: January 02, 2017, 06:05:49 pm »
Ok, that's all making sense, but I have one hang up that comes probably from my lack of a firm grasp on working with logarithms.

In your (barry14's ) first response, you used my example of a -10db fundamental, and a -20db first harmonic. You pointed out that the difference in magnitudes was, thus, 10 db. I was with you still at that point.

Next is where I get confused. You said that 10db difference  makes that harmonic .316 of the fundamental. That gives me two questions. First, both on a log chart, and on my calculator, the base 2 log of 10 is 3.22. The the base 2 log of 9 is 3.16 though. Did you make an error, or am I missing something?

Also, I'm not clear on why the decimal point is moved to the left. Why do you turn 3.16 into .316?

Thanks for your patience with my silly questions!
 

Offline basinstreetdesign

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: ca
Re: Roughly computing harmonic distortion from fft display.
« Reply #7 on: January 02, 2017, 08:14:04 pm »
Not silly at all!

First, everything everybody has said above is correct.  However you must keep in mind two things:
1 - All calculations including logarithms are done in base 10 arithmetic not base 2.
2 - All amplitudes are measured respective of the amplitude of the fundamental, not the top of your scope (or should be).

So, since the amplitude of the 2nd harmonic, as you correctly called it, is at -10dB with respect to the fundamental, it is at a voltage level of 10**(-10/20) = .316 of the fundamental.  When all of the harmonics are similarly treated and the resulting voltages plugged into the RMS (Root Mean Square) formula reported by coppice, the correct answer pops out.

This equation applies since we are considering voltages (or currents).  If we were considering electrical power then the "20" in that equation would turn into "10" and all of the same arguments would apply.
STAND BACK!  I'm going to try SCIENCE!
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #8 on: January 02, 2017, 08:32:59 pm »
is 10** the same as 10 squared? I'm not familiar with that notation.

Do I even have to compute any logs  at all? I feel I should have to convert the log magnitudes my scope gives me into a linear scale so the percentages make sense. Am I correct?

I assume, for my calculations, I should treat the magnitude of my fundamental as displayed by the scope as "1". So with my -20db fundemental. -20db is "1" in my calcs, yes?

It would be awesome if you could step through the process, assuming nothing about my level of understanding! I cant find a way o get .316 from what you showed me, so I'm either misunderstanding your notation, the process, or both.

I realize I could have the scope display a linear voltage, but I really want to learn to do this with the log display for the obvious reason that its way more convenient a view.

Thanks for your time!
 

Offline basinstreetdesign

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: ca
Re: Roughly computing harmonic distortion from fft display.
« Reply #9 on: January 02, 2017, 10:51:04 pm »
10**() refers to "10 raised to the power of" so 10**(-10/20) is 10 to the power of (-1/2) which is .316.

Do I even have to compute any logs  at all? I feel I should have to convert the log magnitudes my scope gives me into a linear scale so the percentages make sense. Am I correct?

Actually no logs are necessary.  You would use log(base 10) if you were converting from volts to dB.  Since we are going the other way, use powers.

The dB level of a voltage compared to a reference level signal, Vref, is equal to 20 x log[base10](V/Vref).  In this case we may assume Vref is 1.
Converting back to Volts then V = Vref x 10**(dB/20).

I assume, for my calculations, I should treat the magnitude of my fundamental as displayed by the scope as "1". So with my -20db fundemental. -20db is "1" in my calcs, yes?

Since we are calculating the RELATIVE amplitudes of harmonics and their total distortion we may assume the fundamental has a Voltage level of 1 (peak, RMS, P-P, it doesn't matter) and figure everything from there.  For the purposes of this discussion the actual signal level may be mV, V, KV, it also doesn't matter.

So, the fundamental is assigned the value of 0 dB when we are dealing with this.  All of the harmonics are measured relative to that so your 2nd harmonic would sit at -10 dB.  The negative sign is important and indicates that the amplitude of the 2nd is LESS than the fundamental.  If you have any other harmonics then they would also be measured at some dB level compared to the 0dB fundamental, negative being LESS and positive being MORE.

So, with the fundamental assigned the value of 0 dB and the 2nd Harm at -10dB then we first calculate its voltage level of the 2nd harm. as V2nd = 10**(-10/20) = 0.316 V assuming the fundamental level is 1 V.

We then do similarly with any other harmonics that show up on the FFT, square those values and add up these RELATIVE voltages.
Next take the square root of this total and divide it by the fundamental amplitude (which is as we said before) is 1.

This result is the RMS voltage level of all harmonics combined.
The only thing left to do is multiply by 100 to convert that to a percentage value.  This percentage value is the magnitude of the voltage of all harmonics combined as compared to the fundamental.

In your first example, if you had only the 2nd harmonic then you would have 100% x 0.316 = 31.6% harmonic distortion.
STAND BACK!  I'm going to try SCIENCE!
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #10 on: January 03, 2017, 12:58:30 am »
Ok, I'm a lot closer to fully understanding this now. My math knowledge is the kind of the strange hodge podge one gets when one only formally has a high school math level (24 years ago!), but has acquired various things over the years from the hobby.

If I calculate (on a calculator) 10^(1/2), I get 3.16.  you wrote 10^(-1/2), but  wouldn't that just be -3.16? I can't figure out how to get my calculator to do negative exponents, so I can't confirm I have that right.

Anyway, how do you get .316? why is the decimal point moved?

also, am i understanding that you got 1/2 by reducing the fraction 10/20? so if I was dealing with a difference of, say, 11db, id do 10**(-11/20)?
 

Offline basinstreetdesign

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: ca
Re: Roughly computing harmonic distortion from fft display.
« Reply #11 on: January 03, 2017, 02:58:22 am »
AHA! So you have a calculator that wont do negative exponents!  Yes the negative sign is important and no it doesn't just translate to -3.16.  The negative sign means that the result of 10^(1/2) is inverted after taking the power.  It just so happens that 1/3.16 = 0.316.  This is the consequence of the square root of 10.

Use the calculator Windows gives you in Scientific mode so you get more functions.
Quote from: Dan Moos

link=topic=80739.msg1104897#msg1104897 date=1483405110

am i understanding that you got 1/2 by reducing the fraction 10/20? so if I was dealing with a difference of, say, 11db, id do 10**(-11/20)?

Yes, exactly.
STAND BACK!  I'm going to try SCIENCE!
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #12 on: January 03, 2017, 04:26:17 am »
ok, its all making sense!

just to make sure, I'm gonna run  my analysis of a signal i have in front of me right now. Hopefully you can tell me if my process is correct.

I'm looking at the FFT of a 10k sine wave. Its fundamental is conveniently at 0dB.
I have 3 prominent harmonics at 20k, 30k, and 50k. Their magnitudes are -25dB, -44dB, and - 53dB respectively.

To compute the first harmonic, 10**(25/20) = 17.78.   1/17.78 = .562

Second: 10**(44/20) = 158. 1/158 =  .006

Third: 10**(53/20) = 447.  1/447 = .002

Ok, next I square  the three harmonics. .316, .000036, .000004.

I sum them: .31604 (higher harmonics clearly don't effect much here)

I take the square root of that sum = .562 (again, only that first harmonic seems to have mattered in the end)

I divide by the fundamental. 10**(20) = 1
.562/1 =.562 (obviously!)

.562 * 100 = 56% harmonic distortion. Ok, here's what seems wrong to me. Th sine wave I see on my screen isn't perfect, but I am surprised that it has 50% THD. Its a tad asymmetrical vertically,  so the prominent 2nd harmonic makes sense, but if it looks pretty good. Does 56% THD make sense for a almost good looking wave?

Ok, next I switche4d to a linear vertical scale. Fundemental is at 920 mV. Second harmonic is at 88mV.

88/920 is .096, or basically 10 percent. That number sounds more like what I see. Shouldn't I get the same results both ways?
 

Offline basinstreetdesign

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: ca
Re: Roughly computing harmonic distortion from fft display.
« Reply #13 on: January 03, 2017, 05:08:46 am »
To compute the first harmonic, 10**(25/20) = 17.78.   1/17.78 = .562

OOPs:    1/17.78 = 0.056 not .562

Everything else is correct so the end result is .0562 or 5.62% THD.

Switching to the linear scale doesn't mean you don't still have to square, sum and root the numbers.
But if the harmonic is measured at -25 dB on the log scale it should be 56mV on the linear scale.  96mV sounds out to me especially if the fundamental is slightly below 1V at 960mV.

Yes, all of the other harmonics have negligible effect since they are so far down the scale.  In fact, since you are going for a rough estimate anyway, if anything is farther than about 4 dB farther down than the worst offender they can be ignored as they will contribute an error of less than 10% of the resultant number IMHO.
« Last Edit: January 03, 2017, 05:22:54 am by basinstreetdesign »
STAND BACK!  I'm going to try SCIENCE!
 

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #14 on: January 03, 2017, 05:19:05 am »
 ::) Doh!

Ok, that's 5 percent THD. That jives with what the wave looks like.

But how come I got a different result when working with a linear voltage scale. Same wave, but linear scale. Fundamental is 920mV. Second tone is 88mV

88/920 .096., or ~10%. Shouldn't they be close top the same? I can change things a bit by fooling with the cursors (closer t0 7), so is it maybe a matter the linear range being too difficult to get proper cursor placement on?

I guess my question is, all else being equal, should I get the same %thd calculation both ways? And if so, would it be safe to say using the dB scale will yeild more accurate results with cursor placement?   
 

Offline basinstreetdesign

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: ca
Re: Roughly computing harmonic distortion from fft display.
« Reply #15 on: January 03, 2017, 05:27:23 am »
Shouldn't they be close top the same? I can change things a bit by fooling with the cursors (closer t0 7), so is it maybe a matter the linear range being too difficult to get proper cursor placement on?

I guess my question is, all else being equal, should I get the same %thd calculation both ways? And if so, would it be safe to say using the dB scale will yeild more accurate results with cursor placement?   

Yes, you should get the same answer both ways. :)
and yes, usually the dB scale usually gives more accurate results because of cursor placement.
Cheers
STAND BACK!  I'm going to try SCIENCE!
 
The following users thanked this post: Dan Moos

Offline Dan MoosTopic starter

  • Frequent Contributor
  • **
  • Posts: 357
  • Country: us
Re: Roughly computing harmonic distortion from fft display.
« Reply #16 on: January 03, 2017, 05:31:07 am »
Thank you so much for patiently getting me  through this business!

Happy New Year!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf