[Math] How would you compute that “average”

signal analysisst.statistics

I created a DJ-ing application that allows you to mix your MP3s with a real turntable.
So I generated an audio timecode to burn on a CD, left channel is the absolute position, right channel is a synchronization sine which frequency is 2205 Hz. Left channel is same frequency except that it represents binary sequences.

Precision is an absolute pre-requisite, the pitch on my Pioneer CDJ-1000 has a precision of 0.02% which is good enough to properly beatmatch songs. I have no problem on getting the absolute position but with the right channel.
After some searching, I found the Zero Crossing Rate algorithm to try detect the pitch. When I process data in real-time however, the pitch moves constantly.

After some searching I found out that as samples are discrete values, so not continuous if I'm right, there's not enough precision with a sample rate of 44100 Hz. Period of 20 samples is 2205 Hz, period of 21 samples is 2100 Hz; so the problem needs something more high-level.

I found then harmonic average, and moving average, results are somewhat more stable. FFT is the best but costs a lot of CPU, using a size of 65536 and time to compute it, whereas with the zero-crossing rate, I can update the value very frequently. The latest candidate, I still need to test is the Standard Deviation.

There must be some math formula that helps for that particular problem, but as I know not much about maths, I am somewhat lost.

Do you have any ideas ?

Thanks a lot :-)))

Best Answer

It sounds to me that you need to detect the tempo of the music, and not the pitch. If you are trying to use a pitch-detection algorithms, then these are going to fluctuate rapidly, as they will lock onto the high frequences in your music. It sounds like you need something that filters out all but the lowest frequencies and allows you to determine how many BPM (beat per minute) the music is, as well as the phase of the beat also, so that you can do beatmatching as you originally mention.

However, I don't think that anyone here is going to be able to give you a simple formula for doing this directly from the samples. Digital signal processing is, by its very nature, a fairly mathematical subject. I do think that if you try Googling for "beat-matching signal-processing", or "beat-matching matlab", you will be pointed in the right direction, as you might find a published algorithm for doing exactly what you need. For instance, I found the following paper by searching: Design of an Automatic Beat-Matching Algorithm for Portable Media Devices. It might be worth looking at if you can get it without paying, say through a university with a subscription. Otherwise, I'm sure there are 100's of similar papers you can find on this subject. Also, many universities teach an audio signal processing class, and often the notes from these classes are online. Beat-matching is a common project for students to try in such classes and I'm sure you will be able to find some examples where people have done it.

Sorry I couldn't give you more explicit advice, but I hope I understood your question correctly and have pointed you in the right direction. Good luck.

Related Question