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
|
#!/usr/bin/env python
import sys
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import butter, lfilter, freqz
import matplotlib.pyplot as plt
samp_rate = 10000
input_rate = 1000
assert(samp_rate % input_rate == 0)
rf_to_baseband_sample_ratio = samp_rate // input_rate;
L = 200
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False)
return b, a
def butter_lowpass_filter(data, cutoff, fs, order=6):
b, a = butter_lowpass(cutoff, fs, order=order)
return lfilter(b, a, data)
debug_pd = np.loadtxt("debug-pd.csv", delimiter=",")
sample, slope, pd, pdslope = np.split(debug_pd, 4, 1)
debug_dds = np.loadtxt("debug-dds.csv", delimiter=",")
dds_ix, dds_phase, dds_phase_delta, dds_phase_idx_i, dds_phase_idx_q = np.split(debug_dds, 5, 1)
out = np.fromfile("debug-out.i8", dtype="i1")
out_r, out_g = np.split(np.reshape(out, newshape=(out.shape[0]//2, 2)), 2, 1)
L_out = L * rf_to_baseband_sample_ratio
plt.figure()
plt.subplot(3, 1, 1)
plt.title("sample")
plt.plot(sample[0:L])
plt.subplot(3, 1, 2)
plt.title("pd")
plt.plot(pd[0:L])
plt.subplot(3, 1, 3)
plt.title("pdslope")
plt.plot(pdslope[0:L])
plt.figure()
plt.subplot(4, 1, 1)
plt.title("dds ix")
plt.plot(dds_ix[0:L_out])
plt.subplot(4, 1, 2)
plt.title("dds phase")
plt.plot(dds_phase[0:L_out])
plt.subplot(4, 1, 3)
plt.title("dds phase_delta")
plt.plot(dds_phase_delta[0:L_out])
plt.subplot(4, 1, 4)
plt.title("output")
plt.plot(out_r[0:L_out])
plt.plot(out_g[0:L_out])
plt.figure()
plt.subplot(2, 1, 1)
plt.title("out sum")
out_sum = out_r[0:L_out].astype(float) + out_g[0:L_out].astype(float)
plt.plot(out_sum)
plt.subplot(2, 1, 2)
plt.title("out sum filt")
plt.plot(butter_lowpass_filter(out_sum, cutoff=10, fs=2000))
plt.show()
|