 # Cross Correlation Function

Hi,
Did anybody know how to implement cross correlation function? Thanks.
It is not gr_simple_correlator, is it?
Thanks

Sunflower:

the correlator may be used. You may also use the filtering routine by
making the appropriate changes to the waveform you wish to cross
correlate against the incoming signal such as reverse in time and
complex conjugate. What are your needs?

sunflower wrote:

Hi,
Did anybody know how to implement cross correlation function? Thanks.
It is not gr_simple_correlator, is it?
Thanks

AMSAT VP Engineering. Member: ARRL, AMSAT-DL, TAPR, Packrats,
NJQRP/AMQRP, QRP ARCI, QCWA, FRC. ARRL SDR Wrk Grp Chairman
Laziness is the number one inspiration for ingenuity. Guilty as
charged!

sunflower wrote:

If you want a generic correlation function then you can do correlation
in the frequency domain quite efficiently.

See the code below on how to do this:

This code is very well suited if you want the whole correlation function
over a reletively large time-frame.
This code is maybe not the best way when you only want to know where the
correlation peak is and already know where it approximately should be.

You can also find this code on:

(Look for the file named correlator.py)
I extracted it from my passive radar experiments code which you also can
find there.
(But which are not very readable)

class correlator_c(gr.hier_block):
def init(self, fg, fft_size=512,output_type=‘COMPLEX’):
#This Hier_block expects an input block with two interleaved
gr_complex signals
#It outputs fft_size blocks with time zero at the middle of the
block
#Output type can be chosen between ‘COMPLEX’, ‘REAL’, ‘MAG’ or
‘ARG’
#
#You can use it in the following way:
# interleaver= gr.interleave(gr.sizeof_gr_complex)
# fg.connect(src0,(interleaver,0))
# fg.connect(src1,(interleaver,1))
#
corr=correlator.correlator_c(fg=fg,fft_size=512,output_type=‘COMPLEX’)
# fg.connect(interleaver,corr)
#

``````    di = gr.deinterleave(gr.sizeof_gr_complex)
s2p_a = gr.serial_to_parallel(gr.sizeof_gr_complex, fft_size)
s2p_b = gr.serial_to_parallel(gr.sizeof_gr_complex, fft_size)
s2p3 = gr.serial_to_parallel(gr.sizeof_gr_complex, fft_size)
p2s_a = gr.parallel_to_serial(gr.sizeof_gr_complex, fft_size)
p2s_b = gr.parallel_to_serial(gr.sizeof_gr_complex, fft_size)

mywindow = fftsink.window.blackmanharris(fft_size)

fft_a = gr.fft_vcc(fft_size, True, mywindow)
fft_b = gr.fft_vcc(fft_size, True, mywindow)
ifft=gr.fft_vcc(fft_size, False, mywindow)

conj=gr.conjugate_cc()
mult=gr.multiply_cc()

#get the ffts of the input signals (go from time to frequency
``````

domain)
fg.connect((di,0),s2p_a,fft_a,p2s_a)
fg.connect((di,1),s2p_b,fft_b,p2s_b)

``````    #do the correlation in the frequency domain
fg.connect(p2s_a,conj)
fg.connect(p2s_b,(mult,0))
fg.connect(conj,(mult,1))

#transform back to the time domain
fg.connect(mult,s2p3,ifft)

if output_type=='REAL':
c2real = gr.complex_to_real(fft_size)
elif output_type=='MAG':
c2real=gr.complex_to_mag(fft_size)
elif output_type=='ARG':
c2real=gr.complex_to_arg(fft_size)
if output_type=='COMPLEX':
sink=ifft
else:
fg.connect(ifft,c2real)
sink=c2real

gr.hier_block.__init__(self, fg, di, sink)``````

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.