I'm trying to write a correlation function on an embedded device. Because its embedded, I need to make sure that the memory/CPU usage is minimum.
Here's the deal: - I have a saved waveform sampled at 1 MHz - I have timing info for the waveform - I am going to be taking a new waveform at 200 kHz with new timing info - The timing info for both waveforms is comparable, neither of them start at zero - I want to determine the delay between one waveform and the next precise to 1 us.
The method I was going to use to do this was: - Find the maximum of each waveform (there should only be 1 peak in each, and they should match up) - Set the indexes of each array so that the maximums of the waveforms match up. I'll save the amount of clock cycles that I am shifting in order to do this. - Then I will correlate this and shift a few samples in each direction and correlate as well. The highest correlation value corresponds to the correct amount of delay, and I will keep this value.
The problem is that my array manipulation skills are limited. I'm struggling when trying to implement this algorithm, especially because one of the waveforms is sampled at 5X the other. Does anybody have any references for this or knows how I can achieve this easily?
The specific problems I'm running into are: - How do I set the indexes differently so that the maximums match up? I don't want to write a new register because this takes up memory and takes a long time in terms of read/write cycles. - How do I compensate for the different sampling frequencies? I could fill the 200 kHz waveform with zeros (which won't affect the correlation) but this will take up more memory with no real purpose. - The timing info isn't precise, in that they don't necessarily line up perfectly. For example, the timing numbers "10000, 10020, 10040, 10060, 10080, and 10100" for the 1MHz signal doesn't necessarily match up with "10000, 10100" for the 200 kHz signal. So I can't rely on using the timing numbers as an index very easily.
If what I am asking isn't very clear, I can try to embellish a little on requests, but I don't want this to be too long.