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

25
gui.py
View File

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

View File

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

View File

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