Triangular Probability Density Function Dither, How does this random number exaclty work 
Triangular Probability Density Function Dither, How does this random number exaclty work 
Dec 31 2003, 04:52
Post
#1


Group: Members Posts: 22 Joined: 31December 03 From: Warwick, UK Member No.: 10830 
Hello everybody,
THis is my first post on this site. NIce to find a forum for this field which I am interested in and studying. So here is the problem... I need to write in C, a program that will dither and truncate a 16 bit stereo file to a 14 bit stereo file. It is for an assignment for university basically. I more or less have the idea of how it works after having read several books and websites. However here is the problem/question. To go from 16 bit to 14 bit and add dither before truncating it is necessary to add 3 bits of noise to the 16 bit original signal. 3 bits can have the maximum value of 8. In audio Terms 4 to +4. Correct so far? Now if i generate a random number between 0 and 8, I can't just add that number to the 16 bit stream right? Becuase I need to add a +4 to 4 range number. It that correct? and if it is, how can I generate a random number between +4 and 4 in C? int a = rand() % 8; this would give a random value between 0 and 8. BUt how do i set a lower and upper limit for the random number to be generated? Well, at this point this is all i will ask. I have a feeling this is somehting really simple and for some reason I have been stuck on it for some time now. Thank you in advance for reading it and hopefully replying. In the meantime, Happy New Year everybody! PS: Oops..i just realised it was moved from general audio to Scientific..Sorry..i am new ..i thought this was a simple question and thats why i put it in General audio. This post has been edited by aristotel: Dec 31 2003, 05:02 


Jun 16 2005, 14:50
Post
#2


Group: Members Posts: 24 Joined: 14April 05 Member No.: 21432 
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. I hope this helps? Nika 


Aug 27 2007, 15:47
Post
#3


Group: Members Posts: 16 Joined: 27August 07 Member No.: 46548 
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. Is that correct? Thanks much!! 


Aug 27 2007, 17:53
Post
#4


Group: Developer Posts: 1318 Joined: 20March 04 From: Göttingen (DE) Member No.: 12875 
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. Is that correct? Thanks much!! That's too much dither (12 dB more than necessary). It's as simple as Nick.C pointed out: new_int20 = round( old_int24 / 16.0 + rnd()  rnd() ); where rnd() returns independently and idendicallydistributed values between 0.0 and 1.0 A full TPF dither signal only carries samples values between d...d where d is the quantizer step size. A full rectangular dither would be: new_int20 = round( old_int24 / 16.0 + rnd()  0.5 ); You can even morph between both distributions: new_int20 = round( old_int24 / 16.0 + rnd()  0.5*rnd()  0.25 ); The choice is really a tradeoff 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. Cheers! SG This post has been edited by SebastianG: Aug 27 2007, 18:02 


LoFi Version  Time is now: 24th May 2015  05:14 