Hi,
I wrote a cross- correlation function in MSP430f2274. But it is really slow if I increases the number of samples (to 500).
I am wondering if there is a faster way to do accurate cross correlation in MSP430 ? I checked cross-correlation using fft and inverse fft. I am not sure if it is implementable with number of samples over 500.
Here is the code.
int xcorr ( int Array1[175], int Array2[175], const int size)
{
int i,lag=-size + 1;
int index =0;
int16_t temp = 0;
int16_t peak=0;
int16_t xcorr_result[350];
for (lag=-size+1; lag<size;lag++) //loop of calculation
{
temp=0;
for (i=0; i < size ; i++)
{
{
temp = temp+Array1[i]*Array2[lag+i];
}
}
xcorr_result[lag+size-1]=temp;
}
for (i=0; i < 2 * size-1;i++) //finding the peak index
{
if (xcorr_result[i] >= peak)
{
peak = xcorr_result[i];
index = i-size + 1;
}
}
return index;
}
The first part of doing all the calculations is using the majority of time.
For two arrays of 175 length, using a 8Mhz clock, it takes about 0.6s to complete such a calculation.
Anyone can help ?
Thanks!