IPB

Welcome Guest ( Log In | Register )

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





Group: Members
Posts: 22
Joined: 31-December 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. huh.gif

Thank you in advance for reading it and hopefully replying.

In the meantime, Happy New Year everybody! cool.gif


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
Go to the top of the page
+Quote Post
 
Start new topic
Replies
2Bdecided
post Jan 7 2004, 13:46
Post #2


ReplayGain developer


Group: Developer
Posts: 5059
Joined: 5-November 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 16-bit) 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.
Go to the top of the page
+Quote Post
goli
post May 29 2005, 19:02
Post #3





Group: Members
Posts: 1
Joined: 29-May 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 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,
Go to the top of the page
+Quote Post
Nika
post Jun 16 2005, 14:55
Post #4





Group: Members
Posts: 24
Joined: 14-April 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 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.

Nika
Go to the top of the page
+Quote Post

Posts in this topic
- aristotel   Triangular Probability Density Function Dither   Dec 31 2003, 04:52
- - kjoonlee   Hi, I'm quite a newbie, so I can't offer ...   Dec 31 2003, 05:16
- - tigre   AFAIK rectangular dither is equal to random noise ...   Dec 31 2003, 11:23
- - aristotel   Hey..thanks for your replies. I have come up with...   Dec 31 2003, 16:49
- - Jasper   It seems correct, but wouldn't you just need t...   Jan 1 2004, 11:49
- - aristotel   Hey Jasper..thanks for your post. The decision to...   Jan 1 2004, 16:57
- - cabbagerat   You might want to consider the fact that with most...   Jan 2 2004, 06:57
- - Jasper   If you are looking for good random number generato...   Jan 2 2004, 12:02
- - aristotel   Hello, Jasper..the way I understood it was that if...   Jan 3 2004, 20:15
- - Jasper   Actually the information from those two bits of no...   Jan 4 2004, 11:28
- - tigre   There must be a mathematical way to determine how ...   Jan 4 2004, 12:20
- - Ariakis   http://www.hydrogenaudio.org/forums/index....indpo...   Jan 4 2004, 12:33
- - Diocletian   QUOTE (tigre @ Jan 4 2004, 12:20 PM)There mus...   Jan 4 2004, 12:56
- - tigre   totally = not mesurable. e.g. distortion: If you ...   Jan 4 2004, 13:06
- - aristotel   Hello everybody...lots of replies i see...lots of ...   Jan 4 2004, 19:16
- - tigre   QUOTE (aristotel @ Jan 4 2004, 08:16 PM)It ta...   Jan 4 2004, 19:58
- - 2Bdecided   I've only just seen this thread. At the risk ...   Jan 5 2004, 16:07
- - KikeG   QUOTE (tigre @ Jan 4 2004, 12:20 PM)There mus...   Jan 6 2004, 16:49
- - aristotel   QUOTE (tigre @ Jan 4 2004, 10:58 AM)Do proces...   Jan 6 2004, 18:21
- - aristotel   Hello 2bDecided..your post is helpful and thank yo...   Jan 6 2004, 19:04
- - aristotel   QUOTE (KikeG @ Jan 6 2004, 07:49 AM)if I...   Jan 6 2004, 19:16
- - aristotel   QUOTE (aristotel @ Jan 4 2004, 10:16 AM)Howev...   Jan 6 2004, 19:20
- - 2Bdecided   QUOTE (aristotel @ Jan 6 2004, 06:04 PM)Hello...   Jan 7 2004, 13:46
|- - goli   Hi everybody, I just visited this page and i was ...   May 29 2005, 19:02
|- - 2Bdecided   QUOTE (goli @ May 29 2005, 06:02 PM)Hi everyb...   Jun 16 2005, 11:37
|- - Nika   QUOTE (goli @ May 29 2005, 12:02 PM)Hi everyb...   Jun 16 2005, 14:55
- - aristotel   QUOTE (2Bdecided @ Jan 7 2004, 04:46 AM)Hope ...   Jan 9 2004, 03:22
- - Ariakis   Just a note on what David said about a triangular ...   Jan 9 2004, 09:04
- - Jasper   Actually I think you'd want something symmetri...   Jan 9 2004, 13:06
- - 2Bdecided   QUOTE (Ariakis @ Jan 9 2004, 08:04 AM)Just a ...   Jan 9 2004, 13:29
- - spoon   To quote shibatch "Dithered 8bit files contai...   Jun 15 2005, 10:11
- - KikeG   That depends largely on the sample rate.   Jun 15 2005, 13:13
- - Nika   Sorry, guys, I've only just seen the thread an...   Jun 16 2005, 14:50
|- - madshi   QUOTE (Nika @ Jun 16 2005, 14:50) Sorry, ...   Aug 27 2007, 15:47
|- - SebastianG   QUOTE (madshi @ Aug 27 2007, 16:47) Sorry...   Aug 27 2007, 17:53
|- - madshi   QUOTE (SebastianG @ Aug 27 2007, 17:53) T...   Aug 28 2007, 08:23
|- - SebastianG   QUOTE (madshi @ Aug 28 2007, 09:23) (1) a...   Aug 28 2007, 09:13
|- - madshi   QUOTE (SebastianG @ Aug 28 2007, 09:13) T...   Aug 28 2007, 09:23
|- - SebastianG   QUOTE (madshi @ Aug 28 2007, 10:23) QUOTE...   Aug 28 2007, 14:10
|- - madshi   QUOTE (SebastianG @ Aug 28 2007, 14:10) B...   Aug 28 2007, 14:50
|- - SebastianG   QUOTE (madshi @ Aug 28 2007, 15:50) P.S: ...   Aug 28 2007, 14:59
|- - madshi   QUOTE (SebastianG @ Aug 28 2007, 14:59) E...   Aug 28 2007, 16:23
|- - SebastianG   QUOTE (madshi @ Aug 28 2007, 17:23) QUOTE...   Sep 28 2007, 10:51
|- - madshi   QUOTE (SebastianG @ Sep 28 2007, 10:51) Y...   Sep 28 2007, 21:58
- - Nick.C   Is it not simply: new_value = round(old_value/(2^...   Aug 27 2007, 17:01
- - Nick.C   Surely, to round you will have to use FP maths? .....   Aug 28 2007, 08:31
|- - madshi   QUOTE (Nick.C @ Aug 28 2007, 08:31) Surel...   Aug 28 2007, 09:02
- - 2Bdecided   It's probably worth mentioning a simple trick ...   Aug 28 2007, 14:18
|- - Nick.C   QUOTE (2Bdecided @ Aug 28 2007, 14:18) Do...   Aug 28 2007, 14:33
|- - kwwong   QUOTE (2Bdecided @ Aug 28 2007, 08:18) It...   Sep 4 2007, 02:59
|- - SebastianG   QUOTE (2Bdecided @ Aug 28 2007, 15:18) It...   Sep 5 2007, 10:27
- - jlohl   QUOTE What is the effect of a non-white random sou...   Sep 6 2007, 11:02
- - ilo   TPDF dither should have a peak amplitude twice tha...   Sep 27 2007, 22:57
|- - madshi   @ilo, that sounds quite interesting, but honestly...   Sep 28 2007, 09:12
|- - ilo   @ madshi: I think the stuff already posted will d...   Sep 28 2007, 14:16
- - Nick.C   It should be 0..16 as that is (0.0 .. 1.0) x 2^4. ...   Sep 28 2007, 22:11
|- - madshi   QUOTE (Nick.C @ Sep 28 2007, 22:11) Sorry...   Sep 28 2007, 22:18
- - Nick.C   If you're really wanting to use integers, why ...   Sep 28 2007, 22:21
- - madshi   QUOTE (Nick.C @ Sep 28 2007, 22:21) If yo...   Sep 28 2007, 22:29


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 24th July 2014 - 13:21