root / gr-noaa / apps / demod_hrpt_file.py @ 70709caa
History | View | Annotate | Download (5 kB)
| 1 | #!/usr/bin/env python
|
|---|---|
| 2 | ##################################################
|
| 3 | # Gnuradio Python Flow Graph
|
| 4 | # Title: USRP HRPT Receiver
|
| 5 | # Generated: Sun Oct 4 08:40:03 2009
|
| 6 | ##################################################
|
| 7 | |
| 8 | from gnuradio import eng_notation |
| 9 | from gnuradio import gr |
| 10 | from gnuradio import noaa |
| 11 | from gnuradio.eng_option import eng_option |
| 12 | from gnuradio.gr import firdes |
| 13 | from optparse import OptionParser |
| 14 | import math |
| 15 | |
| 16 | class demod_hrpt_file(gr.top_block): |
| 17 | |
| 18 | def __init__(self, filename="usrp.dat", output="frames.dat", decim=16, pll_alpha=0.05, sync_alpha=0.05): |
| 19 | gr.top_block.__init__(self, "USRP HRPT Receiver") |
| 20 | |
| 21 | ##################################################
|
| 22 | # Parameters
|
| 23 | ##################################################
|
| 24 | self.filename = filename
|
| 25 | self.output = output
|
| 26 | self.decim = decim
|
| 27 | self.pll_alpha = pll_alpha
|
| 28 | self.sync_alpha = sync_alpha
|
| 29 | |
| 30 | ##################################################
|
| 31 | # Variables
|
| 32 | ##################################################
|
| 33 | self.sym_rate = sym_rate = 600*1109 |
| 34 | self.sample_rate = sample_rate = 64e6/decim |
| 35 | self.sps = sps = sample_rate/sym_rate
|
| 36 | self.hs = hs = int(sps/2.0) |
| 37 | self.mf_taps = mf_taps = [-0.5/hs,]*hs+[0.5/hs,]*hs |
| 38 | self.max_sync_offset = max_sync_offset = 0.01 |
| 39 | self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate |
| 40 | |
| 41 | ##################################################
|
| 42 | # Blocks
|
| 43 | ##################################################
|
| 44 | self.decoder = noaa.hrpt_decoder()
|
| 45 | self.deframer = noaa.hrpt_deframer()
|
| 46 | self.deinterleave = gr.deinterleave(gr.sizeof_float*1) |
| 47 | self.f2c = gr.float_to_complex(1) |
| 48 | self.file_sink = gr.file_sink(gr.sizeof_short*1, output) |
| 49 | self.file_source = gr.file_source(gr.sizeof_short*1, filename, False) |
| 50 | self.gr_fir_filter_xxx_0 = gr.fir_filter_ccc(1, (mf_taps)) |
| 51 | self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) |
| 52 | self.s2f = gr.short_to_float()
|
| 53 | self.sync = noaa.hrpt_sync_fb(sync_alpha, sync_alpha**2/4.0, sps, max_sync_offset) |
| 54 | |
| 55 | ##################################################
|
| 56 | # Connections
|
| 57 | ##################################################
|
| 58 | self.connect((self.deframer, 0), (self.file_sink, 0)) |
| 59 | self.connect((self.sync, 0), (self.deframer, 0)) |
| 60 | self.connect((self.pll, 0), (self.sync, 0)) |
| 61 | self.connect((self.deinterleave, 1), (self.f2c, 1)) |
| 62 | self.connect((self.deinterleave, 0), (self.f2c, 0)) |
| 63 | self.connect((self.deframer, 0), (self.decoder, 0)) |
| 64 | self.connect((self.gr_fir_filter_xxx_0, 0), (self.pll, 0)) |
| 65 | self.connect((self.f2c, 0), (self.gr_fir_filter_xxx_0, 0)) |
| 66 | self.connect((self.s2f, 0), (self.deinterleave, 0)) |
| 67 | self.connect((self.file_source, 0), (self.s2f, 0)) |
| 68 | |
| 69 | def set_filename(self, filename): |
| 70 | self.filename = filename
|
| 71 | |
| 72 | def set_output(self, output): |
| 73 | self.output = output
|
| 74 | |
| 75 | def set_decim(self, decim): |
| 76 | self.decim = decim
|
| 77 | self.set_sample_rate(64e6/self.decim) |
| 78 | |
| 79 | def set_pll_alpha(self, pll_alpha): |
| 80 | self.pll_alpha = pll_alpha
|
| 81 | self.pll.set_alpha(self.pll_alpha) |
| 82 | self.pll.set_beta(self.pll_alpha**2/4.0) |
| 83 | |
| 84 | def set_sync_alpha(self, sync_alpha): |
| 85 | self.sync_alpha = sync_alpha
|
| 86 | self.sync.set_alpha(self.sync_alpha) |
| 87 | self.sync.set_beta(self.sync_alpha**2/4.0) |
| 88 | |
| 89 | def set_sym_rate(self, sym_rate): |
| 90 | self.sym_rate = sym_rate
|
| 91 | self.set_sps(self.sample_rate/self.sym_rate) |
| 92 | |
| 93 | def set_sample_rate(self, sample_rate): |
| 94 | self.sample_rate = sample_rate
|
| 95 | self.set_max_carrier_offset(2*math.pi*100e3/self.sample_rate) |
| 96 | self.set_sps(self.sample_rate/self.sym_rate) |
| 97 | |
| 98 | def set_sps(self, sps): |
| 99 | self.sps = sps
|
| 100 | self.set_hs(int(self.sps/2.0)) |
| 101 | |
| 102 | def set_hs(self, hs): |
| 103 | self.hs = hs
|
| 104 | self.set_mf_taps([-0.5/self.hs,]*self.hs+[0.5/self.hs,]*self.hs) |
| 105 | |
| 106 | def set_mf_taps(self, mf_taps): |
| 107 | self.mf_taps = mf_taps
|
| 108 | self.gr_fir_filter_xxx_0.set_taps((self.mf_taps)) |
| 109 | |
| 110 | def set_max_sync_offset(self, max_sync_offset): |
| 111 | self.max_sync_offset = max_sync_offset
|
| 112 | self.sync.set_max_offset(self.max_sync_offset) |
| 113 | |
| 114 | def set_max_carrier_offset(self, max_carrier_offset): |
| 115 | self.max_carrier_offset = max_carrier_offset
|
| 116 | self.pll.set_max_offset(self.max_carrier_offset) |
| 117 | |
| 118 | if __name__ == '__main__': |
| 119 | parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
|
| 120 | parser.add_option("-F", "--filename", dest="filename", type="string", default="usrp.dat", |
| 121 | help="Set Filename [default=%default]")
|
| 122 | parser.add_option("-o", "--output", dest="output", type="string", default="frames.dat", |
| 123 | help="Set Output [default=%default]")
|
| 124 | parser.add_option("-d", "--decim", dest="decim", type="intx", default=16, |
| 125 | help="Set Decimation [default=%default]")
|
| 126 | parser.add_option("-p", "--pll-alpha", dest="pll_alpha", type="eng_float", default=eng_notation.num_to_str(0.05), |
| 127 | help="Set pll_alpha [default=%default]")
|
| 128 | parser.add_option("-s", "--sync-alpha", dest="sync_alpha", type="eng_float", default=eng_notation.num_to_str(0.05), |
| 129 | help="Set sync_alpha [default=%default]")
|
| 130 | (options, args) = parser.parse_args() |
| 131 | tb = demod_hrpt_file(filename=options.filename, output=options.output, decim=options.decim, pll_alpha=options.pll_alpha, sync_alpha=options.sync_alpha) |
| 132 | tb.run() |
| 133 |