gitting project in git

This commit is contained in:
2025-03-30 21:43:59 -05:00
commit 18988b8656
1975 changed files with 703353 additions and 0 deletions

4
python/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
__pycache__
.idea
*.zip
*.bin

131
python/data_recorder.py Executable file
View File

@@ -0,0 +1,131 @@
import socket
import numpy as np
import ctypes
import data_structures
import threading
import queue
import os
import mmap
class DataRecorder:
def __init__(self,
host="192.168.2.128",
port=1234,
packet_size=4096):
# # TESTTTT
# self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# print('SO_RCVBUF', self.s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
# self.s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4 * 1024 * 1024)
# print('SO_RCVBUF', self.s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
# self.s.settimeout(1)
# self.s.bind(("", 1234))
# data = np.arange(16, dtype=np.uint32)
# data = data.tobytes()
# self.s.sendto(data, (host, 1234))
# self.s.close()
# # TESTTTTT
# UDP Socket for High Speed Data
self.ip = host
self.port = port
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print('SO_RCVBUF', self.s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4 * 1024 * 1024)
print('SO_RCVBUF', self.s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
self.s.settimeout(1)
self.s.bind(("", port))
# Need to send one udp message to set IP and port info inside FPGA
data = np.arange(16, dtype=np.uint32)
data = data.tobytes()
self.s.sendto(data, (self.ip, self.port))
self.max_packet_size = packet_size
# Data Buffer
# self.buffer = bytearray(512 * 1024 * 1024)
self.buffer = mmap.mmap(-1, 512 * 1024 * 1024)
self.buffer_view = memoryview(self.buffer)
self.stop_event = threading.Event()
self.fid = None
self.write_to_disk = False
self.write_offset = 0
self.write_count = 0
self.write_queue = queue.SimpleQueue()
def start_recording(self, filename, write_to_disk=False):
self.write_to_disk = write_to_disk
if write_to_disk:
self.write_offset = 0
self.write_count = 0
self.fid = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_DIRECT )
self.write_queue = queue.SimpleQueue()
self.write_data_thread = threading.Thread(target=self.write_data)
self.write_data_thread.start()
self.get_data_thread = threading.Thread(target=self.get_data)
self.get_data_thread.start()
def stop_recording(self):
print('Stop Thread')
self.stop_event.set()
self.get_data_thread.join()
print('Get Data Thread Joined')
if self.write_to_disk:
self.write_data_thread.join()
print('Write Data Thread Joined')
def write_data(self):
write_chunk_size = 4 * 1024 * 1024
buffer_view = memoryview(self.buffer)
print('Waiting For Data to Write')
while not self.stop_event.is_set():
try:
num_bytes = self.write_queue.get(timeout=1)
self.write_count += num_bytes
if self.write_count > write_chunk_size:
# print(self.write_offset)
# os.write(self.fid, self.buffer[self.write_offset:self.write_offset + write_chunk_size])
os.write(self.fid, buffer_view[self.write_offset:self.write_offset + write_chunk_size])
self.write_offset += write_chunk_size
self.write_count -= write_chunk_size
self.write_offset = self.write_offset % len(self.buffer)
except queue.Empty:
print('DR Queue Empty!', self.ip)
def get_data(self):
offset = 0
print('Waiting For Data From Socket')
while not self.stop_event.is_set():
try:
n = self.s.recv_into(self.buffer_view[offset:offset + self.max_packet_size])
if self.write_to_disk:
self.write_queue.put(n)
offset += n
offset = offset % len(self.buffer)
# print(offset)
except socket.timeout:
continue

173
python/data_structures.py Executable file
View File

@@ -0,0 +1,173 @@
import ctypes
from ctypes import Structure, c_uint64, c_uint32, c_uint16, c_uint8, c_float
AXI_WRITE_REG = 1
AXI_READ_REG = 2
AXI_READ_RESP = 3
ACK_MSG = 4
NACK_MSG = 5
AXI_WRITE_REG_BURST = 6
RF_SPI_WRITE = 7
SET_AD9081_DAC_NCO = 128
SET_AD9081_ADC_NCO = 129
ACK_FLAG_VALID_PACKET = 0x01
ACK_FLAG_VALID_EXECUTION = 0x02
ACK_FLAG_GOT_FRAME_END = 0x04
MAX_BURST_LENGTH = 512
HDR_FLAG_REQ_ACK = 0x01
class CpiHeader(Structure):
_pack_ = 1
_fields_ = [
("sync", c_uint32),
("num_pulses", c_uint32),
("num_samples", c_uint32),
("start_sample", c_uint32),
("tx_num_samples", c_uint32),
("tx_start_sample", c_uint32),
("pri", c_uint32),
("inter_cpi", c_uint32),
# ("spare", c_uint32), # Populated by FPGA
("pps_sec", c_uint64), # Populated by FPGA
("pps_frac_sec", c_uint64), # Populated by FPGA
("system_time", c_uint64), # Populated by FPGA
("tx_lo_offset", c_float),
("rx_lo_offset", c_float),
("data1", c_uint32 * 240) # Populated by user
]
class Header(Structure):
_pack_ = 1
_fields_ = [
("fsync", c_uint32),
("type", c_uint16),
("flags", c_uint16),
("length", c_uint16)
]
# Have to put this here to get pycharm autocomplete to work, don't like this, but autocomplete is too convenient
def __init__(self):
self.fsync = 0xAABBCCDD
self.type = 0
self.flags = 0
self.length = 0
def init_header(self, msg_id):
self.header = Header()
self.header.type = msg_id
self.header.length = ctypes.sizeof(self)
class WriteRegType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("address", c_uint32),
("data", c_uint32)
]
def __init__(self):
init_header(self, AXI_WRITE_REG)
self.address = 0
self.data = 0
class WriteRegBurstType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("address", c_uint32),
("length", c_uint32),
("data", c_uint32 * MAX_BURST_LENGTH)
]
def __init__(self):
init_header(self, AXI_WRITE_REG_BURST)
self.address = 0
self.length = 0
class AckType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("flags", c_uint32)
]
def __init__(self):
init_header(self, ACK_MSG)
self.flags = 0
class ReadRequestType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("address", c_uint32)
]
def __init__(self):
init_header(self, AXI_READ_REG)
self.address = 0
class ReadResponseType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("data", c_uint32)
]
def __init__(self):
init_header(self, AXI_READ_RESP)
self.data = 0
class DacNcoConfigType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("channel", c_uint32),
("frequency", c_float)
]
def __init__(self):
init_header(self, SET_AD9081_DAC_NCO)
self.channel = 0
self.frequency = 0
class AdcNcoConfigType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("channel", c_uint32),
("frequency", c_float)
]
def __init__(self):
init_header(self, SET_AD9081_ADC_NCO)
self.channel = 0
self.frequency = 0
class RfSpiWriteType(Structure):
_pack_ = 1
_fields_ = [
("header", Header),
("dev_sel", c_uint32),
("num_bits", c_uint32),
("data", c_uint32)
]
def __init__(self):
init_header(self, RF_SPI_WRITE)
self.dev_sel = 0
self.num_bits = 0
self.data = 0

303
python/radar_manager.py Executable file
View File

@@ -0,0 +1,303 @@
import ctypes
import datetime
import ipaddress
import socket
import struct
import time
import numpy as np
import data_structures as msg_types
from data_structures import CpiHeader
TIMING_ENGINE_ADDR = 0x40051000
DIG_RX_ADDR = 0x20000000
DIG_RX_STRIDE = 0x10000
WAVEFORM_GEN_ADDR = 0x40053000
NUM_RX = 2
def form_chirp(pulsewidth, bw, sample_rate, win=None, ):
n = int(np.round(pulsewidth * sample_rate))
d_t = 1 / sample_rate
f = np.linspace(-bw/2, bw/2, n)
phi = np.cumsum(2 * np.pi * f * d_t)
x = np.exp(-1j * phi)
return x.astype(np.complex64)
class RadarManager:
def __init__(self,
host="192.168.1.200",
port=5001):
self.host = host
self.port = port
self.s = None
self.CONNECTED = False
self.connect()
# Update UDP packet size
self.packet_size = 4096
self.axi_write_register(0x4005001C, self.packet_size)
self.reset_10g_udp()
self.stop_running()
def connect(self):
self.CONNECTED = False
retry_cnt = 0
while True:
try:
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.settimeout(5)
self.s.connect((self.host, self.port))
self.s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.s.settimeout(5)
self.CONNECTED = True
break
except socket.error as e:
print("Connection Error %s" % e)
# print("Connection Timeout, trying again %d" % retry_cnt)
self.CONNECTED = False
retry_cnt += 1
if retry_cnt >= 1:
break
return self.CONNECTED
def disconnect(self):
self.s.close()
self.CONNECTED = False
def is_connected(self):
return self.CONNECTED
def send_bytes(self, msg_bytes):
self.s.sendall(msg_bytes)
def send_message(self, msg, update_hdr=True, enable_ack=True, wait_for_ack=True, timeout=10):
self.s.settimeout(timeout)
ret = True
msg.header.flags = 0
# Request a completion ACK
if enable_ack:
msg.header.flags = msg_types.HDR_FLAG_REQ_ACK
# Serialize message and send
self.send_bytes(bytes(msg))
# Need to wait for response
if wait_for_ack:
recv_bytes, err = self.get_response(ctypes.sizeof(msg_types.AckType))
resp = msg_types.AckType.from_buffer_copy(recv_bytes)
ret = True
return ret
def get_response(self, size):
recv_data = bytearray()
while len(recv_data) < size:
try:
recv_data += self.s.recv(size, 0)
except socket.timeout as e:
return 0, -1
return recv_data, 0
def axi_write_register(self, address, data):
# Make sure address is word aligned
address -= (address % 4)
# Form message
msg = msg_types.WriteRegType()
msg.address = address
msg.data = data
self.send_message(msg)
return
def axi_write_register_burst(self, address, data):
# Make sure address is word aligned
address -= (address % 4)
# Form message
msg = msg_types.WriteRegBurstType()
msg.address = address
msg.length = len(data)
for i in range(len(data)):
msg.data[i] = data[i]
self.send_message(msg)
return
def axi_read_register(self, address):
# Make sure address is word aligned
address -= (address % 4)
# Form message
msg = msg_types.ReadRequestType()
msg.address = address
self.send_message(msg, enable_ack=False, wait_for_ack=False)
# Get response
recv_bytes, _ = self.get_response(ctypes.sizeof(msg_types.ReadResponseType))
resp = msg_types.ReadResponseType.from_buffer_copy(recv_bytes)
return resp.data
def set_dac_nco(self, channel, frequency):
# Form message
msg = msg_types.DacNcoConfigType()
msg.channel = channel
msg.frequency = frequency
self.send_message(msg)
return
def set_adc_nco(self, channel, frequency):
# Form message
msg = msg_types.AdcNcoConfigType()
msg.channel = channel
msg.frequency = frequency
self.send_message(msg)
return
def rf_spi_write(self, dev_sel, num_bits, data):
# Form message
msg = msg_types.RfSpiWriteType()
msg.dev_sel = dev_sel
msg.num_bits = num_bits
msg.data = data
self.send_message(msg)
return
def load_waveform(self, ch, amp, bw, pw):
addr = 0x0010000 + 0x0010000 * ch
print('Load', hex(addr))
num_samples = pw
wf = form_chirp(pw, bw, 1)
wf = wf * amp
bram_address = addr
iq = wf * 0x7FFF
iq_real = iq.real.astype(np.uint16)
iq_imag = iq.imag.astype(np.uint16)
iq_real = iq_real.astype(np.uint32)
iq_imag = iq_imag.astype(np.uint32)
data = iq_real | (iq_imag << 16)
num_bursts = num_samples / msg_types.MAX_BURST_LENGTH
num_bursts = int(np.ceil(num_bursts))
for i in range(num_bursts):
start_ind = i * msg_types.MAX_BURST_LENGTH
stop_ind = start_ind + msg_types.MAX_BURST_LENGTH
stop_ind = min(stop_ind, num_samples)
burst_data = data[start_ind:stop_ind]
self.axi_write_register_burst(bram_address + i * 4 * msg_types.MAX_BURST_LENGTH, burst_data)
def reset_10g_udp(self):
val = self.axi_read_register(0x40050008)
self.axi_write_register(0x40050008, val | (1 << 15))
self.axi_write_register(0x40050008, val)
time.sleep(2)
def setup_cpi_header(self, pri, inter_cpi, num_pulses, num_samples, start_sample,
tx_num_samples, tx_start_sample, rx_lo_offset, tx_lo_offset):
# Load Up header BRAM
header = CpiHeader()
header.sync = 0xAABBCCDD
header.num_pulses = num_pulses
header.num_samples = num_samples
header.start_sample = start_sample
header.tx_num_samples = tx_num_samples
header.tx_start_sample = tx_start_sample
header.pri = pri
header.inter_cpi = inter_cpi
header.tx_lo_offset = tx_lo_offset
header.rx_lo_offset = rx_lo_offset
data = np.frombuffer(bytes(header), dtype=np.uint32)
self.axi_write_register_burst(TIMING_ENGINE_ADDR + 0xC00, data)
def setup_timing_engine(self, pri, num_pulses, inter_cpi):
self.axi_write_register(TIMING_ENGINE_ADDR + 0x4, pri - 1)
self.axi_write_register(TIMING_ENGINE_ADDR + 0x8, num_pulses)
self.axi_write_register(TIMING_ENGINE_ADDR + 0x10, inter_cpi - 1)
def setup_rx(self, num_samples, start_sample):
for i in range(NUM_RX):
self.axi_write_register(DIG_RX_ADDR + i*DIG_RX_STRIDE + 0x4, num_samples >> 2)
self.axi_write_register(DIG_RX_ADDR + i*DIG_RX_STRIDE + 0x8, start_sample >> 2)
def setup_tx(self, num_samples, start_sample):
self.axi_write_register(WAVEFORM_GEN_ADDR + 0x4, num_samples >> 2)
self.axi_write_register(WAVEFORM_GEN_ADDR + 0x8, start_sample >> 2)
def start_running(self):
for i in range(NUM_RX):
self.axi_write_register(DIG_RX_ADDR + i*DIG_RX_STRIDE + 0x0, 0) # RX Reset
self.axi_write_register(WAVEFORM_GEN_ADDR + 0x0, 0) # TX Reset
self.axi_write_register(TIMING_ENGINE_ADDR + 0x0, 0) # Timing Reset (do this last)
def stop_running(self):
self.axi_write_register(TIMING_ENGINE_ADDR + 0x0, 1) # Timing Engine Reset
for i in range(NUM_RX):
self.axi_write_register(DIG_RX_ADDR + i*DIG_RX_STRIDE + 0x0, 1) # RX Reset
self.axi_write_register(WAVEFORM_GEN_ADDR + 0x0, 1) # TX Reset
def setup_rf_attenuators(self, rf_atten):
self.rf_spi_write(0, 6, rf_atten[0]) # TX0 RF (ADRF5730)
self.rf_spi_write(1, 6, rf_atten[1]) # TX1 RF (ADRF5730)
self.rf_spi_write(2, 6, rf_atten[2]) # RX0 RF (ADRF5721)
self.rf_spi_write(3, 6, rf_atten[3]) # RX0 IF (HMC624)
self.rf_spi_write(4, 6, rf_atten[4]) # RX1 RF (ADRF5721)
self.rf_spi_write(5, 6, rf_atten[5]) # RX1 IF (HMC624)
def configure_cpi(self, pri, inter_cpi, num_pulses, num_samples, start_sample,
tx_num_samples, tx_start_sample, rx_lo_offset, tx_lo_offset):
self.load_waveform(0, 1, 0.1, tx_num_samples)
self.load_waveform(1, 1, 0.1, tx_num_samples)
rf_atten = [1, 2, 3, 4, 5, 6]
self.setup_rf_attenuators(rf_atten)
# DAC at 5.25 GHz is in second nyquist
# ADC would be in 3rd nyquist
lo = 5.25e9
f_dac = 9e9
f_adc = 3e9
tx_lo = 5.25e9 % f_dac
rx_lo = 5.25e9 % f_adc
for i in range(4):
self.set_adc_nco(i, rx_lo)
self.set_dac_nco(0, tx_lo)
self.set_dac_nco(1, tx_lo)
self.set_dac_nco(2, tx_lo + tx_lo_offset)
self.set_dac_nco(3, tx_lo + rx_lo_offset)
self.setup_timing_engine(pri, num_pulses, inter_cpi)
self.setup_rx(num_samples, start_sample)
self.setup_tx(tx_num_samples, tx_start_sample)
self.setup_cpi_header(pri, inter_cpi, num_pulses, num_samples, start_sample,
tx_num_samples, tx_start_sample, rx_lo_offset, tx_lo_offset)

113
python/read_data_file.py Executable file
View File

@@ -0,0 +1,113 @@
import ctypes
import os.path
import time
import numpy as np
from matplotlib import pyplot as plt
import socket
import data_structures
import radar_manager
from data_recorder import DataRecorder
def db20(x):
return 20*np.log10(np.abs(x))
def db20n(x):
x = db20(x)
x = x - np.max(x)
return x
def main():
print('Hello')
clk = 187.5e6
# Parse Data
headers = []
offset = 0
file = 'test0.bin'
fid = open(file, 'rb')
# Find header, recording buffer could have wrapped depending on data rate and how long we ran for
hdr_sync = False
while not hdr_sync:
# data = recorder.buffer[offset:offset + 4]
data = fid.read(4)
sync_word = np.frombuffer(data, dtype=np.uint32)[0]
if sync_word == 0xAABBCCDD:
hdr_sync = True
print('Header found at offset', offset)
fid.seek(-4, 1)
# Get the first header
header = fid.read(ctypes.sizeof(data_structures.CpiHeader))
header = data_structures.CpiHeader.from_buffer_copy(header)
fid.seek(-ctypes.sizeof(data_structures.CpiHeader), 1)
# CPI Parameters (timing values are in clk ticks)
num_pulses = header.num_pulses
num_samples = header.num_samples
pri = header.pri
inter_cpi = header.inter_cpi
data_size = num_pulses * num_samples * 4
file_size = os.path.getsize(file)
expected_num_cpis = int(file_size / (ctypes.sizeof(data_structures.CpiHeader) + data_size))
print('Expected CPIS:', expected_num_cpis)
for i in range(expected_num_cpis):
# Get Header
data = fid.read(ctypes.sizeof(data_structures.CpiHeader))
headers.append(data_structures.CpiHeader.from_buffer_copy(data))
# Get CPI
data = fid.read(data_size)
# Check some header fields
cpi_times = np.array([x.system_time for x in headers]) / 187.5e6
pps_frac = np.array([x.pps_frac_sec for x in headers]) / 187.5e6
pps_sec = np.array([x.pps_sec for x in headers])
utc_time = pps_sec + pps_frac
print(pri, inter_cpi, num_pulses * pri + inter_cpi)
print(cpi_times - cpi_times[0])
print(pps_frac)
print(pps_sec - pps_sec[0])
# Plot last CPI
data2 = np.frombuffer(data, dtype=np.int16)
i = data2[0::2]
q = data2[1::2]
iq = i + 1j * q
iq = iq.reshape(-1, num_samples)
iq = iq + 1e-15
vmin = -60
vmax = 0
plt.figure()
plt.plot(np.diff(cpi_times))
plt.figure()
plt.plot(iq.T.real, '.-')
plt.plot(iq.T.imag, '--.')
plt.grid()
plt.figure()
plt.imshow(db20n(iq), aspect='auto', interpolation='nearest', vmin=vmin, vmax=vmax)
plt.ylabel('Pulse Count')
plt.xlabel('Sample Count')
plt.colorbar()
plt.show()
if __name__ == '__main__':
main()

135
python/test_cpi.py Executable file
View File

@@ -0,0 +1,135 @@
import ctypes
import time
import numpy as np
from matplotlib import pyplot as plt
import data_structures
import radar_manager
from data_recorder import DataRecorder
# Give 10g eth interface an ip and set MTU for better performance
# sudo ifconfig enp5s0f0 192.168.2.10 up mtu 5000
# sudo ifconfig enp5s0f1 192.168.3.10 up mtu 5000
# Note that increases the size of rmem_max in the linux kernel improves performance for data recording
# this can be done witht the following terminal command
# sudo sysctl -w net.core.rmem_max=1048576
def db20(x):
return 20*np.log10(np.abs(x))
def db20n(x):
x = db20(x)
x = x - np.max(x)
return x
def main():
print('Hello')
clk = 187.5e6
# CPI Parameters (timing values are in clk ticks)
num_pulses = 128
num_samples = 8192
start_sample = 0
tx_num_samples = 1024
tx_start_sample = start_sample
pri = int(.001 * clk)
inter_cpi = 50
tx_lo_offset = 10e6
rx_lo_offset = 0
pri_float = pri / clk
print('PRI', pri_float, 'PRF', 1 / pri_float)
print('Expected Data Rate', num_samples * 4 / pri_float / 1e6)
radar = radar_manager.RadarManager()
recorder0 = DataRecorder("192.168.2.128", 1234, packet_size=radar.packet_size)
recorder1 = DataRecorder("192.168.3.128", 1235, packet_size=radar.packet_size)
recorder0.start_recording('test0.bin', True)
recorder1.start_recording('test1.bin', True)
radar.configure_cpi(pri, inter_cpi, num_pulses, num_samples, start_sample,
tx_num_samples, tx_start_sample, rx_lo_offset, tx_lo_offset)
print('Start Running')
radar.start_running()
# Let it run for a bit
time.sleep(5)
# Stop running
radar.stop_running()
# Stop the data recorder
recorder0.stop_recording()
recorder1.stop_recording()
# Parse some data
# Find header, recording buffer could have wrapped depending on data rate and how long we ran for
recorders = [recorder0, recorder1]
for recorder in recorders:
headers = []
offset = 0
plot_recorder = recorder
hdr_sync = False
while not hdr_sync:
data = plot_recorder.buffer[offset:offset + 4]
sync_word = np.frombuffer(data, dtype=np.uint32)[0]
if sync_word == 0xAABBCCDD:
hdr_sync = True
print('Header found at offset', offset)
else:
offset += 4
num_cpi = 16
for i in range(num_cpi):
# Get Header
data = plot_recorder.buffer[offset:offset + ctypes.sizeof(data_structures.CpiHeader)]
offset += ctypes.sizeof(data_structures.CpiHeader)
headers.append(data_structures.CpiHeader.from_buffer_copy(data))
# Get CPI
data_size = num_pulses * num_samples * 4
data = plot_recorder.buffer[offset:offset + data_size]
offset += data_size
# Check some header fields
cpi_times = np.array([x.system_time for x in headers]) / 187.5e6
pps_frac = np.array([x.pps_frac_sec for x in headers]) / 187.5e6
pps_sec = np.array([x.pps_sec for x in headers])
utc_time = pps_sec + pps_frac
print(pri, inter_cpi, num_pulses * pri + inter_cpi)
print(cpi_times - cpi_times[0])
print(pps_frac)
print(pps_sec - pps_sec[0])
# Plot last CPI
data2 = np.frombuffer(data, dtype=np.int16)
i = data2[0::2]
q = data2[1::2]
iq = i + 1j * q
iq = iq.reshape(-1, num_samples)
iq = iq + 1e-15
vmin = -60
vmax = 0
fid, axs = plt.subplots(2)
axs[0].plot(iq.T.real, '.-')
axs[0].plot(iq.T.imag, '--.')
axs[0].grid()
axs[1].imshow(db20n(iq), aspect='auto', interpolation='nearest', vmin=vmin, vmax=vmax)
axs[1].set_ylabel('Pulse Count')
axs[1].set_xlabel('Sample Count')
plt.show()
if __name__ == '__main__':
main()