Complex Ambiguity Function (CAF)

[1]:
%matplotlib inline
from matplotlib import pylab
from matplotlib.pyplot import plot, ylim, xlabel, ylabel, grid, savefig, imshow, contour
import numpy as np
from matplotlib.pyplot import psd
pylab.rcParams['savefig.dpi'] = 300
[2]:
from caf_verilog import sim_helper as sh
from caf_verilog.caf import simple_caf
from gps_helper.prn import PRN
from sk_dsp_comm import sigsys as ss
from sk_dsp_comm import digitalcom as dc
[3]:
prn = PRN(10)
prn2 = PRN(20)
fs = 625e3
Ns = fs / 200e3
prn_seq = prn.prn_seq()
prn_seq = [*prn_seq, *prn_seq]
prn_seq2 = prn2.prn_seq()
prn_seq,b = ss.nrz_bits2(np.array(prn_seq), Ns)
prn_seq2,b2 = ss.nrz_bits2(np.array(prn_seq2), Ns)
[4]:
Px,f = psd(prn_seq, 2**12, Fs=fs)
plot(f, 10*np.log10(Px))
[4]:
[<matplotlib.lines.Line2D at 0x7f5fc4776d70>]
../_images/nb_examples_CAF_4_1.png
[5]:
f_size = 100
foas = np.arange(-f_size, f_size + 1) * 1000
foas, len(foas)
[5]:
(array([-100000,  -99000,  -98000,  -97000,  -96000,  -95000,  -94000,
         -93000,  -92000,  -91000,  -90000,  -89000,  -88000,  -87000,
         -86000,  -85000,  -84000,  -83000,  -82000,  -81000,  -80000,
         -79000,  -78000,  -77000,  -76000,  -75000,  -74000,  -73000,
         -72000,  -71000,  -70000,  -69000,  -68000,  -67000,  -66000,
         -65000,  -64000,  -63000,  -62000,  -61000,  -60000,  -59000,
         -58000,  -57000,  -56000,  -55000,  -54000,  -53000,  -52000,
         -51000,  -50000,  -49000,  -48000,  -47000,  -46000,  -45000,
         -44000,  -43000,  -42000,  -41000,  -40000,  -39000,  -38000,
         -37000,  -36000,  -35000,  -34000,  -33000,  -32000,  -31000,
         -30000,  -29000,  -28000,  -27000,  -26000,  -25000,  -24000,
         -23000,  -22000,  -21000,  -20000,  -19000,  -18000,  -17000,
         -16000,  -15000,  -14000,  -13000,  -12000,  -11000,  -10000,
          -9000,   -8000,   -7000,   -6000,   -5000,   -4000,   -3000,
          -2000,   -1000,       0,    1000,    2000,    3000,    4000,
           5000,    6000,    7000,    8000,    9000,   10000,   11000,
          12000,   13000,   14000,   15000,   16000,   17000,   18000,
          19000,   20000,   21000,   22000,   23000,   24000,   25000,
          26000,   27000,   28000,   29000,   30000,   31000,   32000,
          33000,   34000,   35000,   36000,   37000,   38000,   39000,
          40000,   41000,   42000,   43000,   44000,   45000,   46000,
          47000,   48000,   49000,   50000,   51000,   52000,   53000,
          54000,   55000,   56000,   57000,   58000,   59000,   60000,
          61000,   62000,   63000,   64000,   65000,   66000,   67000,
          68000,   69000,   70000,   71000,   72000,   73000,   74000,
          75000,   76000,   77000,   78000,   79000,   80000,   81000,
          82000,   83000,   84000,   85000,   86000,   87000,   88000,
          89000,   90000,   91000,   92000,   93000,   94000,   95000,
          96000,   97000,   98000,   99000,  100000]),
 201)

CAF Module

[6]:
from caf_verilog.caf import CAF
from caf_verilog.sim_helper import sim_shift
from caf_verilog.xcorr import dot_xcorr
[7]:
len(prn_seq)
[7]:
6138
[8]:
center = 3000
corr_length = len(foas) - 1
shift = 15
ncorr = np.arange(0, corr_length * 2)
foa_offset = 16
theta_shift = np.exp(1j*2*np.pi*ncorr*(foas[foa_offset])/float(fs))
ref, rec = sim_shift(prn_seq, center, corr_length, shift=shift)
caf = CAF(ref, rec * theta_shift, foas, fs=fs, n_bits=8, ref_i_bits=8, rec_i_bits=8)
caf.gen_tb()
[9]:
ref = np.array(ref)
rec = np.array(rec)
[10]:
xcorr_res_shift = dot_xcorr(ref, rec * theta_shift)
xcorr_res = dot_xcorr(ref, rec)
[11]:
plot(rec.real)
[11]:
[<matplotlib.lines.Line2D at 0x7f5fc46339d0>]
../_images/nb_examples_CAF_12_1.png
[12]:
plot(np.abs(np.array(xcorr_res_shift)))
ylim([0, corr_length])
grid();
xlabel("Inverse Center Offset (Samples)")
savefig('caf_test_shift.png')
../_images/nb_examples_CAF_13_0.png
[13]:
am_pos = np.argmax(abs(np.array(xcorr_res_shift)))
am_pos, abs(np.array(xcorr_res))[am_pos]
[13]:
(37, 36.0)
[14]:
plot(abs(np.array(xcorr_res)))
ylim([0, corr_length])
grid();
am_pos = np.argmax(abs(np.array(xcorr_res)))
am_pos, abs(np.array(xcorr_res))[am_pos]
xlabel("Inverse Center Offset (Samples)")
savefig('caf_test_signal.png')
../_images/nb_examples_CAF_15_0.png

CAF Surface Plot

[15]:
from caf_verilog.caf import simple_caf
[16]:
ref, rec = sim_shift(prn_seq, center, corr_length, shift=shift, freq_shift=foas[105], fs=fs, padding=True)
ref = np.array(ref)
rec = np.array(rec)
[17]:
caf_res, dt = simple_caf(ref, rec, foas=foas, fs=fs)
[18]:
caf_res_np = np.array(caf_res)
[19]:
imshow(caf_res_np, interpolation='none', extent=[-corr_length, corr_length, corr_length, -corr_length])
xlabel("N-th Sample")
ylabel("N-th Frequency Offset")
grid();
../_images/nb_examples_CAF_21_0.png
[20]:
contour(dt, foas / fs, caf_res_np, levels=int(np.ceil(np.log10(corr_length))))
ylabel("Offset in Hz")
xlabel("Offset in Time (s)")
grid();
../_images/nb_examples_CAF_22_0.png