forked from daniestevez/gr-frontends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
airspy_usb_wide.py
executable file
·211 lines (173 loc) · 8.39 KB
/
airspy_usb_wide.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Wide SSB receiver for an Airspy device
# Author: Daniel Estevez
# Description: Receives with an Airspy and streams the wide USB audio (24kHz filter)
# Generated: Fri Sep 30 12:23:05 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 gpredict
import osmosdr
import time
class airspy_usb_wide(gr.top_block):
def __init__(self, bb_gain=20, destination="localhost", freq=0, freq_corr=0, gpredict_port=4532, if_gain=20, offset=50e3, port=7355, rf_gain=40):
gr.top_block.__init__(self, "Wide SSB receiver for an Airspy device")
##################################################
# Parameters
##################################################
self.bb_gain = bb_gain
self.destination = destination
self.freq = freq
self.freq_corr = freq_corr
self.gpredict_port = gpredict_port
self.if_gain = if_gain
self.offset = offset
self.port = port
self.rf_gain = rf_gain
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 2.5e6
self.doppler_freq = doppler_freq = freq
##################################################
# Blocks
##################################################
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
interpolation=24,
decimation=25,
taps=None,
fractional_bw=None,
)
self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.osmosdr_source_0.set_sample_rate(samp_rate)
self.osmosdr_source_0.set_center_freq(freq-offset, 0)
self.osmosdr_source_0.set_freq_corr(freq_corr, 0)
self.osmosdr_source_0.set_dc_offset_mode(0, 0)
self.osmosdr_source_0.set_iq_balance_mode(0, 0)
self.osmosdr_source_0.set_gain_mode(False, 0)
self.osmosdr_source_0.set_gain(rf_gain, 0)
self.osmosdr_source_0.set_if_gain(if_gain, 0)
self.osmosdr_source_0.set_bb_gain(bb_gain, 0)
self.osmosdr_source_0.set_antenna("", 0)
self.osmosdr_source_0.set_bandwidth(0, 0)
self.gpredict_doppler_0 = gpredict.doppler(self.set_doppler_freq, "localhost", 4532, False)
self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(50, (firdes.low_pass(1, samp_rate, 12000, 500)), doppler_freq-freq+offset, samp_rate)
self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_short*1, destination, port, 1472, True)
self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
self.blocks_float_to_short_0 = blocks.float_to_short(1, 32767)
self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
self.analog_sig_source_x_0 = analog.sig_source_c(48000, analog.GR_COS_WAVE, 12000, 1, 0)
##################################################
# Connections
##################################################
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_float_to_short_0, 0))
self.connect((self.blocks_float_to_short_0, 0), (self.blocks_udp_sink_0, 0))
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_complex_to_real_0, 0))
self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.rational_resampler_xxx_0, 0))
self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0, 1))
def get_bb_gain(self):
return self.bb_gain
def set_bb_gain(self, bb_gain):
self.bb_gain = bb_gain
self.osmosdr_source_0.set_bb_gain(self.bb_gain, 0)
def get_destination(self):
return self.destination
def set_destination(self, destination):
self.destination = destination
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = freq
self.set_doppler_freq(self.freq)
self.osmosdr_source_0.set_center_freq(self.freq-self.offset, 0)
self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.doppler_freq-self.freq+self.offset)
def get_freq_corr(self):
return self.freq_corr
def set_freq_corr(self, freq_corr):
self.freq_corr = freq_corr
self.osmosdr_source_0.set_freq_corr(self.freq_corr, 0)
def get_gpredict_port(self):
return self.gpredict_port
def set_gpredict_port(self, gpredict_port):
self.gpredict_port = gpredict_port
def get_if_gain(self):
return self.if_gain
def set_if_gain(self, if_gain):
self.if_gain = if_gain
self.osmosdr_source_0.set_if_gain(self.if_gain, 0)
def get_offset(self):
return self.offset
def set_offset(self, offset):
self.offset = offset
self.osmosdr_source_0.set_center_freq(self.freq-self.offset, 0)
self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.doppler_freq-self.freq+self.offset)
def get_port(self):
return self.port
def set_port(self, port):
self.port = port
def get_rf_gain(self):
return self.rf_gain
def set_rf_gain(self, rf_gain):
self.rf_gain = rf_gain
self.osmosdr_source_0.set_gain(self.rf_gain, 0)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.osmosdr_source_0.set_sample_rate(self.samp_rate)
self.freq_xlating_fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, 12000, 500)))
def get_doppler_freq(self):
return self.doppler_freq
def set_doppler_freq(self, doppler_freq):
self.doppler_freq = doppler_freq
self.freq_xlating_fir_filter_xxx_0.set_center_freq(self.doppler_freq-self.freq+self.offset)
def argument_parser():
description = 'Receives with an Airspy and streams the wide USB audio (24kHz filter)'
parser = OptionParser(usage="%prog: [options]", option_class=eng_option, description=description)
parser.add_option(
"", "--bb-gain", dest="bb_gain", type="eng_float", default=eng_notation.num_to_str(20),
help="Set baseband gain [default=%default]")
parser.add_option(
"", "--destination", dest="destination", type="string", default="localhost",
help="Set localhost [default=%default]")
parser.add_option(
"-f", "--freq", dest="freq", type="eng_float", default=eng_notation.num_to_str(0),
help="Set frequency [default=%default]")
parser.add_option(
"", "--freq-corr", dest="freq_corr", type="eng_float", default=eng_notation.num_to_str(0),
help="Set frequency correction (ppm) [default=%default]")
parser.add_option(
"", "--gpredict-port", dest="gpredict_port", type="intx", default=4532,
help="Set GPredict port [default=%default]")
parser.add_option(
"", "--if-gain", dest="if_gain", type="eng_float", default=eng_notation.num_to_str(20),
help="Set IF gain [default=%default]")
parser.add_option(
"", "--offset", dest="offset", type="eng_float", default=eng_notation.num_to_str(50e3),
help="Set centre frequency offset [default=%default]")
parser.add_option(
"", "--port", dest="port", type="intx", default=7355,
help="Set port [default=%default]")
parser.add_option(
"", "--rf-gain", dest="rf_gain", type="eng_float", default=eng_notation.num_to_str(40),
help="Set RF gain [default=%default]")
return parser
def main(top_block_cls=airspy_usb_wide, options=None):
if options is None:
options, _ = argument_parser().parse_args()
tb = top_block_cls(bb_gain=options.bb_gain, destination=options.destination, freq=options.freq, freq_corr=options.freq_corr, gpredict_port=options.gpredict_port, if_gain=options.if_gain, offset=options.offset, port=options.port, rf_gain=options.rf_gain)
tb.start()
tb.wait()
if __name__ == '__main__':
main()