waterfall display

This commit is contained in:
Sebastien Bourdeauducq 2020-08-10 19:22:58 +08:00
parent 08efdf6352
commit 15e7a87959
4 changed files with 62 additions and 41 deletions

67
dmi.py
View File

@ -3,6 +3,7 @@ import numpy as np
import gc
from noptica import *
from gui import GUI
def main():
@ -11,42 +12,50 @@ def main():
freq_sample = 1e6
freq_base = 1088230e3
bufsize = 4096
block_size = 4096
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
induction.start()
gui = GUI()
try:
stabilizer = Stabilizer(bufsize, 80.0, 1088.1e6 - freq_base, 10e-6, induction)
position_tracker = PositionTracker(int(0.1*freq_sample/bufsize))
sdr = SoapySDR.Device()
for channel in range(2):
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
buf_sdr = BufferedSDR(sdr, [0, 1], bufsize, 256)
buf_sdr.start()
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
induction.start()
try:
stabilizer_throttle = 0
while True:
buffers = buf_sdr.get()
try:
samples_ref, samples_meas = buffers
def stabilizer_cb(spectrum, tuning):
gui.update_beat_spectrum(spectrum)
induction.set(tuning)
# We can't update faster than the MHS5200A serial interface
stabilizer_throttle += 1
if stabilizer_throttle == 8:
stabilizer.input(samples_ref)
stabilizer_throttle = 0
stabilizer = Stabilizer(block_size, 80.0, 1088.1e6 - freq_base, 10e-6, stabilizer_cb)
position_tracker = PositionTracker(int(0.1*freq_sample/block_size))
#position, leakage = position_tracker.input(samples_ref, samples_meas)
#print(np.sum(position)/len(position), leakage)
finally:
buf_sdr.dispose(buffers)
sdr = SoapySDR.Device()
for channel in range(2):
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
buf_sdr = BufferedSDR(sdr, [0, 1], block_size, 256)
buf_sdr.start()
try:
stabilizer_throttle = 0
while True:
buffers = buf_sdr.get()
try:
samples_ref, samples_meas = buffers
# We can't update faster than the MHS5200A serial interface
stabilizer_throttle += 1
if stabilizer_throttle == 8:
stabilizer.input(samples_ref)
stabilizer_throttle = 0
#position, leakage = position_tracker.input(samples_ref, samples_meas)
#print(np.sum(position)/len(position), leakage)
finally:
buf_sdr.dispose(buffers)
finally:
buf_sdr.stop()
finally:
buf_sdr.stop()
induction.stop()
finally:
induction.stop()
gui.close()
if __name__ == "__main__":

25
gui.py
View File

@ -47,17 +47,28 @@ class ParentComm:
os.close(self.c_wfd)
class GUI:
def __init__(self):
self.impl = ParentComm()
self.impl.create_subprocess([sys.executable,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py")])
def update_beat_spectrum(self, data):
obj = {"action": "update_beat_spectrum", "data": data}
self.impl.write_pyon(obj)
def close(self):
obj = {"action": "terminate"}
self.impl.write_pyon(obj)
self.impl.close()
def main():
gui = ParentComm()
gui = GUI()
try:
gui.create_subprocess([sys.executable, os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py")])
for i in range(600):
obj = {"action": "update", "data": np.random.normal(size=4096)}
gui.write_pyon(obj)
for i in range(200):
gui.update_beat_spectrum(np.random.normal(size=4096))
time.sleep(1/60)
obj = {"action": "terminate"}
gui.write_pyon(obj)
finally:
gui.close()

View File

@ -32,7 +32,7 @@ class SpectrogramWidget(pg.PlotWidget):
def update(self, block):
self.img_array = np.roll(self.img_array, -1, 0)
self.img_array[-1:] = block
self.img_array[-1:] = np.fft.fftshift(block)
self.img.setImage(self.img_array, autoLevels=True)
@ -49,7 +49,7 @@ class IPCClient(AsyncioChildComm):
obj = await self.read_pyon()
try:
action = obj["action"]
if action == "update":
if action == "update_beat_spectrum":
spectrogram.update(obj["data"])
if action == "terminate":
self.close_cb()

View File

@ -104,13 +104,14 @@ class InductionHeater:
self.thread.join()
self.serial.close()
class Stabilizer:
def __init__(self, fft_size, amp_threshold, freq_target, k, tuner):
def __init__(self, fft_size, amp_threshold, freq_target, k, cb):
self.freqs = np.fft.fftfreq(fft_size)
self.amp_threshold = amp_threshold
self.freq_target = freq_target
self.k = k
self.tuner = tuner
self.cb = cb
def input(self, samples):
spectrum = np.abs(np.fft.fft(samples*blackmanharris(len(samples))))
@ -122,7 +123,7 @@ class Stabilizer:
tuning = (freq - self.freq_target)*self.k
else:
tuning = 0.0
self.tuner.set(tuning)
self.cb(spectrum, tuning)
def continuous_unwrap(last_phase, last_phase_unwrapped, p):