Forum Discussion
Problem in Implementing Autocorrelation on Stratix II EP2S60 DSP Development Board
Hi there,
I am trying to synchronize the transmitted signal with the receiver by energy detection. The transmitted signal is a sine wave and I plan to autocorrelate it to obtain the peak and then transmitting the data. Could you please help me in implementing the autocorrelation using Stratix II. Thanks a lot.... -S23 Replies
- Altera_Forum
Honored Contributor
A practical approach is to measure mean power of your input in time domain. square up the input (I^2 + Q^2) and add up in accumulator 2^n samples then truncate n LSB bits from result.
I am assuming your input is not a mixture of sinusoids and other signals. - Altera_Forum
Honored Contributor
--- Quote Start --- Could you please suggest how to estimate the energy of a sinusoid? I need an algorithm to differentiate between the sinusoids from different channels. I am thinking of using fft megacore , do you Gurus think thats a good idea? :) --- Quote End --- Do you know the frequency of the sinusoids, or do you have to determine that too? If so, how closely spaced will the sinusoids be? This is required to determine the number of points needed in your transform. How accurate do you need to estimate the power and frequency of the sinusoid? If you do not have a window function prior to the FFT, then you will experience 'scalloping loss', i.e., if the sinusoid frequency is such that it lies between spectral channels (FFT output channels), its amplitude will be down by -3.92dB, relative to what would be detected if it was on a spectral channel. What dynamic range do you need, i.e., what is the largest and smallest sinusoid you need to measure? What is the noise level expected in the signal? Before thinking about the hardware design, you should first model the signals. Go and download the sine_plus_noise.m MATLAB script I posted here and start changing parameters in the file http://www.alteraforum.com/forum/showthread.php?t=30284&page=3 Cheers, Dave - Altera_Forum
Honored Contributor
thanks Dave and Kaz for the guidance.
Could you please suggest how to estimate the energy of a sinusoid? I need an algorithm to differentiate between the sinusoids from different channels. I am thinking of using fft megacore , do you Gurus think thats a good idea? :) thanks, - Altera_Forum
Honored Contributor
--- Quote Start --- I want cross-correlation. --- Quote End --- Ok. --- Quote Start --- So I need help in parameterizing the FIR Megacore. --- Quote End --- When you 'correlate' your input signal with a sinusoid, you're performing an operation that is very similar to what you do when you perform a discrete Fourier transform (DFT). The following may give you a better understanding of what you are doing ... The Forward DFT equation is X[k] = sum_{n=0}^{n=N-1} x[n] * exp(-2*pi*k*n/N) Where the exponential can be split into cos and sine, or real and imaginary components, i.e., assuming x[n] are real-valued samples, then X_real[k] = sum_{n=0}^{n=N-1} x[n] * cos(2*pi*k*n/N) X_imag[k] = -sum_{n=0}^{n=N-1} x[n] * sin(2*pi*k*n/N) These equations implement the sum of N input samples x[n] multiplied by N weights; now what does that sound like? A FIR filter perhaps? There are two sets of FIR filter coefficients; one filter is a cosine filter, the other is a sine filter. The output of the filter is related to the magnitude and phase of the Fourier response at channel k. Where, in your case, k is the frequency of your sinusoid normalized by the sampling rate, i.e., k = f0/fs. Note that the above equation is the calculation at a single output sample time instant, so there is a parameter missing (your output sample time index), which is why the above equation doesn't look exactly like a FIR filter equation (the parameter k is fixed, since you're only measuring at one frequency). Cheers, Dave - Altera_Forum
Honored Contributor
I want cross-correlation. I was trying to understand the process through FIR Megacore in Altera DSP, thats why I said to auto-correlate as once if I am able to auto-correlate through FIR megacore, them I am sure that I will be able to perform cross-correlation too. So I need help in parameterizing the FIR Megacore.
thanks a lot - Altera_Forum
Honored Contributor
Hi Saket,
The title of your post indicates that you want an autocorrelation. However, the FIR filtering option Kaz suggested (nice suggestion!) is effectively a cross-correlation; the filter coefficients are a sinusoid with the same frequency as the transmitted signal. If you 'filter' an incoming signal with this filter, then you will get peaks where the two signals are in phase, and zeroes where they are out of phase (if the filter length is only one period, then you only get one peak). Basically, you get the autocorrelation you are looking for with a different scaling, and a shift of the zeroth lag. You need to figure out what it is you really want first; auto- or cross-correlation. What parameter are you trying to determine? If you are simply looking for a power detection or system gain response, then an autocorrelation is sufficient. If you want timing information (delay or phase), then you need a cross-correlation. You then need to determine how unambiguous you need that time estimate, eg., a sinusoid is ambiguous every period (you can shift the received signal by a full period, and you will get the same cross-correlation result). Cheers, Dave - Altera_Forum
Honored Contributor
Hey Kaz, thanks a lot for the idea. Should I need to use serial or parallel fir? I think serial would do the correlation but my input is 12-bit and thus I will be wasting 13 clock cycles for every output. could you please suggest a smarter configuration which I could use? I am using Stratix II device.
Just for the sake of understanding, could you please suggest me the configuration(coefficients and other settings) for completing the autocorrelation for a=[1 2 3 4]. Thanks a lot.... - Altera_Forum
Honored Contributor
You can use FIR compiler setting coefficients to your sine data(128 data as is or flipped). Correlation is sum of products just like filter's computation.
Edit: You will need just one cycle of f1 and its frequency must be equal to input f then you get max aoutput amplitude if f detected - Altera_Forum
Honored Contributor
--- Quote Start --- I might have confused you by all that description. For now, lets just forget the other things(OFDM,SM and all). I will mention my exact problem. I am generating a sine wave using a LUT with 128 sample points x1=round(((2^10)-1)*(1+sin(linspace(0,2*pi,128)))); now I need to perform w=xcorr(x1,x1,'coeff'); through the blocks in altera DSP Builder Blockset. --- Quote End --- I'm not sure how to do this using specific blockset components, however, the two mathematical techniques are autocorrelation in the lag domain, and multiplication in the frequency domain. For autocorrelation in the lag domain, you multiply samples delayed by registers, eg., see this document (p11 has a hardware implementation) http://www.ovro.caltech.edu/~dwh/wbsddc/correlator_efficiency.pdf (http://www.ovro.caltech.edu/%7edwh/wbsddc/correlator_efficiency.pdf) For autocorrelation in the frequency domain, you can use an FFT, and take the magnitude squared of the output frequency channels. Cheers, Dave - Altera_Forum
Honored Contributor
I might have confused you by all that description. For now, lets just forget the other things(OFDM,SM and all). I will mention my exact problem.
I am generating a sine wave using a LUT with 128 sample points x1=round(((2^10)-1)*(1+sin(linspace(0,2*pi,128)))); now I need to perform w=xcorr(x1,x1,'coeff'); through the blocks in altera DSP Builder Blockset.