diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-29 20:34:07 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-29 20:34:07 +0200 |
commit | 52c378b59ed4920fc4805fe9154fe49bf912cc46 (patch) | |
tree | 8293098695dcf3754ef9344487693b5928f1b1f1 /correlate_with_ref.py | |
parent | 1e625548ad55d73be527c028c89ccd81163766af (diff) | |
download | odr-dab-cir-52c378b59ed4920fc4805fe9154fe49bf912cc46.tar.gz odr-dab-cir-52c378b59ed4920fc4805fe9154fe49bf912cc46.tar.bz2 odr-dab-cir-52c378b59ed4920fc4805fe9154fe49bf912cc46.zip |
Switch from rtl_sdr to rtl_tcp
This permits the rtlsdr to stream permanently, apparently
the start/stop cycles of rtl_sdr freak out my rtlsdr after
a while
Diffstat (limited to 'correlate_with_ref.py')
-rwxr-xr-x | correlate_with_ref.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/correlate_with_ref.py b/correlate_with_ref.py index ab55682..23c9c5c 100755 --- a/correlate_with_ref.py +++ b/correlate_with_ref.py @@ -33,13 +33,27 @@ T_NULL = 2656 T_TF = 196608 class CIR_Correlate: - def __init__(self, iq_filename, iq_format): - """Read phase reference from fixed file and load IQ data from - iq_filename. iq_format must be fc64 or u8""" + def __init__(self, iq_filename="", iq_format=None, iq_data=None): + """Either call with iq_filename, or with iq_data containing + a np.array with the data. + + This class will then read phase reference from fixed file and + load IQ data from iq_filename, or use iq_data directly. + + iq_format must be fc64 or u8""" + + if iq_format is None: + raise ValueError("Incorrect initialisation") + self.phase_ref = np.fromfile("phasereference.2048000.fc64.iq", np.complex64) if iq_format == "u8": - channel_u8_interleaved = np.fromfile(iq_filename, np.uint8) + if iq_filename: + channel_u8_interleaved = np.fromfile(iq_filename, np.uint8) + elif iq_data is not None: + channel_u8_interleaved = iq_data + else: + raise ValueError("Must give iq_filename or iq_data") channel_u8_iq = channel_u8_interleaved.reshape(int(len(channel_u8_interleaved)/2), 2) # This directly converts to fc64 channel_fc64_unscaled = channel_u8_iq[...,0] + np.complex64(1j) * channel_u8_iq[...,1] @@ -47,7 +61,12 @@ class CIR_Correlate: channel_fc64_dc_comp = channel_fc64_scaled - np.average(channel_fc64_scaled) self.channel_out = channel_fc64_dc_comp elif iq_format == "fc64": - self.channel_out = np.fromfile(iq_filename, np.complex64) + if iq_filename: + self.channel_out = np.fromfile(iq_filename, np.complex64) + elif iq_data is not None: + self.channel_out = iq_data + else: + raise ValueError("Must give iq_filename or iq_data") else: raise ValueError("Unsupported format {}".format(iq_format)) |