-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcompute_error_rate.py
35 lines (28 loc) · 1.22 KB
/
compute_error_rate.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
import sys
if len(sys.argv) != 3:
print("Usage: python3 compute_error_rate.py encoded_file decoded_file")
sys.exit(1)
encoded_file = sys.argv[1]
decoded_file = sys.argv[2]
with open(encoded_file) as f:
encoded_codewords = [l.rstrip('\n') for l in f.readlines()]
with open(decoded_file) as f:
decoded_codewords = [l.rstrip('\n') for l in f.readlines()]
assert len(encoded_codewords) == len(decoded_codewords)
len_codeword = len(encoded_codewords[0])
for i in range(len(encoded_codewords)):
assert len(encoded_codewords[i]) == len_codeword
assert len(decoded_codewords[i]) == len_codeword
print('Number of codewords:', len(decoded_codewords))
print('Codeword length:', len_codeword)
bit_errors_total = 0
block_errors_total = 0
total_length = 0
for encoded_codeword, decoded_codeword in zip(encoded_codewords,decoded_codewords):
bit_errors = sum([encoded_codeword[i] != decoded_codeword[i] for i in range(len(decoded_codeword))])
if bit_errors != 0:
block_errors_total += 1
bit_errors_total += bit_errors
total_length += len(decoded_codeword)
print('Bit error rate:','%.2f%%'%((bit_errors_total/total_length)*100))
print('Block error rate:','%.2f%%'%((block_errors_total/len(decoded_codewords))*100))