noptica2-sdr/stabilize.py

48 lines
1.5 KiB
Python
Raw Normal View History

import SoapySDR
import numpy as np
from scipy.signal import blackmanharris
2020-01-05 19:31:07 +08:00
2020-01-11 16:06:54 +08:00
from stabilizer import InductionHeater, Stabilizer
2020-01-05 19:31:07 +08:00
def main():
2020-01-11 16:06:54 +08:00
freq_sample = 5e6
freq_base = 1086e6
2020-01-05 19:31:07 +08:00
induction = InductionHeater("/dev/ttyUSB0", 430e3, 445e3)
induction.start()
try:
2020-01-11 16:06:54 +08:00
stabilizer = Stabilizer(freq_sample, 0.4, 1088.3e6 - freq_base, 200e-6, induction)
2020-01-05 19:31:07 +08:00
2020-01-11 16:06:54 +08:00
sdr = SoapySDR.Device()
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, 0, freq_sample)
2020-01-05 19:31:07 +08:00
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, 0, base_freq)
2020-01-11 16:06:54 +08:00
samples = np.array([0]*4096, np.complex64)
rx_stream = sdr.setupStream(SoapySDR.SOAPY_SDR_RX, SoapySDR.SOAPY_SDR_CF32)
2020-01-05 19:31:07 +08:00
try:
2020-01-11 16:06:54 +08:00
sdr.activateStream(rx_stream)
try:
# We can't update faster than the MHS5200A serial interface
stabilizer_throttle = 0
while True:
sr = sdr.readStream(rx_stream, [samples], len(samples))
if sr.ret != len(samples):
print("SDR sampling error")
return
stabilizer_throttle += 1
if stabilizer_throttle == 30:
stabilizer.input(samples)
stabilizer_throttle = 0
finally:
sdr.deactivateStream(rx_stream)
2020-01-05 19:31:07 +08:00
finally:
2020-01-11 16:06:54 +08:00
sdr.closeStream(rx_stream)
2020-01-05 19:31:07 +08:00
finally:
induction.stop()
if __name__ == "__main__":
main()