-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdvbt_decoder.py
executable file
·98 lines (48 loc) · 2.14 KB
/
dvbt_decoder.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import struct
import components
import argparse
import logging
class DVBTDecoder(object):
def __init__(self, rate):
self.rate = rate
self.iq_data = None
self.m2ts_byte_string = None
def run(self, file_):
self._get_iq_data(file_)
data_carriers, super_frame_start = components.run_dsp(self.iq_data)
demultiplex_bits = components.inner_processing(data_carriers,
super_frame_start)
vit_decoded = components.viterbi_decoder(demultiplex_bits, self.rate)
self.m2ts_byte_string = components.outer_processing(vit_decoded,
super_frame_start,
self.rate)
return self.m2ts_byte_string
def read(self):
return self.m2ts_byte_string
def _get_iq_data(self, file_):
indata = file_.read()
self.num_samples = len(indata)/4
data = struct.unpack('%ih' %(2*self.num_samples), indata)
data = np.array(data,'int16')
self.iq_data = data[0:2*self.num_samples:2] + \
1j*data[1:2*self.num_samples:2]
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument("filename", help="name of file containing iq data")
parser.add_argument("--verbose", help="increase output verbosity",
action="store_true")
args = parser.parse_args()
if args.verbose:
print "Verbosity turned on"
logging.basicConfig(level=logging.DEBUG)
in_file = open(args.filename, 'rb')
dvbt_decoder = DVBTDecoder(rate=(2,3))
m2ts_byte_string = dvbt_decoder.run(in_file)
out_filename = 'dvbt_decoder_output.m2ts'
out_file = open(out_filename,'wb')
out_file.write(m2ts_byte_string)
in_file.close()
out_file.close()