-
Notifications
You must be signed in to change notification settings - Fork 1
/
dwim.py
82 lines (61 loc) · 2.15 KB
/
dwim.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import iq
import find_start
import auto_correlate
import correlate
import make_prs
import sys
import parameters
import numpy
import os
import getopt
import matplotlib.pyplot as plt
options, remainder = getopt.getopt(sys.argv[1:], 'r:f:', [
'rate=',
'format=',
])
sample_rate = 2000000
sample_type = 'c32'
for opt, arg in options:
if opt in ('-r', '--rate'):
sample_rate = int(arg)
if opt in ('-f', '--format'):
sample_type = arg
dp = parameters.dab_parameters(1, sample_rate)
prs = make_prs.modulate_prs(sample_rate, True)
frame_length = int(sample_rate * 96e-3)
f = open(remainder[0], "rb")
reader = iq.IQReader(f, sample_type)
signal, sample_offset = reader.read(count=frame_length)
start = find_start.find_start(signal, sample_rate)
signal = signal[start:]
sample_offset += start
fine_freq_offset = auto_correlate.auto_correlate(signal, dp, sample_rate)
start, rough_freq_offset = correlate.find_rough_freq_offset(signal, -fine_freq_offset, prs, dp, sample_rate)
signal = signal[start:]
sample_offset += start
freq_offset = rough_freq_offset - fine_freq_offset
shift_signal = numpy.exp(complex(0,-1)*numpy.arange(len(signal))*2*numpy.pi*freq_offset/float(sample_rate))
signal = signal * shift_signal
iq.write("/tmp/bar.cfile", signal)
print start
reader.skip(sample_offset)
prs_len=len(prs)
shift_signal = numpy.exp(complex(0,-1)*numpy.arange(prs_len)*2*numpy.pi*freq_offset/float(sample_rate))
print len(signal), frame_length
sample_offset = 0
prev_start = 0
starts = []
while True:
signal, sample_offset = reader.read(count=prs_len)
if len(signal)!=prs_len: break
signal = signal * shift_signal
relative_start, cor, phase = correlate.estimate_prs_fine(signal[:len(prs)], prs)
print relative_start
start = sample_offset + relative_start
if prev_start: starts.append(start - prev_start)
print start - prev_start
prev_start = start
offset = frame_length-prs_len+1*int(relative_start+0.5)
reader.skip(offset)
plt.plot(starts)
plt.show()