-
Notifications
You must be signed in to change notification settings - Fork 97
/
atsc-b200.py
executable file
·85 lines (71 loc) · 2.84 KB
/
atsc-b200.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
#!/usr/bin/env /usr/bin/python
# Copyright 2013-2014 Clayton Smith ([email protected])
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 program. If not, see <http://www.gnu.org/licenses/>.
from gnuradio import gr, atsc, blocks, analog, digital, filter, uhd
from gnuradio.filter import firdes
from grc_gnuradio import blks2 as grc_blks2
import sys, os
import osmosdr
def main(args):
nargs = len(args)
if nargs == 1:
port = int(args[0])
outfile = None
elif nargs == 2:
port = int(args[0])
outfile = args[1]
else:
sys.stderr.write("Usage: atsc-blade.py port [output_file]\n");
sys.exit(1)
symbol_rate = 4500000.0 / 286 * 684
pilot_freq = 309441
center_freq = 441000000
tx_gain = 83 # max 89.5
tb = gr.top_block()
out = uhd.usrp_sink(
device_addr="recv_frame_size=65536,num_recv_frames=128,send_frame_size=65536,num_send_frames=128,master_clock_rate=" + str(symbol_rate*4),
stream_args=uhd.stream_args(
cpu_format="fc32",
otw_format="sc16",
channels=range(1),
),
)
out.set_samp_rate(symbol_rate)
out.set_center_freq(center_freq, 0)
out.set_gain(tx_gain, 0)
#src = blocks.udp_source(gr.sizeof_char*1, "127.0.0.1", port, 18800, True)
src = grc_blks2.tcp_source(gr.sizeof_char*1, "127.0.0.1", port, True)
pad = atsc.pad()
rand = atsc.randomizer()
rs_enc = atsc.rs_encoder()
inter = atsc.interleaver()
trell = atsc.trellis_encoder()
fsm = atsc.field_sync_mux()
v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
mix = blocks.multiply_vcc(1)
rrc = filter.fft_filter_ccc(1, firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate/2, 0.1152, 100))
tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
tb.connect((c2sym, 0), (mix, 0))
tb.connect((offset, 0), (mix, 1))
tb.connect(mix, rrc, out)
if outfile:
dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
tb.connect(rrc, dst)
tb.run()
if __name__ == '__main__':
main(sys.argv[1:])