From 9700ab0038fb3988ea7a95526c4490a4ef1afc60 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 15 Aug 2015 19:54:25 +0200 Subject: Add hackrf format converter --- autocorrelate_window.py | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/autocorrelate_window.py b/autocorrelate_window.py index c97f7fb..cf69a77 100755 --- a/autocorrelate_window.py +++ b/autocorrelate_window.py @@ -3,17 +3,37 @@ # Do a set of autocorrelations over the test.16.14.25.iq file # # Licence: see LICENCE file +# +# hackrf_transfer example: +# hackrf_transfer -r hackrf_dab.iq -f 211648000 -s 8 -n 768000 import numpy as np import matplotlib.pyplot as pp +import sys + +if len(sys.argv) != 3: + print("Usage") + print(" script [f64|u8] ") + print(" fc64: file is 32-bit float I + 32-bit float Q") + print(" u8: file is 8-bit unsigned I + 8-bit unsigned Q") + sys.exit(1) -file_in = "test.16.14.25.iq" +file_in = sys.argv[2] -channel_out = np.fromfile(file_in, np.complex64) +if sys.argv[1] == "u8": + channel_out1 = np.fromfile(file_in, np.uint8) + print("Convert u8 IQ to fc64 IQ") + channel_out2 = channel_out1.reshape(2, len(channel_out1)/2) + channel_out3 = channel_out2[0,...] + 1j * channel_out2[1,...] + channel_out = channel_out3.astype(np.complex64) / 256.0 - (0.5+0.5j) +elif sys.argv[1] == "fc64": + channel_out = np.fromfile(file_in, np.complex64) + +channel_out = channel_out[:channel_out.size / 4] print("Autocorrelating") -correlationlength = 50 +correlationlength = 500 def autocorrelate(x, length): return np.array([1] + [np.abs(np.corrcoef(x[:-i], x[i:])[0,1]) for i in range(1, length)]) @@ -21,23 +41,37 @@ def autocorrelate(x, length): reshape_width = correlationlength * 4 -channel_out_truncated = channel_out[:-(channel_out.size % reshape_width)] +channel_out_truncated = channel_out[:channel_out.size - (channel_out.size % reshape_width)] channel_out_reshaped = channel_out_truncated.reshape(channel_out_truncated.size / reshape_width, reshape_width) channel_autocorr_image = np.zeros((channel_out_reshaped.shape[0], correlationlength)) + +num_windows = len(channel_out_reshaped) + for i, window in enumerate(channel_out_reshaped): if i % 100 == 0: - print("Window {}".format(i)) + print("Window {}/{}".format(i, num_windows)) channel_autocorr_image[i] = autocorrelate(window, correlationlength) rows, cols = channel_autocorr_image.shape +print("Shape: {}x{}".format(rows, cols)) + aspect_ratio = 1.0 fig = pp.figure() ax = fig.add_subplot(111) hi = ax.imshow(channel_autocorr_image, cmap='hot', aspect=aspect_ratio*(cols/rows)) +fig2 = pp.figure() +ax = fig2.add_subplot(211) +accumulated0 = channel_autocorr_image.sum(axis=0) +ac1 = ax.plot(accumulated0) + +ax = fig2.add_subplot(212) +accumulated1 = channel_autocorr_image.sum(axis=1) +ac1 = ax.plot(accumulated1) + pp.show() -- cgit v1.2.3