Sign in

username:

password:



Not a member?

Search compdsp



Search tips

comp.dsp by Keywords

Adaptive Filter | ADPCM | ADSP | ADSP-2181 | Aliasing | AMR | Anti-Aliasing | ARMA | Autocorrelation | AutoCovariance | Beamforming | Bessel | Blackfin | Butterworth | C6713 | CCS | Chebyshev | CIC Filter | Circular Convolution | Code Composer Studio | Comb Filter | Compression | Convolution | Cross Correlation | DCT | Decimation | Deconvolution | Demodulation | DM642 | DSP Boards | DSP/BIOS | DTMF | Echo Cancellation | Equalization | Equalizer | ETSI | EZLITE (Ez-kit Lite) | FFT | FFTW | FIR Filter | Fixed Point | FSK | G.711 | G.723 | G.729 | Gaussian Noise | Goertzel | GPIO | Hilbert Transform | IFFT | IIR Filter | Interpolation | Invariance | JTAG | Kalman | Laplace Transform | Levinson | LPC | McBSP | MIPS | Modulation | MPEG | Multirate | Notch Filter | Nyquist | OFDM | Oversampling | Pink Noise | Pitch | PLL | Polyphase | QAM | QDMA | Quantization | Quantizer | Radar | Random Noise | Reed Solomon | Remez | Resampling | RTDX | Sampling | Sharc | TI C6711 | Undersampling | Viterbi | Wavelets | White Noise | Wiener Filter | Windowing | XDS510PP | Z Transform

Ads

Discussion Groups

Free Online Books

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | Comp.DSP | Cross correlation

There are 3 messages in this thread.

You are currently looking at messages 0 to 3.


Cross correlation - vakilp - 2006-05-31 17:22:00

Hello,

I have a problem with my C code. My algorithm might be wrong but when I
work with fewer samples, I get convinced that I am right.

In C I have two arrays: Data and Code. They are both array of structs
(both are array of imaginary numbers).
Now, according to my shorter calculations, if I keep Data constant and
shift only Code array or vice versa, I ought to end up with the cross
correlation values that I would by putting these two arrays of numbers in
MATLAB albeit that the highest value of the cross correlation will not be
in the same spot as MATLAB's.

However, when I plot cross correlation from my code and that from MATLAB's
xcorr function, mine is wrong. Clearly I am doing something wrong.

Let me give you some code here:

% Code is a circular array and hence we have the begin and end indecies.
Each Data and Code are 15999 elements long. Each element of array holds
two doubles. One is real and one is imaginary %

%Currently begin = 0 and end = 15998%
void Cross_Correlate(being, end, index){ 
j = 0;
while (begin != end){
  cross[index].real = Code[begin].real*Data[j].real -
Code[being].imag*Data[j].imag;

  cross[index].imag = Code[being].imag*Data[j].real +  
Code[being].real*Data[j].imag;

  begin = (begin+1) % 15999;
  }
}

The Cross_Correlate function is called from main and I increment end as:

end = (end+1) % 15999

Basically, in iteration 2, end = 0 and begin = 1. So I will be multiplying
Code[1] to Data[0], Code[2] to Data[1] and so on. Keep iterating end until
end = 15997. So in this last case we have Code[15998]*Data[0],
Code[0]*Data[1] and so on. I am doing something wrong here. Help please?

Thanks.


______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Cross correlation - Paul Russell - 2006-06-01 03:12:00



vakilp wrote:

> 
> Let me give you some code here:
> 
> % Code is a circular array and hence we have the begin and end indecies.
> Each Data and Code are 15999 elements long. Each element of array holds
> two doubles. One is real and one is imaginary %
> 
> %Currently begin = 0 and end = 15998%
> void Cross_Correlate(being, end, index){ 
> j = 0;
> while (begin != end){
>   cross[index].real = Code[begin].real*Data[j].real -
> Code[being].imag*Data[j].imag;
> 
>   cross[index].imag = Code[being].imag*Data[j].real +  
> Code[being].real*Data[j].imag;
> 
>   begin = (begin+1) % 15999;
>   }
> }
> 

Did you copy and paste this code ? Only there are a couple of typos in 
it, where you have "being" instead of "begin", which might lead to some 
unexpected behaviour.

Paul
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Cross correlation - vakilp - 2006-06-01 10:23:00

>vakilp wrote:
>
>> 
>> Let me give you some code here:
>> 
>> % Code is a circular array and hence we have the begin and end
indecies.
>> Each Data and Code are 15999 elements long. Each element of array
holds
>> two doubles. One is real and one is imaginary %
>> 
>> %Currently begin = 0 and end = 15998%
>> void Cross_Correlate(being, end, index){ 
>> j = 0;
>> while (begin != end){
>>   cross[index].real = Code[begin].real*Data[j].real -
>> Code[being].imag*Data[j].imag;
>> 
>>   cross[index].imag = Code[being].imag*Data[j].real +  
>> Code[being].real*Data[j].imag;
>> 
>>   begin = (begin+1) % 15999;
>>   }
>> }
>> 
>
>Did you copy and paste this code ? Only there are a couple of typos in 
>it, where you have "being" instead of "begin", which might lead to some 
>unexpected behaviour.
>
>Paul
>


Hey Paul,

I was infact typing up the code so that infact is a typo. My code compiles
and runs fine. I guess my question is more algorithmic than code related. I
am shifting only one of the arrays and not both. My thought is that it
should work. But it doesnt!

Thanks.
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.