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 9 2004, 13:29
Post
#2


ReplayGain developer Group: Developer Posts: 5614 Joined: 5November 01 From: Yorkshire, UK Member No.: 409 
QUOTE (Ariakis @ Jan 9 2004, 08:04 AM) 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. So, in your case, you'd want 3 bits of noise, which is [0, 7]... so you'd want to combine [0, 3] and [0, 4] rectangular generators, I think. Someone correct me if I'm wrong, please. =) 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=finaloriginal) 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.) 


LoFi Version  Time is now: 2nd June 2015  23:10 