Motorola DSP Developer's Kit | ![]() ![]() |
[C ]=mot###_xcorr( A, B, MAXLAG, 'flag')
Description
This function returns the length 2*M-1 cross-correlation sequence in a column vector where A and B are length N vectors.
Input/Output
Input: Vector A (includes the real part Ar
, and the imaginary part Ai
), vector B (includes the real part Br
, and the imaginary part Bi
), int MAXLAG
, and int 'flag'
Output: Vector C (includes the real part Cr
, and the imaginary part Ci
)
Algorithm
N = LengthA; for (i = Max(1, (N - MAXLAG)); i <= N - 1; i ++) { for (j = 0; j < = i - 1; j ++) { C[i]+= B[j+1] * A[j+ N - i + 1]+ BI[j+1] * AI[j+ N - i +1]; CI[i]+= BI[j+1] * A[j+ N -i +1]-B[j+1] * AI[j + N -i +1]; } CI[i] = -CI[i];// complex conjugate if (flag == "biased") C[i] /= N; else if (flag == "unbiased") C[i] /= i ; } for (i = N; i <= Min((2 * N - 1), (N + MAXLAG)); i ++) { for (j = 0; j <= 2 * N - i - 1; j ++) { C[i] += A[j+1] * B[j+i- N+1]+ AI[j+1]* BI[j+i-N+1]; CI[i]+= AI[j+1] * B[j+i- N+1]-A[j+1] * BI[j+i-N+1]; } if (flag == "biased") C[i] /= N; else if (flag == "unbiased") C[i] /= (2 * N - i); } if (flag == "coeff") { for(i=Max(1,(N-MAXLAG));i<= Min((2*N-1),(N+MAXLAG));i++){ C[i]=C[i]*C[N]+CI[i]*CI[N])/C[N]*C[N]+CI[N]*CI[N]; C[i] = (CI[i]*C[N] - C[i]*CI[N]) / (C[N]* C[N] + CI[N] *CI[N]; } } // Format vector C if (MAXLAG >= N) { LengthC = 2 * MAXLAG + 1; df = MAXLAG - N + 1; for (i = LengthC; i >= 1 ; i --) { if ( i > df && i <= LengthC - df ) { C[i] = C[i - df]; CI[i] = CI[i - df]; } else { C[i] = 0; CI[i] = 0; } } } else { C = C(N - MAXLAG : LengthC); CI = CI(N - MAXLAG : LengthC); }
Memory & Register
MAXLAG
'flag'
'none'
'biased'
'unbiased'
'coeff'
Status Register
The assembly function xcorr-c.asm
does not explicitly set any status registers/bits during the function execution.
Data Size Limit
The total size of all vectors can't be larger than the continuous available data memory size.
Data Range Limit
The value of input vectors must be between -1.0 and +1.0.
Precision
In the case of DSP563, precision is 18 bits.
In the case of DSP566, precision is 10 bits.
Performance Limit
![]() | xcorr-r.asm | Motorola Toolbox Function Reference | ![]() |