THD controlling

SergeG

Member
2020-01-01 3:13 pm
Hi,

Edit: R2R DAC emulation implemented
Sound Distorter R2R 0.2.37.53




Many times while considering to order a new DAC, that should better than a previous, I asked myself how low distortions I do need practically. The question was always important just because any next DAC requires next growing budget. I believe the equation is not surprising for anybody.


So I wrote a tool to simulate controllable distortions from -110db to - 40db and to add the distortion to a software player. Sound Distorter

Also in the background I've been thinking about no-linear distortion in general.
Actually there is a set of audio equipment genres, such as R2R DACs, tube amplifier, with distortions noticeably higher than expected.
However the sound of such devices is often perceived as desired, not just specific. Ordering an R2R DAC (for instance) just to check the sound is not the best idea to me (at least), the experiment doesn't look affordable. So I think about whether it's possible to simulate the same specific distortions programmatically and compare the difference.

I would like some feedback if the subject is curious to somebody else.

Thank you,
Serge
 
Last edited:
1. An R2R-DAC with mismatch has mismatched bit weights. You could simulate that by multiplying each bit with a number that is a bit off (not exactly the power of two that it is supposed to be) and adding the results.

2. Poorly designed sigma-delta DACs can have very complex types of distortion, such as idle tones that are frequency modulated by the signal. You can simulate that by passing the signal through a digital sigma-delta modulator, a model of a non-ideal DAC (just make the weight of a bit slightly dependent on what bit came before it, for example) and a low-pass filter, but then you need a very different program from what you are writing.

3. There is the issue of peak sample normalization and intersample overshoots: most DACs that have a digital interpolation filter inside clip on peak sample normalized music recordings. That is, when the largest samples are put exactly at +/- full scale, the waveform in between the samples may have to exceed full scale. That would not be a problem if either the DAC manufacturers or the mastering engineers or both kept some headroom for this issue, but often they don't. It is also not a problem when you attenuate the signal a bit before putting it through the first digital filter. Analogue filters can have similar problems, but usually have some headroom to cover things like signal level spread.

So all in all, a DAC with -110 dB distortion on 0 dBFS sine waves may well be hard clipping on music.

I never thought about how to simulate this in software. If the software is allowed to increase the sample rate, it would be a matter of interpolating (I mean putting zero samples in between and filtering) and hard clipping. If not, it would probably require interpolating, hard clipping, low-pass filtering and decimating.
 

SergeG

Member
2020-01-01 3:13 pm
>1. An R2R-DAC with mismatch has mismatched bit weights.

It's not enough, I tried. It gave only odd harmonics only, not odd+even as I saw on third party spectra. There should another "defect" to produce even harmonics as well.


>3. There is the issue of peak sample normalization and intersample overshoots:

Thanks for the idea! However I'm trying to cover distortions simulation in general
without an especial focus on levels near the full scale.
Undoubtedly levels near the clipping can add supplementary effects.

>So all in all, a DAC with -110 dB distortion on 0 dBFS sine waves may well be hard clipping on music.

This tool keeps nearly the same THD in a wide level range, not just at 0db.
Honestly I saw the similar behavior on digital (software) loopbacks natively, even without the tool
 
You are right, mismatched bit weights always result in an input-to-output relation that is point symmetrical in the centre, which can only give odd-order distortion. I didn't know that, but it became clear when I wrote out the equations.

Do you know whether those even harmonics are dependent on the signal frequency when you include an op-amp current-to-voltage converter?
 
The upper bits are usually thermometer-coded, because a completely binary-scaled DAC is too sensitive to mismatch. With thermometer coding, mismatch can cause even-order distortion. So then you have to convert the upper few bits into offset binary. When the number is n, add n steps, where those steps are mismatched. For example, with three thermometer-coded bits:

0 -> 0
1 -> step[1]
2 -> step[1] + step[2]
3 -> step[1] + step[2] + step[3]
4 -> step[1] + step[2] + step[3] + step[4]
5 -> step[1] + step[2] + step[3] + step[4] + step[5]
6 -> step[1] + step[2] + step[3] + step[4] + step[5] + step[6]
7 -> step[1] + step[2] + step[3] + step[4] + step[5] + step[6] + step[7]

where the step[n]'s are all close to each other, but not quite equal.

On top of that, you could have even-order distortion due to imperfect current-to-voltage conversion.
 
If the application of the DAC is audio then I'd suggest not neglecting dynamic errors in an over-focus on static ones. Imperfect I/V conversion (as already mentioned by Marcel) is worthy of consideration - as far as I recall from one of Malcolm Hawksford's papers on the subject, non-purely-exponential settling behaviour is a cause of distortion.
 

SergeG

Member
2020-01-01 3:13 pm
>Do you know whether those even harmonics are dependent on the signal frequency when you include an op-amp current-to-voltage converter?


I have no practical spectra, no R2R DACs are available to me so far.
However theoretically the harmonics level should not be frequency dependent at all.
My internal R2R model confirms that.
The harmonics level depends on reference voltage asymmetry if R2R reference is bipolar. But again it surprisingly (but explainably though) adds only odd harmonics.


Also please realize SoundDistorter is a program and works in digital “space” only.
Obviously I could anyhow model op-apms/etc programmatically, but actually
DACs themselves (as more complex entities) produce much more specific non-linearity than op-amps/etc (or other pure analog devices). Op-amp is an AB class amplifier with strong negative feedback, so its harmonics are very predictable, much lower than DACs ones and (again) nearly always
odd, AB is a symmetrical nature.


>completely binary-scaled DAC is too sensitive to mismatch


Exactly, very sensitive, but modeling revealed only odd harmonics.
My intuitive explanation is simple. A middle bit (say 10-th from 16) triggers on and off equally on positive and negative half-waves equally producing only odd harmonics.


>I'd suggest not neglecting dynamic errors in an over-focus on static ones.


Thank you! Honestly I thought about that, not sure how to include it into my model however.
It's a software program finally without any analog elements at all.
Probably there should be bit dithering somewhere.
At the moment my the related experiments didn't lead to even harmonics appearance.


However my main focus is not on R2R emulation, R2R emulation is the second stage.
First of all I would like to realize whether the original idea of harmonics simulation is worthy of checking personal audio listening preferences/abilities/etc


Following my experiments I'm starting to realize that popular tendency to have minimal possible distortions is rather impractical and similar to the trend of blindly having more “pixels” in monitors/TVs/ cameras/etc. The latter is not bad, but just quality (good impression) irrelevant.