This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to do cross correlation in MSP430

Other Parts Discussed in Thread: MSP430F2274

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!

  • The first part of your code is performing 3 * size MAC operations. This device doesn't have a hardware MPY32 block in it. So, unless you can optimize your algorithm you aren't going to gain any noticeable improvement.

  • Brian is right: this MSP doesn't have a hardware multiplier. But even if it had, there is soem room for improvements.

    xianzhen zhu said:
     for (i=0; i < 2 * size-1;i++)              //finding the peak index

    turn this into
    for (i=0; i < ((size-1)<<1); i++)

    and you eliminated a multiplication by a simple shift operation. Even with hardware multiplier, this is still significantly faster (200-300%) but without a multiplier I guess it is ten times faster or even more.

**Attention** This is a public forum