display detected beat frequency
This commit is contained in:
parent
efc7ca9e32
commit
8b90d7395b
4
dmi.py
4
dmi.py
|
@ -19,8 +19,8 @@ def main():
|
||||||
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
|
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
|
||||||
induction.start()
|
induction.start()
|
||||||
try:
|
try:
|
||||||
def stabilizer_cb(spectrum, tuning):
|
def stabilizer_cb(spectrum, peak_freq, tuning):
|
||||||
gui.update_beat_spectrum(spectrum)
|
gui.update_beat_spectrum(spectrum, peak_freq)
|
||||||
induction.set(tuning)
|
induction.set(tuning)
|
||||||
|
|
||||||
stabilizer = Stabilizer(block_size, 80.0, 1088.1e6 - freq_base, 10e-6, stabilizer_cb)
|
stabilizer = Stabilizer(block_size, 80.0, 1088.1e6 - freq_base, 10e-6, stabilizer_cb)
|
||||||
|
|
4
gui.py
4
gui.py
|
@ -54,8 +54,8 @@ class GUI:
|
||||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"),
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"),
|
||||||
str(freq_sample), str(freq_base), str(block_size)])
|
str(freq_sample), str(freq_base), str(block_size)])
|
||||||
|
|
||||||
def update_beat_spectrum(self, data):
|
def update_beat_spectrum(self, block, peak_freq):
|
||||||
obj = {"action": "update_beat_spectrum", "data": data}
|
obj = {"action": "update_beat_spectrum", "block": block, "peak_freq": peak_freq}
|
||||||
self.impl.write_pyon(obj)
|
self.impl.write_pyon(obj)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
53
gui_impl.py
53
gui_impl.py
|
@ -10,30 +10,49 @@ from sipyco.pipe_ipc import AsyncioChildComm
|
||||||
from sipyco import pyon
|
from sipyco import pyon
|
||||||
|
|
||||||
|
|
||||||
class SpectrogramWidget(pg.PlotWidget):
|
class SpectrogramItem(pg.ImageItem):
|
||||||
def __init__(self, freq_sample, freq_base, block_size):
|
def __init__(self, freq_sample, freq_base, block_size):
|
||||||
super(SpectrogramWidget, self).__init__()
|
pg.ImageItem.__init__(self)
|
||||||
|
|
||||||
depth = 100
|
depth = 100
|
||||||
self.img_array = np.zeros((depth, block_size))
|
self.img_array = np.zeros((depth, block_size))
|
||||||
|
|
||||||
self.img = pg.ImageItem()
|
self.setImage(self.img_array, autoLevels=True)
|
||||||
self.addItem(self.img)
|
|
||||||
|
|
||||||
self.img.setImage(self.img_array, autoLevels=True)
|
|
||||||
|
|
||||||
pos = np.array([0., 1., 0.5, 0.25, 0.75])
|
pos = np.array([0., 1., 0.5, 0.25, 0.75])
|
||||||
color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 255), (255, 0, 0, 255)], dtype=np.ubyte)
|
color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 255), (255, 0, 0, 255)], dtype=np.ubyte)
|
||||||
cmap = pg.ColorMap(pos, color)
|
cmap = pg.ColorMap(pos, color)
|
||||||
lut = cmap.getLookupTable(0.0, 1.0, 256)
|
lut = cmap.getLookupTable(0.0, 1.0, 256)
|
||||||
self.img.setLookupTable(lut)
|
self.setLookupTable(lut)
|
||||||
|
|
||||||
self.img.setRect(QtCore.QRectF(0.0, freq_base-freq_sample/2, float(depth), freq_sample))
|
self.setRect(QtCore.QRectF(0.0, (freq_base-freq_sample/2)/1e6, float(depth), freq_sample/1e6))
|
||||||
|
|
||||||
def update(self, block):
|
def add_block(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:] = np.fft.fftshift(block)
|
self.img_array[-1:] = np.fft.fftshift(block)
|
||||||
self.img.setImage(self.img_array, autoLevels=True)
|
self.setImage(self.img_array, autoLevels=True)
|
||||||
|
|
||||||
|
|
||||||
|
class MainWindow(pg.GraphicsWindow):
|
||||||
|
def __init__(self, freq_sample, freq_base, block_size):
|
||||||
|
pg.GraphicsWindow.__init__(self)
|
||||||
|
self.setWindowTitle("NOPTICA Wavemeter")
|
||||||
|
|
||||||
|
self.freq_sample = freq_sample
|
||||||
|
self.freq_base = freq_base
|
||||||
|
|
||||||
|
self.text = pg.LabelItem()
|
||||||
|
self.addItem(self.text)
|
||||||
|
|
||||||
|
p1 = self.addPlot(row=1, col=0)
|
||||||
|
self.beat_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
||||||
|
p1.addItem(self.beat_spectrum)
|
||||||
|
|
||||||
|
def update_params(self, peak_freq):
|
||||||
|
if peak_freq is None:
|
||||||
|
self.text.setText("REF: NO BEAT")
|
||||||
|
else:
|
||||||
|
self.text.setText("REF: {:.3f}MHz".format((self.freq_base + self.freq_sample*peak_freq)/1e6))
|
||||||
|
|
||||||
|
|
||||||
class IPCClient(AsyncioChildComm):
|
class IPCClient(AsyncioChildComm):
|
||||||
|
@ -44,13 +63,14 @@ class IPCClient(AsyncioChildComm):
|
||||||
line = await self.readline()
|
line = await self.readline()
|
||||||
return pyon.decode(line.decode())
|
return pyon.decode(line.decode())
|
||||||
|
|
||||||
async def listen(self, spectrogram):
|
async def listen(self, main_window):
|
||||||
while True:
|
while True:
|
||||||
obj = await self.read_pyon()
|
obj = await self.read_pyon()
|
||||||
try:
|
try:
|
||||||
action = obj["action"]
|
action = obj["action"]
|
||||||
if action == "update_beat_spectrum":
|
if action == "update_beat_spectrum":
|
||||||
spectrogram.update(obj["data"])
|
main_window.beat_spectrum.add_block(obj["block"])
|
||||||
|
main_window.update_params(obj["peak_freq"])
|
||||||
if action == "terminate":
|
if action == "terminate":
|
||||||
self.close_cb()
|
self.close_cb()
|
||||||
return
|
return
|
||||||
|
@ -73,11 +93,10 @@ def main():
|
||||||
ipc = IPCClient(os.getenv("NOPTICA2_IPC"))
|
ipc = IPCClient(os.getenv("NOPTICA2_IPC"))
|
||||||
loop.run_until_complete(ipc.connect())
|
loop.run_until_complete(ipc.connect())
|
||||||
try:
|
try:
|
||||||
main_widget = SpectrogramWidget(freq_sample, freq_base, block_size)
|
main_window = MainWindow(freq_sample, freq_base, block_size)
|
||||||
main_widget.setWindowTitle("NOPTICA Wavemeter")
|
main_window.show()
|
||||||
main_widget.show()
|
ipc.set_close_cb(main_window.close)
|
||||||
ipc.set_close_cb(main_widget.close)
|
asyncio.ensure_future(ipc.listen(main_window))
|
||||||
asyncio.ensure_future(ipc.listen(main_widget))
|
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
finally:
|
finally:
|
||||||
ipc.close()
|
ipc.close()
|
||||||
|
|
|
@ -116,14 +116,15 @@ class Stabilizer:
|
||||||
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))))
|
||||||
i = np.argmax(spectrum)
|
i = np.argmax(spectrum)
|
||||||
freq = self.freqs[i]
|
|
||||||
amplitude = spectrum[i]
|
amplitude = spectrum[i]
|
||||||
|
|
||||||
if amplitude > self.amp_threshold:
|
if amplitude > self.amp_threshold:
|
||||||
|
freq = self.freqs[i]
|
||||||
tuning = (freq - self.freq_target)*self.k
|
tuning = (freq - self.freq_target)*self.k
|
||||||
else:
|
else:
|
||||||
|
freq = None
|
||||||
tuning = 0.0
|
tuning = 0.0
|
||||||
self.cb(spectrum, tuning)
|
self.cb(spectrum, freq, tuning)
|
||||||
|
|
||||||
|
|
||||||
def continuous_unwrap(last_phase, last_phase_unwrapped, p):
|
def continuous_unwrap(last_phase, last_phase_unwrapped, p):
|
||||||
|
|
Loading…
Reference in New Issue