forked from tapparelj/gr-lora_sdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qa_mu_demod.py
executable file
·351 lines (251 loc) · 10.7 KB
/
qa_mu_demod.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2020 <+YOU OR YOUR COMPANY+>.
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
import lora_sdr_swig as lora_sdr
import numpy as np
from mu_demod import mu_demod
from scipy.special import i0
from utils import *
import lora
SF = 7
N = 2**SF
Ki = N
Ku = 1
R = 8
class qa_mu_demod(gr_unittest.TestCase):
def setUp (self):
pass
def tearDown (self):
pass
def _feed_system(self, stream, SF=SF, R=1, Nsyms=1):
tb = gr.top_block()
detector = lora_sdr.mu_detection( SF, R,-14)
synchronizer = lora_sdr.mu_synchro(SF, R, Nsyms)
demod = mu_demod(SF, Ku)
sink_u1 = blocks.vector_sink_s()
sink_u2 = blocks.vector_sink_s()
sink_snr = blocks.vector_sink_f()
source = blocks.vector_source_c(gr_cast(stream))
tb.connect(source, detector)
tb.connect(detector, synchronizer)
tb.connect(synchronizer, demod)
tb.connect((demod, 0), sink_u1)
tb.connect((demod, 1), sink_u2)
tb.connect((demod, 2), sink_snr)
tb.run()
S1 = sink_u1.data()
S2 = sink_u2.data()
tb.stop()
tb = None
return (S1, S2)
def test_001_system_su(self):
print("test_001_system_su")
R = 8
S1 = (0, 10, 20, 30, 40, 50, 60, 70)
x = np.concatenate([lora.gen_packet(SF, S1, R=R), np.zeros(15*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(len(S2_out), 0)
def test_002_system_su_cfo(self):
print("test_002_system_su_cfo")
R = 8
S1 = (0, 10, 20, 30, 40, 50, 60, 70, 80)
cfo = 10.5 # Should trigger an integer offset of 1 in the detection bock
x = np.concatenate([lora.gen_packet(SF, S1, R=R), np.zeros(15*N*R)])
x = lora.add_cfo(SF, x, cfo, R=R)
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(len(S2_out), 0)
def test_003_system_su_sto(self):
print("test_003_system_su_sto")
R = 8
S1 = (0, 10, 20, 30, 40, 50, 60, 70, 80)
tau = 30.5
tau_samples = int(round(tau*R))
x = np.concatenate([np.zeros(tau_samples), lora.gen_packet(SF, S1, R=R), np.zeros(15*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(len(S2_out), 0)
def test_004_system_su_powers(self):
print("test_004_system_su_powers")
R = 8
S1 = (0, 10, 20, 30, 40, 50, 60, 70, 80)
theta_u = np.pi/4
P1 = [0, 1, 2, 3, 4, 6, 20] # TODO more powers
for P in P1:
P_lin = 10**(P/10.0)
x = np.sqrt(P_lin) * np.exp(1j*theta_u) * np.concatenate([lora.gen_packet(SF, S1, R=R), np.zeros(15*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(len(S2_out), 0)
theta_u += np.pi/4
def test_005_system_su_twice(self):
print("test_005_system_su_twice")
R = 8
S1 = (0, 10, 20, 30, 40, 50, 60, 70, 80)
p = lora.gen_packet(SF, S1, R=R)
n_z = 6*N*R + 3*N/4*R
x = np.concatenate([p, np.zeros(n_z), p, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1 * 2, S1_out)
self.assertEqual(len(S2_out), 0)
def test_010_system_mu_sync(self):
print("test_010_system_mu_sync")
P1_dB = 0
P2_dB = 3
R = 8
tau = int(14.0*R*N)
R = 8
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 2
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 2
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_011_system_mu_STOint_quarter_overlap(self):
print("test_011_system_mu_STOint_quarter_overlap")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 17*R)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_012_system_mu_STOint_quarter_inside(self):
print("test_012_system_mu_STOint_quarter_inside")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 56*R)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_013_system_mu_STOint_0(self):
print("test_013_system_mu_STOint_0")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 0*R)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_014_system_mu_STOint_32(self):
print("test_014_system_mu_STOint_32")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 96*R)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_015_system_mu_STOfrac_quarter_inside(self): #very unstable can work or not between tw0 consecutive executions
print("test_015_system_mu_STOfrac_quarter_inside")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 32*R+1)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([np.zeros(0),p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2,np.zeros(0)])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def test_016_system_mu_STOfrac_quarter_overlap(self):
print("test_016_system_mu_STOfrac_quarter_overlap")
self.maxDiff = None
P1_dB = -10 #too high power leads to false detection
P2_dB = -7
R = 8
tau = int(15*R*N + 17*R+3)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([np.zeros(6),p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2,np.zeros(6)])
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
def system_mu(self, STO, CFO):
print "test_system_mu ", STO, CFO
self.maxDiff = None
P1_dB = -12 #too high power leads to false detection
P2_dB = -9
tau = int(15*R*N + STO*R)
S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3
S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3
p1 = lora.gen_packet(SF, S1, R=R)
p2 = lora.gen_packet(SF, S2, R=R)
x1 = np.sqrt(10**(P1_dB/10.0)) * np.concatenate([np.zeros(0),p1, np.zeros(tau)])
x2 = np.sqrt(10**(P2_dB/10.0)) * np.concatenate([np.zeros(tau), p2,np.zeros(0)])
x2 = lora.add_cfo(SF, x2, CFO, R=R)
x = np.concatenate([x1 + x2, np.zeros(20*N*R)])
S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1))
self.assertEqual(S1, S1_out)
self.assertEqual(S2, S2_out)
if __name__ == '__main__':
#import os
#print 'Blocked waiting for GDB attach (pid = %d)' % (os.getpid(),)
#raw_input ('Press Enter to continue: ')
gr_unittest.run(qa_mu_demod, "qa_mu_demod.xml")