-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3_2_barker_xcorrelation_sidelobes.py
More file actions
executable file
·63 lines (49 loc) · 2.1 KB
/
Copy path3_2_barker_xcorrelation_sidelobes.py
File metadata and controls
executable file
·63 lines (49 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
"""Barker code autocorrelation sidelobe comparison.
Compare the autocorrelation (matched-filter output) of an uncoded pulse to
every standard Barker code length. Barker codes are prized because their
autocorrelation sidelobes are at most 1/N of the peak, giving clean detection
with minimal range ambiguity.
"""
import matplotlib.pyplot as plt
from rad_lab.waveform_helpers import matchfilter_with_waveform
from rad_lab.waveform import uncoded_pulse, barker_coded_pulse, BARKER_DICT
from rad_lab.waveform_helpers import zeropad_waveform
print("#############################################")
print("Problem 2: Barker sidelobe check code example")
print("#############################################\n")
print("The sidelobes do not follow the table")
print("\tconsider the ypeak/nchips comment in the problem")
# -- Waveform parameters --
BW = 4e6 # waveform bandwidth [Hz]
sampleRate = 16e6 # sample rate [Hz]
Npad = 50 # zero-pad length for cleaner correlation display
# -- Create the uncoded (reference) pulse and zero-pad it --
tu, mag_u = uncoded_pulse(sampleRate, BW)
tu, mag_u = zeropad_waveform(tu, mag_u, Npad)
fig, ax = plt.subplots(1, 2, figsize=(10, 4))
fig.suptitle("S3P2 Barker sidelobe check")
# Left plot: time-domain pulse shapes
ax[0].plot(tu, mag_u, label="uncoded")
ax[0].set_xlabel("time [s]")
ax[0].set_ylabel("pulse [v]")
ax[0].set_title("normalized pulse")
# Right plot: autocorrelation (matched filter of pulse with itself)
iu, conv_u = matchfilter_with_waveform(mag_u, mag_u)
conv_u = abs(conv_u)
ax[1].plot(iu, conv_u, "-x", label="uncoded")
ax[1].set_xlabel("index offset")
ax[1].set_ylabel("magnitude")
ax[1].set_title("xcorrelation")
# -- Loop over all Barker code lengths and overlay results --
for nChip in BARKER_DICT.keys():
t_b, mag_b = barker_coded_pulse(sampleRate, BW, nChip)
ax[0].plot(t_b, mag_b, label=f"barker {nChip}")
t_b, mag_b = zeropad_waveform(t_b, mag_b, Npad)
ib, conv_b = matchfilter_with_waveform(mag_b, mag_b)
conv_b = abs(conv_b)
ax[1].plot(ib, conv_b, label=f"barker {nChip}")
for a in ax:
a.grid()
a.legend()
plt.show()