Actually I think you'd want something symmetrical, so as not to create a DC bias, which is done perfectly when adding two independent rectangular generators with the same range.As for the number of bits used, a few posts earlier someone said that a range of 1 bit (peak-to-peak?) would be enough for triangular dither, but I have also heard of 2 bits being best (Principles of Digital Audio, Ken C. Pohlmann, and this also seems to be what 2Bdecided is suggesting). Perhaps someone can clear this up.

Just a note on what David said about a triangular generator being a combination of two rectangular generators...

He said that to get 8 bits of triangualr pseudorands, you'd need to combine two rectangular generators with ranges of [0, 255]. This, however, would allow a total range of [0, 510], which is more than 8 bits.

So to get 8 bits of triangular dither, you'd need to combine [0, 127] and [0, 128] rectangular generators to get a [0, 255] triangular generator. At least, I think.

Triangular dither must be two bits peak to peak, so I'm affraid you're not right!

Correct triangular dither removes noise modulation - that means that the resulting noise (after truncation) from adding dither will be independent of the level of the original signal.

Rectangular dither doesn't so this properly. If the original signal lies exactly half way between two steps in the least significant bit of the truncated signal, then it can be bumped up or down by 0.5 bits - therefore the resulting noise (noise=final-original) will always have a magnitude of 0.5 bits. Whereas if the original signal is elsewhere, the magnitude of the noise (i.e. the rounding error) will be different, and signal dependent.

Triangular dither solves this by always giving the rounded signal the chance of being the same number of "bits" (or fractions of one bit) away from its original value. Without scanning a picture in, I can't explain this any better.

If you only have 1 bit peak to peak triangular dither (that's called 0.5 bits in Cool Edit for some reason), then it will cause even worse noise modulation than recntangular dither, and won't even remove harmonic distortion.

So it must always be 2 bits peak to peak.

Cheers,David.(That's "Dr David Robinson" for your credits aristotel! I nearly did an MSc at York, and I've stayed there a time or two (once at the uni) - I won't hold you to that drink though! - I'm a long way away now.)

Hi everybody, I just visited this page and i was wondering if anybody can help me with a question about dithering. I want to reduce the # of bits from 8 to 4 and i want to use rectangular dither . So, i have to add a 4-bit random signal to the original one before quantizing. I just don't know what to do with boundries . For example , if the original value is 255 evey positive dither will make the total value to have 9 bits and i am not sure what to do with it.

To quote shibatch "Dithered 8bit files contains strong supersonic, and listening to these files for long hours may damage your hearing. Dithered 16bit files are noproblem since the power of the supersonic of dither is 1/65536 of those ofdithered 8bit files."

Hi everybody, I just visited this page and i was wondering if anybody can help me with a question about dithering. I want to reduce the # of bits from 8 to 4 and i want to use rectangular dither . So, i have to add a 4-bit random signal to the original one before quantizing. I just don't know what to do with boundries . For example , if the original value is 255 evey positive dither will make the total value to have 9 bits and i am not sure what to do with it.

Clip it - if you already have a full scale sample, then dither can send this 1 bit (or 2 bit, with triangular dither) over full scale. Check for it in the code, and ensure values over 255 are clipped to 255. Also ensure you don't go below 0.

If you're not careful, you'll overflow 255 to 0 or 0 to 255, and that will sound terrible!

4-bit audio will sound terrible anyway - what project are you working on? Is it interesting, or experimental?

Sorry, guys, I've only just seen the thread and haven't read all the way through it. The bit depth of the dither is not "2 bits" but rather "2 quantization steps" (of the remaining quanta). 2 bits implies the options of 00, 01, 10, and 11. 2 quanta implies 00, 01 and 10. The dither must be of triangular probability within this range. The way to generate the dither is to generate one bit's worth of random values twice, so:

Random value between 0000 (bits 13 through 16) and 0100. Do this twice and add them together.

You now have TPDF dither of 2 quanta in amplitude (not 2 bits). The result will be some value between 0000 and 1000 with the greatest likelihood that the number will be 0100.

To the person that asked, this is precisely the amount and type of dither needed in order to completely remove quantization distortion (or rather turn it into noise). This has been mathematically proven and you can find these proofs in the writings of Lipshitz and Vanderkooy.

Hi everybody, I just visited this page and i was wondering if anybody can help me with a question about dithering. I want to reduce the # of bits from 8 to 4 and i want to use rectangular dither . So, i have to add a 4-bit random signal to the original one before quantizing. I just don't know what to do with boundries . For example , if the original value is 255 evey positive dither will make the total value to have 9 bits and i am not sure what to do with it.

Thanks in advance,

First, don't use rectangular dither. Second, dither is a signal added to the original. If you have no headroom you will assuredly clip when adding this signal. Either gain adjust the original ahead of time or acknowledge that you are going to clip. Third, if this is really audio you may want to try noiseshaping instead of dithering if you're going to 4 bits. That's a very low dynamic range and you can steal some additional dynamic range by noiseshaping it appropriately.

Sorry, guys, I've only just seen the thread and haven't read all the way through it. The bit depth of the dither is not "2 bits" but rather "2 quantization steps" (of the remaining quanta). 2 bits implies the options of 00, 01, 10, and 11. 2 quanta implies 00, 01 and 10. The dither must be of triangular probability within this range. The way to generate the dither is to generate one bit's worth of random values twice, so:

Random value between 0000 (bits 13 through 16) and 0100. Do this twice and add them together.

You now have TPDF dither of 2 quanta in amplitude (not 2 bits). The result will be some value between 0000 and 1000 with the greatest likelihood that the number will be 0100.

To the person that asked, this is precisely the amount and type of dither needed in order to completely remove quantization distortion (or rather turn it into noise). This has been mathematically proven and you can find these proofs in the writings of Lipshitz and Vanderkooy.

Sorry for bringing up an old thread. I'm trying to reduce a signed 24bit PCM track to 20bit. As far as I understand this is what I have to do:

(1) Add a random value of the range [-32..+32].(2) Add another random value of the range [-32..+32].(3) Round the resulting PCM sample to 20bit.

The choice is really a trade-off between dither noise power and the degree of noise modulation you are willing to accept. For example I prefer the last variant which is as safe as rectangular dither and usually enough to avoid noise modulation -- especially when coupled with noise shaping filters.

Then you won't get an exact triangular distribution -- only an approximation.

Why is that?

Because you add already discrete quantized values. You end up with a discrete probability distribution = finite amount of possible dither sample values.

QUOTE (madshi @ Aug 28 2007, 10:23)

And shouldn't it be rand(257)?

No, it was supposed to be 256. This'll lead to the best approximation to the TPDF.Sketch of proof:The best approximation of a rectangular PDF for values 0..256 can be done via rand(256)+0.5. This should be obvious. If we substitute the RNG in the formular for a TPDF dither we get:

Because you add already discrete quantized values. You end up with a discrete probability distribution = finite amount of possible dither sample values.

Ok, I think I understand, thank you. One final question: If I use your idea to use "value24 << 4" I've no room left in 32bit processing for detecting overflow, or am I wrong? What do you think about this?

Of course I'm cutting off the bottom 4 bits of the TPF value before adding the three values, while you're doing the cutting off after the addition. But in the end IMO it doesn't matter because two of the three values have zeroed out bottom 4 bits. Only TPF has information in the bottom 4 bits. So those bottom 4 bits can never result in any other bits being impacted by "addition overflow". So basically the bottom 4 bits are useless and are being cut off by the final right shift, anyway. What am I missing?

This is still perfectly valid TPF dither, but has the effect of high pass filtering the dither, which is generally a desirable thing for audio (and many other applications).

Cheers,David.

As I understand it that the random number generated is from a pseudo-random number generator function RAND(). I was wondering if it is necessary that the random source be white? In this case it make perfect sense that you can use the previous random number generated in the subtraction.

It's probably worth mentioning a simple trick that's widely used.(...)Instead, generate one random number per sample, and subtract the previous random number.(...)This is still perfectly valid TPF dither, but has the effect of high pass filtering the dither, which is generally a desirable thing for audio (and many other applications).

Honestly, I still need to wrap my head around this. Do you think that the quantization error's auto-correlation (the noise's colour) will be independent of the input-signal? I have my doubts but I'm not sure. The difference to "real noise shaping" is that this trick you mentioned kind of uses "filtering before quantization" whereas proper noise shaping operates on the quantized unfiltered noise which is guaranteed to be white due to "normal" dithering.