-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive.py
executable file
·216 lines (180 loc) · 9.53 KB
/
receive.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block
# Generated: Thu Aug 25 22:40:16 2016
##################################################
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import osmosdr
import time
class top_block(gr.top_block):
def __init__(self, duration=15, gain=20, hpfcutoff=57585, hpfwidth=1370, lpfcutoff=2240, lpfwidth=1075, qrg=106.1, xlatlpfcutoff=80000, xlatlpfwidth=50000):
gr.top_block.__init__(self, "Top Block")
##################################################
# Parameters
##################################################
self.duration = duration
self.gain = gain
self.hpfcutoff = hpfcutoff
self.hpfwidth = hpfwidth
self.lpfcutoff = lpfcutoff
self.lpfwidth = lpfwidth
self.qrg = qrg
self.xlatlpfcutoff = xlatlpfcutoff
self.xlatlpfwidth = xlatlpfwidth
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 47500
##################################################
# Blocks
##################################################
self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.rtlsdr_source_0.set_sample_rate(1e6)
self.rtlsdr_source_0.set_center_freq(qrg*1e6-150e3, 0)
self.rtlsdr_source_0.set_freq_corr(45, 0)
self.rtlsdr_source_0.set_dc_offset_mode(2, 0)
self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
self.rtlsdr_source_0.set_gain_mode(True, 0)
self.rtlsdr_source_0.set_gain(gain, 0)
self.rtlsdr_source_0.set_if_gain(20, 0)
self.rtlsdr_source_0.set_bb_gain(20, 0)
self.rtlsdr_source_0.set_antenna("", 0)
self.rtlsdr_source_0.set_bandwidth(0, 0)
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
interpolation=475,
decimation=1250,
taps=None,
fractional_bw=None,
)
self.low_pass_filter_1 = filter.fir_filter_ccf(1, firdes.low_pass(
400, 125e3, lpfcutoff, lpfwidth, firdes.WIN_RECTANGULAR, 6.76))
self.high_pass_filter_0 = filter.fir_filter_fff(1, firdes.high_pass(
1, 125e3, hpfcutoff, hpfwidth, firdes.WIN_RECTANGULAR, 6.76))
self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(2, (firdes.low_pass(2,1e6,xlatlpfcutoff,xlatlpfwidth,firdes.WIN_RECTANGULAR)), 150e3, 1e6)
self.blocks_wavfile_sink_0 = blocks.wavfile_sink("waveform.wav", 2, samp_rate, 16)
self.blocks_multiply_xx_1 = blocks.multiply_vff(1)
self.blocks_multiply_xx_0 = blocks.multiply_vff(1)
self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, int(samp_rate*duration))
self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
self.analog_wfm_rcv_0 = analog.wfm_rcv(
quad_rate=500e3,
audio_decimation=4,
)
self.analog_sig_source_x_1 = analog.sig_source_f(125e6, analog.GR_SIN_WAVE, 57e6, 1, 0)
self.analog_sig_source_x_0 = analog.sig_source_f(125e3, analog.GR_COS_WAVE, 57000, 1, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 1))
self.connect((self.analog_wfm_rcv_0, 0), (self.high_pass_filter_0, 0))
self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_wavfile_sink_0, 1))
self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_wavfile_sink_0, 0))
self.connect((self.blocks_float_to_complex_0, 0), (self.low_pass_filter_1, 0))
self.connect((self.blocks_head_0, 0), (self.blocks_complex_to_float_0, 0))
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_float_to_complex_0, 1))
self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_float_to_complex_0, 0))
self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_wfm_rcv_0, 0))
self.connect((self.high_pass_filter_0, 0), (self.blocks_multiply_xx_0, 0))
self.connect((self.high_pass_filter_0, 0), (self.blocks_multiply_xx_1, 0))
self.connect((self.low_pass_filter_1, 0), (self.rational_resampler_xxx_0, 0))
self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_head_0, 0))
self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def get_duration(self):
return self.duration
def set_duration(self, duration):
self.duration = duration
self.blocks_head_0.set_length(int(self.samp_rate*self.duration))
def get_gain(self):
return self.gain
def set_gain(self, gain):
self.gain = gain
self.rtlsdr_source_0.set_gain(self.gain, 0)
def get_hpfcutoff(self):
return self.hpfcutoff
def set_hpfcutoff(self, hpfcutoff):
self.hpfcutoff = hpfcutoff
self.high_pass_filter_0.set_taps(firdes.high_pass(1, 125e3, self.hpfcutoff, self.hpfwidth, firdes.WIN_RECTANGULAR, 6.76))
def get_hpfwidth(self):
return self.hpfwidth
def set_hpfwidth(self, hpfwidth):
self.hpfwidth = hpfwidth
self.high_pass_filter_0.set_taps(firdes.high_pass(1, 125e3, self.hpfcutoff, self.hpfwidth, firdes.WIN_RECTANGULAR, 6.76))
def get_lpfcutoff(self):
return self.lpfcutoff
def set_lpfcutoff(self, lpfcutoff):
self.lpfcutoff = lpfcutoff
self.low_pass_filter_1.set_taps(firdes.low_pass(400, 125e3, self.lpfcutoff, self.lpfwidth, firdes.WIN_RECTANGULAR, 6.76))
def get_lpfwidth(self):
return self.lpfwidth
def set_lpfwidth(self, lpfwidth):
self.lpfwidth = lpfwidth
self.low_pass_filter_1.set_taps(firdes.low_pass(400, 125e3, self.lpfcutoff, self.lpfwidth, firdes.WIN_RECTANGULAR, 6.76))
def get_qrg(self):
return self.qrg
def set_qrg(self, qrg):
self.qrg = qrg
self.rtlsdr_source_0.set_center_freq(self.qrg*1e6-150e3, 0)
def get_xlatlpfcutoff(self):
return self.xlatlpfcutoff
def set_xlatlpfcutoff(self, xlatlpfcutoff):
self.xlatlpfcutoff = xlatlpfcutoff
self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(2,1e6,self.xlatlpfcutoff,self.xlatlpfwidth,firdes.WIN_RECTANGULAR)))
def get_xlatlpfwidth(self):
return self.xlatlpfwidth
def set_xlatlpfwidth(self, xlatlpfwidth):
self.xlatlpfwidth = xlatlpfwidth
self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(2,1e6,self.xlatlpfcutoff,self.xlatlpfwidth,firdes.WIN_RECTANGULAR)))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.blocks_head_0.set_length(int(self.samp_rate*self.duration))
def argument_parser():
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
parser.add_option(
"-t", "--duration", dest="duration", type="eng_float", default=eng_notation.num_to_str(15),
help="Set capture duration in seconds [default=%default]")
parser.add_option(
"-g", "--gain", dest="gain", type="eng_float", default=eng_notation.num_to_str(20),
help="Set RF gain [default=%default]")
parser.add_option(
"", "--hpfcutoff", dest="hpfcutoff", type="intx", default=57585,
help="Set cutoff frequency of HPF after WFM demodulation [default=%default]")
parser.add_option(
"", "--hpfwidth", dest="hpfwidth", type="intx", default=1370,
help="Set transition width of HPF after WFM demodulation [default=%default]")
parser.add_option(
"", "--lpfcutoff", dest="lpfcutoff", type="intx", default=2240,
help="Set cutoff frequency of LPF processing the RDS symbols [default=%default]")
parser.add_option(
"", "--lpfwidth", dest="lpfwidth", type="intx", default=1075,
help="Set transition width of LPF processing the RDS symbols [default=%default]")
parser.add_option(
"-f", "--qrg", dest="qrg", type="eng_float", default=eng_notation.num_to_str(106.1),
help="Set frequency [default=%default]")
parser.add_option(
"", "--xlatlpfcutoff", dest="xlatlpfcutoff", type="intx", default=80000,
help="Set cutoff frequency of the LPF tapped to Frequency Xlating filter before WFM demod [default=%default]")
parser.add_option(
"", "--xlatlpfwidth", dest="xlatlpfwidth", type="intx", default=50000,
help="Set transition width of the LPF tapped to Frequency Xlating filter before WFM demod [default=%default]")
return parser
def main(top_block_cls=top_block, options=None):
if options is None:
options, _ = argument_parser().parse_args()
tb = top_block_cls(duration=options.duration, gain=options.gain, hpfcutoff=options.hpfcutoff, hpfwidth=options.hpfwidth, lpfcutoff=options.lpfcutoff, lpfwidth=options.lpfwidth, qrg=options.qrg, xlatlpfcutoff=options.xlatlpfcutoff, xlatlpfwidth=options.xlatlpfwidth)
tb.start()
tb.wait()
if __name__ == '__main__':
main()