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 


Jan 7 2004, 13:46
Post
#2


ReplayGain developer Group: Developer Posts: 5134 Joined: 5November 01 From: Yorkshire, UK Member No.: 409 
QUOTE (aristotel @ Jan 6 2004, 06:04 PM) Hello 2bDecided..your post is helpful and thank you lots for your it. I have the following questions so i can finnaly get my head around this. For two bits of triangular probability noise i could use: (rand() % 3) + (rand() % 3)  2; This will give me a range of 2 to 2. The possible values are 2,1,0,1,2. THat is five of them with 0 being the absolute centre. Does this not result in a dither without DC bias? On your example, you generate a true 2 bit noise range of 4 values. There is no clear MIDDLE value. It this the case where the use of +0.5 or 0.5 is necessary? Also, I assume that in order to add or subtract the 0.5, i need to be processing the samples in 32 bit float precision, so hopefully i can find some information on how to do that if my earlier guess in this post is wrong. You're getting confused between the value before and after truncation. It's helpful if you think in binary about what you're doing before truncation. It's also convention to quote values in decimal relative to the last remaining bit being 1 after truncation. So, thinking in binary, (rand() %3) apparently gives you 0, 1, or 2 i.e. 00, 01, or 10. What happened to 11?! So that's the wrong amplitude to start with. If the last remaining bit after truncation has a value of 1, then the bit that was to its right before truncation has a relative value of 0.5. So, just like you, I was simply subtracting 2 before truncation  no floating point necessary. QUOTE U mentioned the addition of 2 bits worth of noise in the example of going from 16 to 14 bit. Does this mean you believe that the amount of bit of noise to add is equal to the amount of bits you are about to loose by truncating? An easy rule is that the rectangular dither should exactly fill the bits you remove (no more, no less), and that triangular dither can be created by adding two independent rectangular dither sources. This makes things very easy. so 16 to 8 bits conversion is xxxxxxxxyyyyyyyy > xxxxxxxx you need two rectangular dither generators (i.e. two pseudo random number generators) ranging from 00000000 to 11111111 i.e. 0 to 255. You don't want 256 (100000000) because that gives you an amplitude of 1 too many. (Think about it with a decimal example: it's just like 0,1,2,3,4,5,6,7,8,9 gives you ten possible values, but 0,1,2,3,4,5,6,7,8,9,10 gives you eleven. So unless you want a range of eleven, then if you include the number 0, you don't include the number 10. It's the same here, but in binary) Finally, digital audio isn't DC biased one way or the other  it's just that it can go one more value negative than positive. When CDs were introduced, "good" converters had DC offsets of, say, 40 or 50 (measured in units of 1 LSB at 16bit) so it was probably never even considered. Hope this helps. I think the contributors to this thread deserve a credit and/or reference in your project, and a drink! Cheers, David. 


May 29 2005, 19:02
Post
#3


Group: Members Posts: 1 Joined: 29May 05 Member No.: 22382 
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 4bit 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, 


Jun 16 2005, 14:55
Post
#4


Group: Members Posts: 24 Joined: 14April 05 Member No.: 21432 
QUOTE (goli @ May 29 2005, 12:02 PM) 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 4bit 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. Nika 


LoFi Version  Time is now: 15th September 2014  03:35 