wfg scripts
This commit is contained in:
43
python/waveform_generator/prbs_test.py
Normal file
43
python/waveform_generator/prbs_test.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
def main():
|
||||
bit = list()
|
||||
start = 2
|
||||
lfsr = start
|
||||
i = 1
|
||||
values = []
|
||||
taps = [5, 4]
|
||||
# taps = [5, 4, 2, 1]
|
||||
while True:
|
||||
# fb = ((lfsr >> 5) ^ (lfsr >> 4) & 1)
|
||||
fb = 0
|
||||
for tap in taps:
|
||||
fb ^= ((lfsr >> tap) & 1)
|
||||
|
||||
|
||||
lfsr = ((lfsr << 1) + fb) & (2 ** 6 - 1)
|
||||
bit.append(fb)
|
||||
values.append(lfsr)
|
||||
print(i, lfsr, fb, bin(lfsr))
|
||||
if lfsr == start:
|
||||
print('repeat pattern length', i)
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
print('Duplicate Check', len(values), len(set(values)))
|
||||
|
||||
|
||||
# bit = [float(i) for i in bit]
|
||||
|
||||
# for i in range(2 ** 6 - 1):
|
||||
# bit[i] = 2 * (bit[i] - 0.5)
|
||||
|
||||
plt.plot(values)
|
||||
plt.title('sequence')
|
||||
plt.show()
|
||||
print("done!")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,4 +1,5 @@
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
|
||||
# get one chip of a multi-chip OFDM waveform
|
||||
@@ -105,22 +106,67 @@ def get_pulse_params(n_tx, n_rx, f_samp, n_samp_chip, n_f, n_f_pulse, n_sub_cpi,
|
||||
f_sa_dmux[n_sub_cpi_ind, n_rx_ind, n_tx_ind, n_f_pulse_ind] = f_sa[
|
||||
n_tx_ind, n_sub_cpi_ind, n_f_pulse_ind
|
||||
]
|
||||
return
|
||||
|
||||
return baseband, start_phase, f_sa, chip_samples, chip_center_dmux, chip_lower_dmux, chip_upper_dmux, time_shift_dmux, f_sa_dmux
|
||||
|
||||
|
||||
def wg_ofdm():
|
||||
# wp = inputs.wp.proto # just to make code easier to read
|
||||
n_f = 4
|
||||
n_f_pulse = 4
|
||||
n_f = 8
|
||||
n_f_pulse = 8
|
||||
do_random = False
|
||||
do_agile = False
|
||||
n_sub_cpi = 1
|
||||
n_tx = 1
|
||||
n_rx = 2
|
||||
n_pol = 2
|
||||
n_samp = 32
|
||||
|
||||
n_samp = 64
|
||||
n_samp_chip = 8
|
||||
f_samp = 46875000.0
|
||||
tx_sample_rate_multiplier = 16
|
||||
f_samp = 46875000.0
|
||||
f_samp = 750e6 / tx_sample_rate_multiplier
|
||||
|
||||
# Confused about f_samp, n_samp_chip, and tx_sample_rate_multiplier
|
||||
# I would have expected something like n_chips and n_samples_per_chip
|
||||
# What is the total bandwidth of the approximated LFM, how is that decided
|
||||
# Like more, finer spaced chips
|
||||
|
||||
# Charlie says params are normalized to RX sample rate
|
||||
# f_samp is decimated RX sample rate
|
||||
# n_samp is length of pulse in decimated rx_samples
|
||||
# n_samp_chip
|
||||
|
||||
# n_samp = 512
|
||||
# n_samp_chip = 128
|
||||
# tx_sample_rate_multiplier = 1
|
||||
# f_samp = 46875000.0
|
||||
|
||||
# Start with 32 bit accumulator
|
||||
# phase is intended to be continuation of previous chip
|
||||
# so maybe start phase for just first pulse
|
||||
# put in for each chip but make bypassable
|
||||
|
||||
# Think of time bandwidth product
|
||||
# num chips is sqrt of time bandwidth product to start
|
||||
# each chip must be power of 2
|
||||
|
||||
|
||||
# PRBS length has to match number of chips (need to use every chip in every subcpi)
|
||||
|
||||
|
||||
# total number of chips
|
||||
# number of chips per pulse
|
||||
# num_pulses_in_sub_cpi = total number of chips / number of chips per pulse / number of transmitters
|
||||
# number of transmitters
|
||||
# del_f between chips
|
||||
# Start freq
|
||||
# Seed
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
n_gen_pulses = 1
|
||||
rng = np.random.default_rng(seed=42)
|
||||
perm_list = []
|
||||
@@ -184,49 +230,34 @@ def wg_ofdm():
|
||||
for n_p in range(unique_sub_cpi):
|
||||
perm_list_full.append(perm_list[n_p % unique_sub_cpi])
|
||||
|
||||
# pp_list = PulseParamsList(
|
||||
# pulse_params=[get_pulse_params(wp=wp, perm=p) for p in perm_list_full]
|
||||
# )
|
||||
|
||||
[get_pulse_params(n_tx, n_rx, f_samp, n_samp_chip, n_f, n_f_pulse, n_sub_cpi, n_pol, p) for p in perm_list_full]
|
||||
|
||||
subpulses = np.ndarray(
|
||||
shape=(
|
||||
unique_sub_cpi,
|
||||
n_tx * n_pol,
|
||||
n_sub_cpi,
|
||||
n_samp * tx_sample_rate_multiplier,
|
||||
2, # I/Q
|
||||
),
|
||||
dtype=np.uint16,
|
||||
)
|
||||
|
||||
amplitude_quant = 2 ** (16 - 1) - 1
|
||||
zero_quant = 0
|
||||
|
||||
# This generates transmit waveforms for the whole CPI
|
||||
for n_cpi in range(unique_sub_cpi):
|
||||
pulse, _phase = get_waveform(
|
||||
np.array(
|
||||
pp_list.pulse_params[n_cpi].baseband.elements, dtype=np.double
|
||||
).reshape(tuple(pp_list.pulse_params[n_cpi].baseband.dimensions)),
|
||||
np.array(
|
||||
pp_list.pulse_params[n_cpi].start_phase.elements, dtype=np.double
|
||||
).reshape(tuple(pp_list.pulse_params[n_cpi].start_phase.dimensions)),
|
||||
n_tx * n_pol,
|
||||
n_sub_cpi,
|
||||
n_f_pulse,
|
||||
n_samp_chip * tx_sample_rate_multiplier,
|
||||
n_samp * tx_sample_rate_multiplier,
|
||||
f_samp * tx_sample_rate_multiplier,
|
||||
)
|
||||
p = perm_list_full[0]
|
||||
baseband, start_phase, f_sa, chip_samples, chip_center_dmux, chip_lower_dmux, chip_upper_dmux, time_shift_dmux, f_sa_dmux = (
|
||||
get_pulse_params(n_tx, n_rx, f_samp, n_samp_chip, n_f, n_f_pulse, n_sub_cpi, n_pol, p))
|
||||
|
||||
subpulses[n_cpi, ..., 0] = np.round(
|
||||
(amplitude_quant * np.real(pulse) + zero_quant).astype(np.uint16)
|
||||
)
|
||||
subpulses[n_cpi, ..., 1] = np.round(
|
||||
(amplitude_quant * np.imag(pulse) + zero_quant).astype(np.uint16)
|
||||
)
|
||||
print(baseband/1e6)
|
||||
|
||||
pulse, _phase = get_waveform(baseband,
|
||||
start_phase,
|
||||
n_tx * n_pol,
|
||||
n_sub_cpi,
|
||||
n_f_pulse,
|
||||
n_samp_chip * tx_sample_rate_multiplier,
|
||||
n_samp * tx_sample_rate_multiplier,
|
||||
f_samp * tx_sample_rate_multiplier)
|
||||
|
||||
pulse = np.squeeze(pulse)
|
||||
|
||||
plt.figure()
|
||||
plt.plot(pulse[0, :].real)
|
||||
plt.plot(pulse[0, :].imag)
|
||||
|
||||
plt.figure()
|
||||
plt.plot(pulse[1, :].real)
|
||||
plt.plot(pulse[1, :].imag)
|
||||
|
||||
plt.show()
|
||||
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user