aboutsummaryrefslogtreecommitdiffstats
path: root/autocorrelate_window.py
blob: c97f7fb0081f4443d75dae4844304a935121ca86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
#
# Do a set of autocorrelations over the test.16.14.25.iq file
#
# Licence: see LICENCE file

import numpy as np
import matplotlib.pyplot as pp

file_in = "test.16.14.25.iq"

channel_out = np.fromfile(file_in, np.complex64)

print("Autocorrelating")

correlationlength = 50

def autocorrelate(x, length):
    return np.array([1] + [np.abs(np.corrcoef(x[:-i], x[i:])[0,1]) for i in range(1, length)])


reshape_width = correlationlength * 4

channel_out_truncated = channel_out[:-(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))
for i, window in enumerate(channel_out_reshaped):
    if i % 100 == 0:
        print("Window {}".format(i))
    channel_autocorr_image[i] = autocorrelate(window, correlationlength)

rows, cols = channel_autocorr_image.shape

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))

pp.show()