2 ##################################################
3 # Gnuradio Python Flow Graph
4 # Title: LRIT Receiver (from capture file)
5 # Generated: Wed Dec 16 09:16:13 2009
6 ##################################################
8 from gnuradio import eng_notation
9 from gnuradio import gr
10 from gnuradio import window
11 from gnuradio.eng_option import eng_option
12 from gnuradio.gr import firdes
13 from gnuradio.wxgui import fftsink2
14 from gnuradio.wxgui import forms
15 from gnuradio.wxgui import scopesink2
16 from grc_gnuradio import wxgui as grc_wxgui
17 from optparse import OptionParser
22 class file_rx_lrit(grc_wxgui.top_block_gui):
24 def __init__(self, decim=160):
25 grc_wxgui.top_block_gui.__init__(self, title="LRIT Receiver (from capture file)")
27 ##################################################
29 ##################################################
32 ##################################################
34 ##################################################
35 self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/config.conf'
36 self.symbol_rate = symbol_rate = 293e3
37 self._saved_gain_mu_config = ConfigParser.ConfigParser()
38 self._saved_gain_mu_config.read(config_filename)
39 try: saved_gain_mu = self._saved_gain_mu_config.getfloat('usrp_rx_lrit', 'gain_mu')
40 except: saved_gain_mu = 0.2
41 self.saved_gain_mu = saved_gain_mu
42 self._saved_costas_alpha_config = ConfigParser.ConfigParser()
43 self._saved_costas_alpha_config.read(config_filename)
44 try: saved_costas_alpha = self._saved_costas_alpha_config.getfloat('usrp_rx_lrit', 'costas_alpha')
45 except: saved_costas_alpha = 0.2
46 self.saved_costas_alpha = saved_costas_alpha
47 self.sample_rate = sample_rate = 64e6/decim
48 self.sps = sps = sample_rate/symbol_rate
49 self.gain_mu = gain_mu = saved_gain_mu
50 self.costas_alpha = costas_alpha = saved_costas_alpha
52 ##################################################
54 ##################################################
55 self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
56 self.displays.AddPage(grc_wxgui.Panel(self.displays), "USRP RX")
57 self.displays.AddPage(grc_wxgui.Panel(self.displays), "RRC Filter")
58 self.displays.AddPage(grc_wxgui.Panel(self.displays), "PLL")
59 self.displays.AddPage(grc_wxgui.Panel(self.displays), "MM")
60 self.GridAdd(self.displays, 1, 0, 1, 2)
62 ##################################################
64 ##################################################
65 _gain_mu_sizer = wx.BoxSizer(wx.VERTICAL)
66 self._gain_mu_text_box = forms.text_box(
70 callback=self.set_gain_mu,
72 converter=forms.float_converter(),
75 self._gain_mu_slider = forms.slider(
79 callback=self.set_gain_mu,
83 style=wx.SL_HORIZONTAL,
87 self.GridAdd(_gain_mu_sizer, 0, 1, 1, 1)
88 _costas_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
89 self._costas_alpha_text_box = forms.text_box(
91 sizer=_costas_alpha_sizer,
92 value=self.costas_alpha,
93 callback=self.set_costas_alpha,
95 converter=forms.float_converter(),
98 self._costas_alpha_slider = forms.slider(
100 sizer=_costas_alpha_sizer,
101 value=self.costas_alpha,
102 callback=self.set_costas_alpha,
106 style=wx.SL_HORIZONTAL,
110 self.GridAdd(_costas_alpha_sizer, 0, 0, 1, 1)
112 ##################################################
114 ##################################################
115 self.costas = gr.costas_loop_cc(costas_alpha, (costas_alpha**2)/4.0, 50e-6*sps, -50e-6*sps, 2)
116 self.costas_spectrum = fftsink2.fft_sink_c(
117 self.displays.GetPage(2).GetWin(),
123 sample_rate=sample_rate,
128 title="PLL Spectrum",
132 self.displays.GetPage(2).GridAdd(self.costas_spectrum.win, 0, 0, 1, 1)
133 self.costas_spectrum_0 = fftsink2.fft_sink_c(
134 self.displays.GetPage(3).GetWin(),
140 sample_rate=symbol_rate,
145 title="Bit Sync Spectrum",
149 self.displays.GetPage(3).GridAdd(self.costas_spectrum_0.win, 0, 0, 1, 1)
150 self.costas_waveform = scopesink2.scope_sink_c(
151 self.displays.GetPage(2).GetWin(),
152 title="PLL Waveform",
153 sample_rate=sample_rate,
156 t_scale=20.0/sample_rate,
161 self.displays.GetPage(2).GridAdd(self.costas_waveform.win, 1, 0, 1, 1)
162 self.gr_agc_xx_0 = gr.agc_cc(1e-6, 1.0, 1.0/32767.0, 1.0)
163 self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, (gain_mu**2)/4.0, 0.5, gain_mu, 50e-6)
164 self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "lrit.dat", False)
165 self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, sample_rate)
166 self.mm_waveform = scopesink2.scope_sink_c(
167 self.displays.GetPage(3).GetWin(),
168 title="Constellation",
169 sample_rate=symbol_rate,
172 t_scale=20.0/symbol_rate,
177 self.displays.GetPage(3).GridAdd(self.mm_waveform.win, 1, 0, 1, 1)
178 self.rrc = gr.fir_filter_ccf(1, firdes.root_raised_cosine(
179 1, sample_rate, symbol_rate, 0.25, int(11*sample_rate/symbol_rate)))
180 self.rrc_spectrum = fftsink2.fft_sink_c(
181 self.displays.GetPage(1).GetWin(),
187 sample_rate=sample_rate,
192 title="RRC Spectrum",
196 self.displays.GetPage(1).GridAdd(self.rrc_spectrum.win, 0, 0, 1, 1)
197 self.rx_spectrum = fftsink2.fft_sink_c(
198 self.displays.GetPage(0).GetWin(),
204 sample_rate=sample_rate,
209 title="Baseband Spectrum",
212 self.displays.GetPage(0).GridAdd(self.rx_spectrum.win, 0, 0, 1, 1)
213 self.rx_waveform = scopesink2.scope_sink_c(
214 self.displays.GetPage(0).GetWin(),
215 title="Baseband Waveform",
216 sample_rate=sample_rate,
219 t_scale=20.0/sample_rate,
224 self.displays.GetPage(0).GridAdd(self.rx_waveform.win, 1, 0, 1, 1)
225 self.rx_waveform_0 = scopesink2.scope_sink_c(
226 self.displays.GetPage(1).GetWin(),
227 title="RRC Waveform",
228 sample_rate=sample_rate,
231 t_scale=20.0/sample_rate,
236 self.displays.GetPage(1).GridAdd(self.rx_waveform_0.win, 1, 0, 1, 1)
238 ##################################################
240 ##################################################
241 self.connect((self.rrc, 0), (self.rx_waveform_0, 0))
242 self.connect((self.rrc, 0), (self.rrc_spectrum, 0))
243 self.connect((self.gr_agc_xx_0, 0), (self.rrc, 0))
244 self.connect((self.gr_throttle_0, 0), (self.rx_waveform, 0))
245 self.connect((self.gr_throttle_0, 0), (self.rx_spectrum, 0))
246 self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
247 self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
248 self.connect((self.rrc, 0), (self.costas, 0))
249 self.connect((self.costas, 0), (self.costas_spectrum, 0))
250 self.connect((self.costas, 0), (self.costas_waveform, 0))
251 self.connect((self.costas, 0), (self.gr_clock_recovery_mm_xx_0, 0))
252 self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.costas_spectrum_0, 0))
253 self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.mm_waveform, 0))
255 def set_decim(self, decim):
257 self.set_sample_rate(64e6/self.decim)
259 def set_config_filename(self, config_filename):
260 self.config_filename = config_filename
261 self._saved_costas_alpha_config = ConfigParser.ConfigParser()
262 self._saved_costas_alpha_config.read(self.config_filename)
263 if not self._saved_costas_alpha_config.has_section('usrp_rx_lrit'):
264 self._saved_costas_alpha_config.add_section('usrp_rx_lrit')
265 self._saved_costas_alpha_config.set('usrp_rx_lrit', 'costas_alpha', str(self.costas_alpha))
266 self._saved_costas_alpha_config.write(open(self.config_filename, 'w'))
267 self._saved_gain_mu_config = ConfigParser.ConfigParser()
268 self._saved_gain_mu_config.read(self.config_filename)
269 if not self._saved_gain_mu_config.has_section('usrp_rx_lrit'):
270 self._saved_gain_mu_config.add_section('usrp_rx_lrit')
271 self._saved_gain_mu_config.set('usrp_rx_lrit', 'gain_mu', str(self.gain_mu))
272 self._saved_gain_mu_config.write(open(self.config_filename, 'w'))
274 def set_symbol_rate(self, symbol_rate):
275 self.symbol_rate = symbol_rate
276 self.set_sps(self.sample_rate/self.symbol_rate)
277 self.costas_spectrum_0.set_sample_rate(self.symbol_rate)
278 self.mm_waveform.set_sample_rate(self.symbol_rate)
279 self.rrc.set_taps(firdes.root_raised_cosine(1, self.sample_rate, self.symbol_rate, 0.25, int(11*self.sample_rate/self.symbol_rate)))
281 def set_saved_gain_mu(self, saved_gain_mu):
282 self.saved_gain_mu = saved_gain_mu
283 self.set_gain_mu(self.saved_gain_mu)
285 def set_saved_costas_alpha(self, saved_costas_alpha):
286 self.saved_costas_alpha = saved_costas_alpha
287 self.set_costas_alpha(self.saved_costas_alpha)
289 def set_sample_rate(self, sample_rate):
290 self.sample_rate = sample_rate
291 self.set_sps(self.sample_rate/self.symbol_rate)
292 self.rx_spectrum.set_sample_rate(self.sample_rate)
293 self.rx_waveform.set_sample_rate(self.sample_rate)
294 self.costas_spectrum.set_sample_rate(self.sample_rate)
295 self.costas_waveform.set_sample_rate(self.sample_rate)
296 self.rrc_spectrum.set_sample_rate(self.sample_rate)
297 self.rx_waveform_0.set_sample_rate(self.sample_rate)
298 self.rrc.set_taps(firdes.root_raised_cosine(1, self.sample_rate, self.symbol_rate, 0.25, int(11*self.sample_rate/self.symbol_rate)))
300 def set_sps(self, sps):
302 self.gr_clock_recovery_mm_xx_0.set_omega(self.sps)
304 def set_gain_mu(self, gain_mu):
305 self.gain_mu = gain_mu
306 self._gain_mu_slider.set_value(self.gain_mu)
307 self._gain_mu_text_box.set_value(self.gain_mu)
308 self.gr_clock_recovery_mm_xx_0.set_gain_omega((self.gain_mu**2)/4.0)
309 self.gr_clock_recovery_mm_xx_0.set_gain_mu(self.gain_mu)
310 self._saved_gain_mu_config = ConfigParser.ConfigParser()
311 self._saved_gain_mu_config.read(self.config_filename)
312 if not self._saved_gain_mu_config.has_section('usrp_rx_lrit'):
313 self._saved_gain_mu_config.add_section('usrp_rx_lrit')
314 self._saved_gain_mu_config.set('usrp_rx_lrit', 'gain_mu', str(self.gain_mu))
315 self._saved_gain_mu_config.write(open(self.config_filename, 'w'))
317 def set_costas_alpha(self, costas_alpha):
318 self.costas_alpha = costas_alpha
319 self._costas_alpha_slider.set_value(self.costas_alpha)
320 self._costas_alpha_text_box.set_value(self.costas_alpha)
321 self._saved_costas_alpha_config = ConfigParser.ConfigParser()
322 self._saved_costas_alpha_config.read(self.config_filename)
323 if not self._saved_costas_alpha_config.has_section('usrp_rx_lrit'):
324 self._saved_costas_alpha_config.add_section('usrp_rx_lrit')
325 self._saved_costas_alpha_config.set('usrp_rx_lrit', 'costas_alpha', str(self.costas_alpha))
326 self._saved_costas_alpha_config.write(open(self.config_filename, 'w'))
327 self.costas.set_alpha(self.costas_alpha)
328 self.costas.set_beta((self.costas_alpha**2)/4.0)
330 if __name__ == '__main__':
331 parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
332 parser.add_option("-d", "--decim", dest="decim", type="intx", default=160,
333 help="Set Decim [default=%default]")
334 (options, args) = parser.parse_args()
335 tb = file_rx_lrit(decim=options.decim)