Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

Problem in Implementing Autocorrelation on Stratix II EP2S60 DSP Development Board

Altera_Forum
Honored Contributor II
4,876 Views

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.... 

 

-S
0 Kudos
23 Replies
Altera_Forum
Honored Contributor II
2,474 Views

 

--- Quote Start ---  

 

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. 

 

--- Quote End ---  

If the transmitted signal is a sinusoid, then the autocorrelation is a cosine. Auto-correlation not help you synchronize, cross-correlation does; you correlate a reference signal to the incoming signal and try to 'find' the start of the transmitted signal. Since the peaks of the cross-correlation of two sinusoids repeat every period, the synchronization is ambiguous, so it won't work very well. 

 

Synchronization based on autocorrelation typically uses pseudo-random binary sequences (PRBS), since the auto-correlation, or really the cross-correlation of a PRBS at the receiver, with the incoming PRBS has a peak. When you move the peak to the zeroth lag, you are synchronized to the transmitter. Radar and sonar systems use FM chirp pulses (linear FM), Barker codes, and other signals with sharp autocorrelation peaks. 

 

There is no peak in your scheme, so it won't work. 

 

Why don't you explain what you are trying to do. Can you change the transmit signal? 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

thanks for the reply Dave.I really appreciate your interest. 

 

I am basically using OFDM kinda thing for Spatial Modulation. I am transmitting a sinusoid of say freq f1 for synchronization and subsequently of freq f2 for data and will be performing correlation with sinusoid of freq f1 on the receiver side. I expect to get a peak of approx 1 for auto-correlation which will trigger my receiver to collect data. The problem I have is that I am using 128 data length for each symbol and I am using altera blockset (simulink) and I am totally confused about what blocks to use for performing the correlation thing. 

 

thanks...
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- Quote Start ---  

 

I am basically using OFDM kinda thing for Spatial Modulation. I am transmitting a sinusoid of say freq f1 for synchronization and subsequently of freq f2 for data and will be performing correlation with sinusoid of freq f1 on the receiver side. I expect to get a peak of approx 1 for auto-correlation which will trigger my receiver to collect data. The problem I have is that I am using 128 data length for each symbol and I am using altera blockset (simulink) and I am totally confused about what blocks to use for performing the correlation thing. 

 

--- Quote End ---  

In direct spread spectrum (DSS) systems like CDMA, base stations transmit PRBS codes for synchronization. I have not looked into OFDM, so I am not familiar with their technique. However, your description does not sound correct, perhaps you really mean different 'carriers' for modulated data. 

 

Can you please provide a reference for OFDM where they discuss synchronization. 

 

Altera has some application notes on OFDM, so how do they synchronize? 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- 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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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....
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- 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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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,
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- 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
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

hey...thanks for all your help. I have almost completed my design. Now I have the problem implementing it on the board. I guess the problem is because of FIR Megacore I am using. Could you please help me with implementing FIR Megacore on the board? 

 

Thanks 

saket
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- Quote Start ---  

I have almost completed my design. Now I have the problem implementing it on the board. I guess the problem is because of FIR Megacore I am using. Could you please help me with implementing FIR Megacore on the board? 

 

--- Quote End ---  

No, not without an explanation of what you decided to design :) 

 

Please explain your system-level design, and then people can help. 

 

Before you work with the Altera tools, you need to design the filter(s). 

 

For example, if you know the frequency of the signal you are trying to detect the power of, then your design could be implemented per the discussion in this thread; 

 

http://www.alteraforum.com/forum/showthread.php?t=30284&page=3 

 

I just posted a MATLAB script showing how to decimate a high-rate sampled signal, to a low-rate sampled signal. The script shows that the particular combination of filters meets the design requirements, however, the script is not an HDL implementation. The next task for the person I was responding to, is to go and implement these filters in CIC Compiler, and FIR Compiler II. 

 

In your design, you would demodulate your received signal using the known frequency (generated using an NCO with quadrature outputs), low-pass filter and decimate (both the in-phase and quadrature components), and then calculate the power. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

hey Dave, 

 

thanks for the suggestions but I have only configured my fir_compiler megacore and its working fine in dsp builder. I was trying to program it on the board and it wouldn program. I was asking if any extra care I need to take for implementing the megacore on the board. 

 

Cheers, 

Saket
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- Quote Start ---  

 

I was trying to program it on the board and it wouldn program. I was asking if any extra care I need to take for implementing the megacore on the board. 

 

--- Quote End ---  

If you do not have an FIR Compiler license, then I believe you need to keep the JTAG cable connected. Even then, the design might become non-functional after some time. You will need to read the messages from Quartus, I believe they will tell you what the limits on the design are. 

 

These limits will not occur in the simulator. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

Hey Dave, 

 

hope you are fine on the other end. I am not so fine as the transmitter and receiver are not getting synchronized :( 

I am trying to use the peak of auto-correlation to synchronize but I think its not the best way.Could you please suggest any other technique to synchronize? I just need to find the delay of channel so that I can guide receiver to decode data. 

 

Please help!!!! 

Saket
0 Kudos
Altera_Forum
Honored Contributor II
2,474 Views

 

--- Quote Start ---  

 

hope you are fine on the other end. I am not so fine as the transmitter and receiver are not getting synchronized :( 

I am trying to use the peak of auto-correlation to synchronize but I think its not the best way.Could you please suggest any other technique to synchronize? I just need to find the delay of channel so that I can guide receiver to decode data. 

 

--- Quote End ---  

Please describe your hardware setup in a little more detail. 

 

What are you actually trying to do? 

 

What are the frequencies of operation? 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
2,369 Views

I am working with frequencies of 3MHz(transmitted signal) and trying to make a model of visible light communication.

0 Kudos
Reply