-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathft8_benchmark.py
More file actions
572 lines (470 loc) · 32.6 KB
/
Copy pathft8_benchmark.py
File metadata and controls
572 lines (470 loc) · 32.6 KB
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#!/usr/bin/python
# ft8_benchmak.py, a simple traffic generator for benchmarking your FT8 hardware
# 2022, Guenael Jouchet (VA2GKA)
#
# Based on https://github.com/rtmrtmrtmrtm/weakmon/blob/master/ft8.py by Robert Morris, AB1HL
# Same MIT license used here
import os, sys, re, math, time, string, random, getopt
import numpy as np
import simpleaudio as sa
import wave
# FT8 modulation and protocol ==
# 6.25 Hz spacing
# 0.16 seconds/symbol
# 79 FSK-8 symbols
# 12.64 seconds total transmission time
# Encoding ==
# Message = 77 bits
# CRC += 14 bits (= 91 bits)
# LDPC(174,91) (= 174 bits)
# = 58 symbols using FSK-8 (3-bits)
# gray code each 3 bits
# insert three 7-symbol Costas sync arrays
# at symbol #s 0, 36, 72 of final signal
# final 79 FSK-8 symbols
class FT8:
def __init__(self):
# Read the prefix table (fixed format 2 chars only !!)
self.prefix = self.read_prefix("prefix.txt")
# Default values
self.iter = 240
self.num_sig = 35
self.sampling_rate = 8000
self.low_freq = 300
self.high_freq = 2800
self.power_range = 4
self.delay_range = 0.3
self.writetofile = False
self.skip_sync = False
self.filename = "benchmark.wav"
self.debug = False
pass
def crc(self, msg, div, code=None):
"""Cyclic Redundancy Check
Generates an error detecting code based on an inputted message
and divisor in the form of a polynomial representation.
Arguments:
msg: The input message of which to generate the output code.
div: The divisor in polynomial form. For example, if the polynomial
of x^3 + x + 1 is given, this should be represented as '1011' in
the div argument.
code: This is an option argument where a previously generated code may
be passed in. This can be used to check validity. If the inputted
code produces an outputted code of all zeros, then the message has
no errors.
Returns:
An error-detecting code generated by the message and the given divisor.
"""
# Append the code to the message. If no code is given, default to '000'
if code is None:
code = np.zeros(len(div)-1, dtype=np.int32)
assert len(code) == len(div) - 1
msg = np.append(msg, code)
div = np.array(div, dtype=np.int32)
divlen = len(div)
# Loop over every message bit (minus the appended code)
for i in range(len(msg)-len(code)):
# If that messsage bit is 1, perform modulo 2 multiplication
if msg[i] == 1:
#for j in range(len(div)):
# # Perform modulo 2 multiplication on each index of the divisor
# msg[i+j] = (msg[i+j] + div[j]) % 2
msg[i:i+divlen] = np.mod(msg[i:i+divlen] + div, 2)
# Output the last error-checking code portion of the message generated
return msg[-len(code):]
def ldpc_encode(self, message):
matrix = np.array([[1,0,0,0,0,0,1,1,0,0,1,0,1,0,0,1,1,1,0,0,1,1,1,0,0,0,0,1,0,0,0,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,1,1,0,1,0,1,0,1,1,1,1,0,1,0,1,0,0,0,0,1,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,1,1,0],
[0,1,1,1,0,1,1,0,0,0,0,1,1,1,0,0,0,0,1,0,0,1,1,0,0,1,0,0,1,1,1,0,0,0,1,0,0,1,0,1,1,1,0,0,0,0,1,0,0,1,0,1,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1],
[1,1,0,1,1,1,0,0,0,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,0,0,1,0,0,1,1,1,0,1,1,1,1,1,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,1,0,1,1,1,1,0,1,1,1,0],
[0,0,0,1,1,0,1,1,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,1,0,1,1,0,0,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,1,0,1,0,0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,0,1,0,1,0,0,0,1,1,0,0,1,1,1,1,1,0,1,0,0,0,1,1,1,1,1,0,1,0,0,0,0,1,0,1,1,0],
[0,1,1,0,0,0,0,0,1,0,0,0,1,1,0,0,1,1,0,0,1,0,0,0,0,1,0,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,0,0,0,0,0,0]], dtype=np.int32)
assert len(message) == 91
out = np.zeros(174, dtype=np.int32)
out[0:91] = message
np.dot(matrix, message, out=out[91:])
np.mod(out[91:], 2, out=out[91:])
return out
def gray_code(self, b174):
# gray map for encoding 3-bit chunks of the 174 bits,
graymap = np.array( [ 0, 1, 3, 2, 5, 6, 4, 7 ], dtype=np.int32)
# create 58 3-bit numbers
x = 4*b174[0::3] + 2*b174[1::3] + 1*b174[2::3]
y = graymap[x]
a174 = np.zeros(len(b174), dtype=np.int32)
a174[0::3] = np.bitwise_and(np.right_shift(y, 2), 1)
a174[1::3] = np.bitwise_and(np.right_shift(y, 1), 1)
a174[2::3] = np.bitwise_and(np.right_shift(y, 0), 1)
return a174
# turn an integer into an array of bits (MSB) for packing FT8 messages.
def bv(self, x, n):
a = np.zeros(n, dtype=np.int32)
for i in range(0, n):
a[i] = (x >> (n - i - 1)) & 1
return a
# returns a 28-bit number.
# 28-bit number's high bits correspond to first call sign character.
def packcall(self, call):
c1 = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
c2 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
c3 = "0123456789"
c4 = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# offsets for 28-bit call sign encoding.
NTOKENS = 2063592
MAX22 = 4194304
call = call.strip().upper()
if len(call) > 2 and len(call) < 6 and not call[2].isdigit():
call = " " + call
while len(call) < 6:
call = call + " "
# Must fit this pattern, not hashing !!
if re.search(r'^[A-Z0-9 ][A-Z0-9 ][0-9][A-Z ][A-Z ][A-Z ]$', call) != None:
# c1 c2 c3 c4 c4 c4
x = 0
x += c1.find(call[0])
x *= len(c2)
x += c2.find(call[1])
x *= len(c3)
x += c3.find(call[2])
x *= len(c4)
x += c4.find(call[3])
x *= len(c4)
x += c4.find(call[4])
x *= len(c4)
x += c4.find(call[5])
return x + MAX22 + NTOKENS
def packgrid(self, g):
g = g.strip()
g = g.upper()
if re.match(r'^[A-R][A-R][0-9][0-9]$', g) != None:
x1 = ord(g[0]) - ord('A')
x2 = ord(g[1]) - ord('A')
x3 = ord(g[2]) - ord('0')
x4 = ord(g[3]) - ord('0')
x = 0
x += x1 * 18 * 10 * 10
x += x2 * 10 * 10
x += x3 * 10
x += x4
return x
def pack_CQ(self, call, loc):
# CQ CALL GRID
pk_cq = 2 # CQ = 2
pk_call = self.packcall(call)
pk_loc = self.packgrid(loc)
if pk_cq >= 0 and pk_call >= 0 and pk_loc >= 0:
return np.concatenate([
self.bv(pk_cq, 28),
[ 0 ],
self.bv(pk_call, 28),
[ 0 ],
[ 0 ],
self.bv(pk_loc, 15),
self.bv(1, 3)
])
def make_symbols(self, bits77):
assert len(bits77) == 77
# the CRC-14 polynomial, from wsjt-x's 0x2757, with leading 1 bit.
crc14poly = [ 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 ]
costas_symbols = [ 3, 1, 4, 0, 6, 5, 2 ] # new FT8
cksum = self.crc(np.append(bits77, np.zeros(5, dtype=np.int32)), crc14poly)
a91 = np.zeros(91, dtype=np.int32)
a91[0:77] = bits77
a91[77:91] = cksum
a174 = self.ldpc_encode(a91)
a174 = self.gray_code(a174)
# turn array of 174 bits into 58 3-bit symbols, most significant bit first.
dsymbols = np.zeros(58, dtype=np.int32)
for i in range(0, 58):
ii = i * 3
dsymbols[i] = (a174[ii+0] << 2) | (a174[ii+1]<<1) | (a174[ii+2]<<0)
# insert three 7-symbol Costas arrays.
costas = np.array(costas_symbols, dtype=np.int32)
symbols = np.zeros(79, dtype=np.int32)
symbols[0:7] = costas
symbols[7:36] = dsymbols[0:29]
symbols[36:43] = costas
symbols[43:72] = dsymbols[29:]
symbols[72:] = costas
return symbols
def fsk(self, symbols, hza, spacing, rate, symsamples, phase0=0.0):
# compute frequency for each symbol, in hz[0]..hz[1].
symhz = np.zeros(len(symbols))
for bi in range(0, len(symbols)):
base_hz = hza[0] + (hza[1] - hza[0]) * (bi / float(len(symbols)))
fr = base_hz + (symbols[bi] * spacing)
symhz[bi] = fr
# frequency for each sample.
hzv = np.repeat(symhz, symsamples)
# advance angle for each sample
dtheta = (hzv * 2.0 * np.pi) / float(rate)
# start at pi/2 (so it's a cosine wave),
# and so that (for FT8 &c) FFT phases are zero for
# all symbols when hz is centered on a bin and
# the FFTs start exactly at the start of the signal.
dtheta = np.append([math.pi/2], dtheta[0:-1])
# cumulative angle.
angles = np.cumsum(dtheta)
# start at indicated phase.
angles = angles + phase0
a = np.sin(angles)
return a
def read_prefix(self, filename):
return open(filename).read().splitlines()
def random_prefix(self):
return random.choice(self.prefix)
def random_suffix(self):
LETTER='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
NUM='0123456789'
return random.choice(NUM) + random.choice(LETTER) + random.choice(LETTER) + random.choice(LETTER)
def random_callsign(self):
return self.random_prefix() + self.random_suffix()
def random_loc(self):
L1='ABCDEFGHIJKLMNOPQR'
L2='FGHIJKLMNO'
L3='0123456789'
return random.choice(L1) + random.choice(L2) + random.choice(L3) + random.choice(L3)
def save_wav(self, filename, fs, data):
out = np.asarray([ (elem*(2**15-1.0)) for elem in data ], dtype=np.int16)
with wave.open(filename, "w") as f:
raw = ""
f.setnchannels(1) # one channel
f.setsampwidth(2) # 16-bit audio
f.setframerate(fs) # framerate (ex 48000)
f.setcomptype('NONE','Not Compressed')
f.writeframesraw(out.tobytes())
f.close()
def self_test(self):
# Ref test message
# Message : "CQ K1JT FN20QI"
# Packed data: 00 00 00 20 4d fc dc 8a 14 08
# FSK tones: 3140652000000001005477547106035036373140652547441342116056460065174427143140652
ref = [ 3, 1, 4, 0, 6, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 5, 4, 7, 7,
5, 4, 7, 1, 0, 6, 0, 3, 5, 0, 3, 6, 3, 7, 3, 1, 4, 0, 6, 5, 2, 5,
4, 7, 4, 4, 1, 3, 4, 2, 1, 1, 6, 0, 5, 6, 4, 6, 0, 0, 6, 5, 1, 7,
4, 4, 2, 7, 1, 4, 3, 1, 4, 0, 6, 5, 2]
pack77 = self.pack_CQ("K1JT", "FN20")
symbols = self.make_symbols(pack77)
if np.array_equal(ref, symbols):
print(" == Self-test passed")
else:
print(" == Self-test failed!!")
sys.exit()
def wait_sync(self):
wait = (15.0 - time.time() % 15)
print(f' == Time alignment required, waiting {wait} seconds\n')
time.sleep(wait)
def play_audio(self, fs, data):
out = np.asarray([ (elem*(2**15-1.0)) for elem in data ], dtype=np.int16)
# start playback
audio = sa.play_buffer(out, 1, 2, fs)
# Wait for playback to finish before exiting
audio.wait_done()
def usage(self):
sys.stderr.write("ft8_benchmark, a simple traffic generator for benchmarking your FT8 hardware\n\n")
sys.stderr.write("Basic usage: ft8_benchmark -n <number of signals> -r <sampling frequency>\n")
sys.stderr.write("Options detail:\n")
sys.stderr.write("\t-n <number of signals> [1-100] (default: 35)\n")
sys.stderr.write("\t-i <number of iteration> [1-inf] (default: 240, 1 hour)\n")
sys.stderr.write("\t-r <audio sampling rate> [8000,11025,22050,32000,44100,48000,96000] (default: 8000)\n")
sys.stderr.write("\t-l <lower dial frequency> [10-1000] (default: 300)\n")
sys.stderr.write("\t-h <higher dial frequency> [2000-4000] (default: 2800)\n")
sys.stderr.write("\t-p <power range> [1-10] (defaut: 4), rnd between 1-1/10\n")
sys.stderr.write("\t-d <timing delay> [0.0-1.0] (default: 0.3) : Random delay added\n")
sys.stderr.write("\t-w <filename> : Write output to file\n")
sys.stderr.write("Other options (without argument):\n")
sys.stderr.write("\t-h / --help : Show list of options\n")
sys.stderr.write("\t-v / --version : Show version of program\n")
sys.stderr.write("\t-t / --timeskip : Skip the 15 sec time alignment\n")
sys.stderr.write("\t-s / --selftest : Self-test validation\n")
sys.stderr.write("\t-x / --debug : Debug / Log messages\n")
sys.stderr.write("Example:\n")
sys.stderr.write("\tpython ft8_benchmark.py -n 35 -r 8000 -l 300 -h 2800 -p 4 -w test.wav\n")
if __name__ == '__main__':
ft8 = FT8()
try:
opts, args = getopt.getopt(sys.argv[1:],"hvn:r:l:h:p:i:d:w:tsx",
["help","version","num_sig=","sampling_rate=","low_freq=","high_freq=",
"power_range=","iter=","delay_range=","selftest","write=",
"timeskip","selftest=","debug"])
except getopt.GetoptError:
ft8.usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
ft8.usage()
sys.exit()
if opt in ("-v", "--version"):
sys.stderr.write("v0.1.0\n")
sys.exit()
elif opt in ("-n", "--num_sig"):
value = int(arg)
if value >= 1 and value <= 100:
ft8.num_sig = value
else:
sys.stderr.write("-n / --num_sig should be within 1-100\n")
sys.exit()
elif opt in ("-r", "--sampling_rate"):
value = int(arg)
if value in [8000,11025,22050,32000,44100,48000,96000]:
ft8.sampling_rate = value
else:
sys.stderr.write("-r / --sampling_rate should be one of these standard values\
8000, 11025, 22050, 32000, 44100, 48000, 96000\n")
sys.exit()
# FIXME : [ + 12000, 16000 ]
elif opt in ("-l", "--low_freq"):
value = int(arg)
if value >= 10 and value <= 1000:
ft8.low_freq = value
else:
sys.stderr.write("-l / --low_freq should be within 10-1000\n")
sys.exit()
elif opt in ("-h", "--high_freq"):
value = int(arg)
if value >= 2000 and value <= 4000:
ft8.high_freq = value
else:
sys.stderr.write("-l / --high_freq should be within 2000-4000\n")
sys.exit()
elif opt in ("-p", "--power_range"):
value = int(arg)
if value >= 1 and value <= 10:
ft8.power_range = value
else:
sys.stderr.write("-p / --power_range should be within 1-10\n")
sys.exit()
elif opt in ("-i", "--iter"):
value = int(arg)
if value >= 1:
ft8.iter = value
else:
sys.stderr.write("-i / --iter should be an integer positive\n")
sys.exit()
elif opt in ("-d", "--delay_range"):
value = float(arg)
if value >= 0.0 and value <= 1.0:
ft8.delay_range = value
else:
sys.stderr.write("-p / --delay_range should be within 0.0-1.0\n")
sys.exit()
elif opt in ("-w", "--write"):
ft8.writetofile = True
ft8.skip_sync = True
ft8.filename = arg
elif opt in ("-t", "--timeskip"):
ft8.skip_sync = True
elif opt in ("-s", "--selftest"):
ft8.self_test()
sys.exit()
elif opt in ("-x", "--debug"):
ft8.debug = True
# Main loop
for i in range(ft8.iter):
# Output buffer (14 sec max fixed, no more 1s required to generate signals)
out = np.zeros(14 * ft8.sampling_rate)
# Create all the signal according the parameters
for n in range(0, ft8.num_sig):
# Assemble the message
callsign = ft8.random_callsign()
locator = ft8.random_loc()
msg = ft8.pack_CQ(callsign, locator)
# Calculate the symbols
symbols = ft8.make_symbols(msg)
# Pick a random dial frequency
freq = random.randint(ft8.low_freq, ft8.high_freq)
# Create the tones at this dial frequency
tones = ft8.fsk(symbols, [freq, freq], 6.25, ft8.sampling_rate, int(round(ft8.sampling_rate * 0.16)))
# Attenuate the signal randomly withing the range
tones *= float(1.0 / random.randint(1, ft8.power_range))
# Add a delay to our transmission & add it to the output buffer
offset = random.randint(0, int(ft8.delay_range * ft8.sampling_rate))
out[offset:offset+len(tones)] += tones
if ft8.debug == True:
print(f' == Added: {callsign} - {locator} Freq: {freq} Offset: {offset/ft8.sampling_rate}')
# # Normalise the output buffer (16 bits)
out /= max(abs(out))
if ft8.writetofile == True:
ft8.save_wav(ft8.filename, ft8.sampling_rate, out)
sys.exit(0)
else:
if ft8.skip_sync == False:
ft8.wait_sync()
ft8.play_audio(ft8.sampling_rate, out)