Head-Fi.org › Forums › Misc.-Category Forums › DIY (Do-It-Yourself) Discussions › THD measurement wheeze
New Posts  All Forums:Forum Nav:

THD measurement wheeze

post #1 of 23
Thread Starter 

Things rattle around in your head (they do in mine anyway), then eventually they fall out.

 

I'd really like a straightforward way of measuring THD, preferably one not involving spending a great deal of money.

 

It occurred to me to write a program to create some .wav files with tones at 50Hz, 1k and 20k, with the left and right tracks 180 degrees out of phase.

 

Then build a simple very-low-distortion summer with 2 inputs with amplitude controls.

 

Pass one channel through the amp and thence into the summer. Pass the other direct into the summer. Adjust the amplitudes for the minimum residual.

 

I'm fortunate in possessing a USB oscilloscope. It does maths and has a function showing instantaneous RMS. This would make it fairly easy to adjust for the minimum residual. You'd set the RMS value of the DUT output fundamental to a whole number, after that it's just arithmetic.

 

The minimum vertical resolution of the 'scope is 10mV/div., so some additional gain after the summer might be desirable.

 

Maybe I'd be better using a second PC and soundcard set up as a spectrum analyser. I don't know if I could get one PC running 2 pieces of software to talk to 2 soundcards. 

 

Obviously there's a phase error (delay) caused by passing the signal through the amp. This might not be the end of the world, though. I'd prefer not to be messing with the relative phase of the 2 channels since the outputs will be closest to identical if they are inversions of one another, but writing a program to output the signals to a soundcard in real time with phase shifting in small increments is only a bit more difficult than writing a program to output .wav files.

 

 

Anyway I'm going to take a stab at it and see how far I get.

 

I've drawn up a circuit for the summer. I'll get around to a PCB in the next day or so.

 

The first thing is to see how good the nulling is between the channels without a test item in place.

 

Anybody got any thoughts or comments? Anybody know what order the delay through the amplifier is likely to be? Of course I can measure that with a square wave.

 

w

post #2 of 23

What sort of precision are you hoping to achieve?

With distortion in many of the DIY amps vanishingly low,

you will need several 0's after the decimal place...

 

I hope you can get some good precision, even if it only

says the amp is not behaving badly rather than exactly

how well it is doing.

 

Cheers!

post #3 of 23
Quote:
Originally Posted by wakibaki View Post

I'd really like a straightforward way of measuring THD, preferably one not involving spending a great deal of money.

 

RMAA.

 

Quote:

It occurred to me to write a program to create some .wav files with tones at 50Hz, 1k and 20k, with the left and right tracks 180 degrees out of phase.

 

If it turns out that RMAA (or something like it) won't work and you really do have to roll your own, I'd recommend you start a bit higher up the stack. There are several free domain-specific language systems for audio synthesis: Csound, ChucK, SuperCollider...

 

Basically, you write a short script telling the DSL interpreter what sounds you want it to generate.

 

There isn't much call for writing low-level sound synthesis code in this case, unless you're trying to replace RMAA and such, and you'd need a pretty good reason to reinvent those wheels.

 

Quote:
I'm fortunate in possessing a USB oscilloscope.

 

That's not going to be terribly helpful. It will doubtless have an 8-bit vertical resolution, which means its noise floor can't be any better than -48 dBFS, which in turn means distortion below ~0.4% disappears into the noise floor. It only gets that good if the scope's analog front-end adds no noise of its own and the ADC is a perfect error-free digitizer.

 

(Re-reading this, I realize that I'm ignoring the fact that the scope's input stage will have a different input range and will probably have some analog gain before the ADC, so the numbers won't come out exactly that way. But, we're talking about differences within an order of magnitude, so it doesn't really change the conclusions you get by ignoring this fact and going on to the next paragraph.)

 

Even the lowliest on-board sound chip on a PC will be capable of 16 bit vertical resolution. Let's say it's a truly terrible implementation, and so has a noise floor of -80 dB instead of the theoretical max of -96 dB. That means the distortion doesn't disappear below the noise floor until it's less than 0.01%, which is a pretty respectable figure in its own right for THD alone. (As opposed to THD+N.) A good sound card can add another zero or two to that.

 

Quote:

The minimum vertical resolution of the 'scope is 10mV/div., so some additional gain after the summer might be desirable.

 

That's another way of stating the problems I've detailed above. But, what you're doing here is adding hardware (gain stages, analog summers) to let you use an 8-bit resolution input device when a sound card does a better job over the relevant bandwidth, simply because it is a narrow-band low-frequency device. The USB scope's strength is in capturing fast signals, not precision measurement.

 

Quote:
Maybe I'd be better using a second PC and soundcard set up as a spectrum analyser. I don't know if I could get one PC running 2 pieces of software to talk to 2 soundcards.

 

There's no need for a second PC. Almost every PC with sound output has sound input, too. You loop the test signal out of the PC, through the DUT, and back in to the PC for analysis.

 

There are sometimes grounding issues to take care of here, but using two computers would only make this easier if they're both laptops running on battery. If you use two wall-powered PCs, the grounding issues are even trickier.

 

I describe the method I used with RMAA for the PIMETA v2 here.


Edited by tangent - 8/11/12 at 7:23am
post #4 of 23
Thread Starter 

Hi, A_A!

 

Thanks for the input Tangent. I've already got a copy of RMAA. Its credibility has taken a bit of a battering so I'd like something independent of it, where I've got a bit clearer idea of the details of the internal workings, and where there's some control of the levels at which the readings are done. Plus I want to work at 50Hz and 20kHz as well if possible. I was going to buy this http://www.ebay.com.au/itm/Ultra-low-distortion-0-00005-10kHz-sine-generator-assembled-and-tested-PCB-/320946331820?pt=BI_Signal_Sources&hash=item4ab9e460ac#ht_1817wt_1398

ultra-low distortion oscillator (available in other frequencies), and build a Cordell distortion magnifier, but reports of the oscillator say it does not meet spec. The Cordell DM is ~150 euros shipped, so I may end up taking this route or something like it.

 

I have already written programs to generate the J-test signal as .wav files, so outputting a couple of sine waves 180 degrees apart is not really a problem. I'd probably use the C# libraries if I wanted to create a real-time phase-variable output run from a GUI, but only to simplify the soundcard access, I'd prefer to generate the samples explicitly so that I know exactly what's going on. 

 

If you run a program that uses the soundcard it generally takes control of both inputs and outputs, so if I was using ARTA, for example, for monitoring, I'd have a problem sending the .wavs to the output. I can probably install 2 soundcards and get each program to talk to different cards, but I've had a lot of problems with multiple-soundcard installations, that's why I thought about using 2 PCs. Your point about the ground loops is well taken, but I'm not sure that DC coupling is essential. I don't see it as an insurmountable problem anyway, at the worst 2 Atom-core fanless PCs run from a battery would solve that. I'm not giving up on the USB oscilloscope yet though, not until I've tried some experiments. 

 

If I have an output from the amplifier in volts and a residual measurement in millivolts, that is 60db down. If I have 60dB of gain in the summer, I'm starting to get something useful. 120dB down is 0.0001%. The fact that I've got only 8 bits of precision in the millivolt measurement is not really an issue. Yes, I have to be careful about noise, but a conventional THD meter needs to be careful about noise.

 

I'm probably lucky if the soundcard has better than 0.003% THD, but a pure input is not an absolute requirement to measure a distortion residual, what is required is a low null without a DUT in place, i.e good correspondence between the test signal and the nulling subtractant. Whether I can get this using 2 channels of a soundcard is the question, particularly if the time delay is not an integer multiple of the sample rate.

 

What I'll probably start with is outputting the tones using foobar, I know it's possible to set the sample rate and bit resolution. I can generate a library of .wav files with incremental delays. I'm just wondering whether to go with full-scale or fractional amplitudes. Most 24-bit soundcards only achieve <120dB SNR, which is a long way from the theoretical and I haven't quite figured out the implications of that yet. I guess it's suck it and see...

 

Thanks anyway for pushing me to think.

 

w

post #5 of 23
Quote:
I've already got a copy of RMAA. Its credibility has taken a bit of a battering

 

Really? Why? It's not like what it does is black magic. It's just signal generation and measurement. What is there to argue about?

 

All the problems I've had with RMAA in many years of use stem from operator error: if you're not careful about how you set up your measurement, it can give you worse results than the DUT is actually capable of. But, the same is true of your proposed lash-up, only more so, since you propose more independent moving parts.

 

 

Quote:
reports of the oscillator say it does not meet spec.

 

Not surprising. Those are truly heroic specs. A $5,000 to $10,000 Audio Precision rig can "only" manage about 0.0001% THD+N on its oscillator output. Granted, that's plenty good for audio, and AP have put the heroics where they matter, achieving far better frequency accuracy than your eBay PCB, for example.

 

The PCB pic doesn't have enough detail to justify the claims, and there is no schematic link. Tantalum caps and chip resistors fail to impress when they're claiming such low distortion figures.

 

I'm also skeptical that they have a basis to claim a distortion measurement that low anyway. 0.00003% for the 1 kHz version means THD+N is collectively -130 dB below the oscillator signal level. That means they need a measurement system with a THD+N floor below that level! Not impossible, but not exactly easy to believe, either.

 

 

Quote:
The Cordell DM is ~150 euros shipped

 

...and for this, you are getting a claimed -140 dB THD+N floor, and possibly the ability to drive your scope. You need to throw another, what, 80 to 100 euro at it to finish the project?

 

For about a quarter to half that, you can buy a 96 or 192 kHz 24-bit sound card, achieving a THD+N floor between -105 and -125 dB. This is good enough. The extra decade or two of noise floor — even if achievable — simply won't matter.

 

 

Quote:
If you run a program that uses the soundcard it generally takes control of both inputs and outputs

 

That's one of the nice things about RMAA. Both halves of the measurement are in the same program.

 

 

Quote:
Whether I can get this using 2 channels of a soundcard is the question, particularly if the time delay is not an integer multiple of the sample rate.

 

I doubt alias distortion is an issue at reasonable test frequencies with a 192 kHz sound card.

 

Speaking of reasonable test frequencies, why do you believe you need to test at 20 kHz?

 

Not that that's out of reach with a 192 kHz sound card. I just question its ability to tell you useful things about the DUT.

post #6 of 23

I'm with wakibaki, RMAA isn't good SW in my opinion too. If I want "straightforward way of measuring THD" I use any reasonable sound card with SpectraLab SW since the measurements won't tell it all so why put so much importance on them.

post #7 of 23

SpectraLab? If you mean SpectraPLUS, you're comparing Bics to fountain pens, Amarok.

 

RMAA is free, unless you need one of the advanced features or are using it commercially. Even then, it's only about $100 US.

 

SpectraPLUS costs either $695 or $995 for a version suitable for audio DIY. If you throw in all the options, you jack the price up to nearly $1,400.

 

(I think you need options 1, 3 and 6, minimum, and you should consider options 2 and 7.)

post #8 of 23
Thread Starter 
Quote:
Originally Posted by tangent View Post

Really? Why? It's not like what it does is black magic. It's just signal generation and measurement. What is there to argue about?

 

Black magic? It might as well be. The Devil's in the detail. You've got no more idea what's inside it in specific terms than I have.

 

If you're not aware of what there is to argue about, then you're out of touch. See:- he who must not be named.

 

Quote:

Not surprising. Those are truly heroic specs. A $5,000 to $10,000 Audio Precision rig can "only" manage about 0.0001% THD+N on its oscillator output. Granted, that's plenty good for audio, and AP have put the heroics where they matter, achieving far better frequency accuracy than your eBay PCB, for example.

 

The PCB pic doesn't have enough detail to justify the claims, and there is no schematic link. Tantalum caps and chip resistors fail to impress when they're claiming such low distortion figures.

 

I'm also skeptical that they have a basis to claim a distortion measurement that low anyway. 0.00003% for the 1 kHz version means THD+N is collectively -130 dB below the oscillator signal level. That means they need a measurement system with a THD+N floor below that level! Not impossible, but not exactly easy to believe, either.

 

Take a look at this thread:- http://www.diyaudio.com/forums/headphone-systems/211394-marsh-headphone-amp-linear-audio-46.html.

 

Quote:

For about a quarter to half that, you can buy a 96 or 192 kHz 24-bit sound card, achieving a THD+N floor between -105 and -125 dB.

 

I've got one or two. I've even read the specs.

 

Quote:

This is good enough. The extra decade or two of noise floor — even if achievable — simply won't matter.

 

I tend to agree with you there, but this is in the nature of an arms race. Overkill is the watchword.

 

Quote:

That's one of the nice things about RMAA. Both halves of the measurement are in the same program.

 

Yes, but the point is that if you want to employ more than one program, 2 programs can't conveniently share the inputs and outputs of the same soundcard. You're free to use RMAA, I have, but I want another string to my bow. Besides, electronics is fun.

 

If it turns out that I can get very good results, you'll be building one. 

 

Quote:

Speaking of reasonable test frequencies, why do you believe you need to test at 20 kHz?

 

Not that that's out of reach with a 192 kHz sound card. I just question its ability to tell you useful things about the DUT.

 

Take a look at pages 472-474 of Bob Cordell's 'Designing Audio Power Amplifiers', I can't be bothered to repeat it all here.

 

w

post #9 of 23
Quote:
Originally Posted by wakibaki View Post

Black magic? It might as well be. The Devil's in the detail. You've got no more idea what's inside it in specific terms than I have.

 

I have no specific idea what's inside my ceiling fan, either, but based on knowledge of general principles, I feel confident I know how it works anyway.

 

The tests RMAA does are well defined. If it says it does an IMD test at frequencies X and Y, we know what that means. We gain confidence when we see peaks in the result at X-Y and X+Y, because we know, from those general principles, why that happens.

 

Besides, if there were shenanigans going on, it's not like it would to be hard to find that out. It wouldn't be especially difficult to snoop on the signals and check that they are as advertised. They even made it easy 5 years ago when they added a feature to 6.0.4 that let you save the test signals to disk. The intended use for that is so you can play them back without RMAA (burn them to CD, save them as ALAC to your iPod...) and measure them from a separate machine with RMAA. You could analyze those files if you weren't sure what's going on.

 

Unless, that is, you're so paranoid you think they might be writing different data to disk than it sends to the sound card. You could still satisfy yourself in software or in hardware.

 

Quote:

If you're not aware of what there is to argue about, then you're out of touch. See:- he who must not be named.

 

Voldemort?

 

It's not surprising I'm clueless if the only allowed approach to the subject is elliptical.

 

Quote:
this is in the nature of an arms race. Overkill is the watchword.

 

Only among those who believe an 0.01% THD+N amplifier ipso facto sounds worse than a 0.001% THD+N amplifier.

 

For myself, the purpose of running standard audio benchmarks is to prove that there isn't something seriously wrong with a given design. They give you a way to be sure that certain elementary bases are covered. As long as the numbers are below certain reasonable values, I think you can move on to other practical and subjective concerns such as:

 

  • Does it fit where I want it to?
  • Can I afford it?
  • Can it run from the power source I want to use?
  • Does it sound good?
  • If not, can I tweak the base design easily so it does?
  • etc...

 

Every one of those concerns matters to me more than pushing a design from 0.001% to 0.0001%. They even matter more to me than merely measuring such a change. That is, if a given design measures as having 0.001% THD+N but it would measure 0.0001% if you had better measuring instruments, what does it really matter? We've known for half a century that such a change doesn't correlate well with subjective pleasure.

 

Just so it's clear: I'm obviously not one of those who thinks 1% distortion no-feedback tube amps are great, but that's not because I have a strong opinion against them. If that's what you like, I'm happy you've found your bliss. It's just that I've decided that given a choice between a purely subjective outlook and a pursuit of the "straight wire with gain" path, I'd rather go down the latter. But, I'm also not dogmatic. There is no end to that path, and I don't think there is a Nirvana waiting somewhere further down the path than I've gone.

 

Oh, and while I'm disclaiming absolutist positions, I don't believe RMAA is the be-all and end-all of audio analysis. It's just that when I see a proposal to spend 2-4x as much as for a decent RMAA setup, I have to throw the option out there. The only reason I've kept on harping on it is because you all keep attacking the suggestion.

 

Personally, I'd be happier if someone would write an open source clone of it and put a nice Cocoa GUI on it. But, I'm currently doing other things with my time, so I can't really complain when someone else doesn't do that work for me.

 

Quote:

Yes, but the point is that if you want to employ more than one program, 2 programs can't conveniently share the inputs and outputs of the same soundcard. You're free to use RMAA, I have, but I want another string to my bow. Besides, electronics is fun.

 

Again, I have no wish to get in your way as you chase your bliss. If chasing another zero is how you do it, great.

 

I'm just here trying to argue for sticking a sign beside the "straight wire with gain" footpath. I propose it says, "You can turn around now. The scenery really doesn't get any better further down."

 

I don't expect every runner to turn back at that sign. I just think there should be one.

post #10 of 23
Quote:
Originally Posted by tangent View Post

Voldemort?

 

Someone kindly PM'd me with this controversial Voldemort's identity.

 

To help out anyone else feeling clueless without stepping onto sensitive ground, I'll just say that Googling "RMAA blog" will turn up the relevant info in the first page of results.

 

I will also say that while I didn't read everything in that long article, everything I did read, I agreed with. If weaknesses and potential for misapplication were a good reason to stop using a particular bit of test gear, you should throw out every other piece you have, too. Other articles have been written about how to get the wrong answer with DMMs, scopes, etc.

 

This is what I meant above when I referred to operator error. RMAA is not capable of giving trouble-free results without burdening the human with a need to understand what it is he is looking at. That article will give you a lot of help toward using RMAA correctly. Its author should be commended for taking the time to write it, but I don't see that it diminishes RMAA's utility in the least. I suppose it diminishes some people's idea of what RMAA should have been able to do for them, but it's hard to blame RMAA for that. I guess they could have had a "What RMMA cannot do" section on their web site, but how often do you see that sort of thing? This is what critical reviews are for, and I'm glad our Voldemort took the time to do this one.

 

I can see the advantages of a test and measurement lash-up made from individual well-focused pieces. I'm a Unix guy: small pieces, loosely joined. But I'm also a Perl guy: Swiss Army chainsaws are darn useful. One methodology allows you to figure out the problems and limitations of each piece more easily, since you can test them separately. The other puts a lot of useful things in a box for you to use as a whole. Both are useful, and correctly applied, I doubt the two methods will disagree about much.

 

A lot of what that article goes into involves tests that the OP's test scheme won't cover, either. It's one of the reasons I've started supplementing my RMAA tests with square wave tests. RMAA doesn't do everything. It just does a lot, and that's not to be dismissed.

post #11 of 23
Thread Starter 
I see you have beaten me to the draw with a somewhat less objectionable post so I won't bother with the line-by-line refutation of your previous one. 
 
This is an experiment that will cost very little. Let's face it, what really grinds your gears is that you didn't think of it. biggrin.gif
 
w
 
Oh, read the Cordell book, if you really don't know why somebody would want to do THD @ 20kHz.

Edited by wakibaki - 8/12/12 at 7:52pm
post #12 of 23

deleted (misread the OP)


Edited by DingoSmuggler - 8/12/12 at 7:55pm
post #13 of 23
Quote:
what really grinds your gears is that you didn't think of it. 

 

Actually, from looking at my email receipts folder, I see I thought about it in February 2003. (Probably earlier, counting research time.) On the 18th, I ordered parts for a Wein bridge oscillator, which is how I know 0.00003% THD for a cheap oscillator is a heroically impressive spec. That oscillator was going to be part of a similar test setup, but I abandoned the idea once I began to realize what it would take to get to the level I wanted.

post #14 of 23
Thread Starter 

Er, that's not my idea. The whole point is to use a soundcard and software to create a test signal and a nulling signal.

 

If you spent a bit less effort trying to prove your superiority you might learn something.

 

w


Edited by wakibaki - 8/13/12 at 6:19pm
post #15 of 23

That wasn't clear from post #4 above. I got the impression that the hardware oscillator option was still on the table.

 

Anyway, I'm not trying to prove anything. You asked for opinions, I gave you some, you and others attacked them, I defended them.

 

Sorry to have wasted your time.


Edited by tangent - 8/13/12 at 9:24pm
New Posts  All Forums:Forum Nav:
  Return Home
Head-Fi.org › Forums › Misc.-Category Forums › DIY (Do-It-Yourself) Discussions › THD measurement wheeze