Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Converting Frequency Distributions (Read 3738 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Converting Frequency Distributions

I don't know how to phrase my question properly, so I'll try and explain what my intent is.

In a thread a while back, I mentioned an idea of mine: If you find the distribution of the PCM data in a file, altering that distribution could fix some dynamic compression problems, albeit with an increase in harmonic distortion.

So, what would be a method for converting the known, arbitrary distribution of PCM data to another arbitrary distribution, ie the normal distribution?

Converting Frequency Distributions

Reply #1
Should be easy in matlab for example. Check out the histeq function first.

Converting Frequency Distributions

Reply #2
Quote
Should be easy in matlab for example. Check out the histeq function first.

Hmm... if I were only working in Matlab...

May look into that more, may just hack with the math. I don't know a lot about summation operators though. 

Thanks for the idea at very least.

Converting Frequency Distributions

Reply #3
Ok then. So maybe a short description of what histeq does is in place?

You need a function to map input values between -32k and +32k to the same output range. First you have to find the PDF by counting the occurances of each value, and then dividing by the total number of samples. Then a function to turn this into a uniform distribution use this as your mapping function: T(x) = (sum(pdf(i), i=-32 to x) - 0.5 ) * 64k

Then to turn a uniform pdf into a normal there is a fixed function, lets call it N. Compose these two functions, (N o T) and apply it to your data.

Edit: crappy autoformatting turned my variable into ® ...

Oh, and by the way... why not try your idea in matlab before coding in in C or something? It's much faster way of testing, and if it turns out it doesn't work, much less work down the drain. And if it does work you have a good prototype before you start writing c code.

Edit2: Just found that N is normally called Box-Muller transform. Google it.

Converting Frequency Distributions

Reply #4
If you don't have access to Matlab you can try Octave, which is a very similar language and is free. Last time I used it (it develops quickly though) it didn't have the Histeq function, but certainly supports all the primitives that would make one easy to implement. Googling for "octave histeq" also returns a couple of implementations.
Octave's Sourceforge page is a good place to start.

Quote
Oh, and by the way... why not try your idea in matlab before coding in in C or something

This is a very good idea - it means you can seperate the maths from the practicalities. Once you are sure of the maths you are doing, then implementing in C would be simple (look at the fftw and ATLAS libraries for a start).

 

Converting Frequency Distributions

Reply #5
Yeah, I thought that might have been what you intended with the Matlab comment. I'll look into Octave, but I almost think it'd take longer for me to learn that language than to write the code in Delphi (that's what I'm coding in). I'm pretty solid at converting math stuff into code.

Box-Muller transform, eh? I'll look into that. Thank you all for the insight. Hopefully I can make something out of this.

Edit: Histogram equalization! That's what I needed to search for!
Thanks again, everyone.