updates to ofdm waveform gen

This commit is contained in:
2025-10-17 11:52:35 -05:00
parent 086c5dd9f3
commit 60ac0021c8
10 changed files with 951 additions and 51 deletions

View File

@@ -2,6 +2,8 @@ from matplotlib import pyplot as plt
from ctypes import *
import numpy as np
from read_data_file import db20n
def read_sim_output(filename, is_float=False):
fid = open(filename, "r")
@@ -24,10 +26,27 @@ def main():
data[data >= 2**15] -= 2**16
data = data[0::2] + 1j * data[1::2]
x = np.fft.fft(data)
f_axis = np.fft.fftfreq(x.size, d=1/750)
x = np.fft.fftshift(x)
f_axis = np.fft.fftshift(f_axis)
plt.figure()
plt.plot(f_axis, db20n(x))
plt.figure()
plt.plot(data.real)
plt.plot(data.imag)
plt.title('Sim Output')
plt.title('HDL Sim Output - IQ')
plt.grid()
plt.figure()
plt.plot(np.unwrap(np.angle(data)))
plt.title('HDL Sim Output - Phase')
plt.grid()
plt.show()

View File

@@ -5,10 +5,16 @@ def main():
f = 10e6
n = 4096
start_freq = -20507812.5
start_freq = start_freq/fs * 2**32
if (start_freq < 0):
start_freq += 2**32
print(start_freq)
freq = f/fs * 2**31
delta_freq = 5859375
delta_freq = delta_freq/fs * 2**32
print(delta_freq)
print(freq)
if __name__ == '__main__':
main()

View File

@@ -118,8 +118,8 @@ def wg_ofdm():
do_agile = False
n_sub_cpi = 1
n_tx = 1
n_rx = 2
n_pol = 2
n_rx = 1
n_pol = 1
n_samp = 64
n_samp_chip = 8
@@ -237,6 +237,7 @@ def wg_ofdm():
get_pulse_params(n_tx, n_rx, f_samp, n_samp_chip, n_f, n_f_pulse, n_sub_cpi, n_pol, p))
print(baseband/1e6)
print(start_phase)
pulse, _phase = get_waveform(baseband,
start_phase,
@@ -247,15 +248,27 @@ def wg_ofdm():
n_samp * tx_sample_rate_multiplier,
f_samp * tx_sample_rate_multiplier)
print('Num Chips', baseband.size)
print('Start Freq', baseband[0])
print('Delta Freq', np.unique(np.diff(baseband)))
pulse = np.squeeze(pulse)
plt.figure()
plt.plot(pulse[0, :].real)
plt.plot(pulse[0, :].imag)
plt.plot(pulse.real)
plt.plot(pulse.imag)
plt.title('Python Output - IQ')
plt.grid()
plt.figure()
plt.plot(pulse[1, :].real)
plt.plot(pulse[1, :].imag)
plt.plot(np.unwrap(np.angle(pulse)))
# plt.plot(np.angle(pulse), '.-')
plt.title('Python Output - Phase')
plt.grid()
# plt.figure()
# plt.plot(pulse[1, :].real)
# plt.plot(pulse[1, :].imag)
plt.show()

View File

@@ -0,0 +1,47 @@
import numpy as np
from matplotlib import pyplot as plt
def wg_ofdm():
tx_sample_rate = 750e6
rx_decimation = 16
rx_sample_rate = tx_sample_rate / rx_decimation
n_rx_samp_per_chip = 16 # Keep at >= x2 of num_chips and start phase will always be 0, if num chips is power of 2?
num_chips = 8
n_tx_samp_per_chip = n_rx_samp_per_chip * rx_decimation
n_tx_samp_per_pulse = n_tx_samp_per_chip * num_chips
print(n_tx_samp_per_chip / 4)
chip_freq = (np.arange(num_chips) - num_chips//2 + 0.5)/num_chips * rx_sample_rate
# First, generate simple in order waveform
freq = np.repeat(chip_freq, n_tx_samp_per_chip)
phase = freq / tx_sample_rate
phase = np.cumsum(np.concatenate([[0], phase]))
phase = phase[0:-1]
# Extract the start phases of each chip, ideally these are always 0
chip_start_phase = phase[0::n_tx_samp_per_chip] % 1
print(chip_start_phase)
print(chip_start_phase * 2**16)
print(chip_freq)
x = np.exp(1j * 2 * np.pi * phase)
plt.figure()
plt.plot(x.real)
plt.plot(x.imag)
plt.figure()
plt.plot(np.unwrap(np.angle(x)))
plt.show()
return
if __name__ == '__main__':
wg_ofdm()