aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-15 19:54:25 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-15 19:54:25 +0200
commit9700ab0038fb3988ea7a95526c4490a4ef1afc60 (patch)
tree136c3f0f27023359963128fff2bac88dacfe78a1
parent4976e2ba8d4223d740228bf8aee4340ff3f4a7ef (diff)
downloadodr-dab-cir-9700ab0038fb3988ea7a95526c4490a4ef1afc60.tar.gz
odr-dab-cir-9700ab0038fb3988ea7a95526c4490a4ef1afc60.tar.bz2
odr-dab-cir-9700ab0038fb3988ea7a95526c4490a4ef1afc60.zip
Add hackrf format converter
-rwxr-xr-xautocorrelate_window.py44
1 files 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] <filename>")
+ 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()