3 from gnuradio import gr, gru, eng_notation, optfir
4 from gnuradio.eng_option import eng_option
5 from optparse import OptionParser
11 def split_filename(src_filename):
12 s = os.path.splitext(src_filename)[0] # drop extension
13 date, time, freq, dec, nchan = s.split('-')
14 return (date, time, freq, int(dec), int(nchan))
17 def make_filename(date, time, freq, n, short_output):
19 return '-'.join((date, time, freq)) + '.s%02d' % (n,)
21 return '-'.join((date, time, freq)) + '.c%02d' % (n,)
23 class my_graph(gr.flow_graph):
25 def __init__(self, src_filename, short_output):
27 Deinterleave file, filter and decimate by 4, and write out
28 a separate file for each input channel.
30 The input file is the raw output of nchannels of short USRP data.
31 That is, they are interleaved short I&Q for each channel.
35 gr.flow_graph.__init__(self)
39 (date, time, freq, dec, nchan) = split_filename(src_filename)
41 src = gr.file_source(gr.sizeof_short, src_filename)
43 # convert stream of interleaved shorts to a stream of complex
44 s2c = gr.interleaved_short_to_complex()
46 # deinterleave complexes into separate streams
47 deint = gr.deinterleave(gr.sizeof_gr_complex)
49 self.connect(src, s2c, deint)
51 taps = optfir.low_pass(1, # gain
53 0.100, # passband cutoff
54 0.125, # stopband cutoff
55 0.01, # passband ripple (dB)
56 70) # stopband atten (dB)
58 print "len(taps) =", len(taps)
60 #plot = gru.gnuplot_freqz(gru.freqz(taps, 1), 1)
61 #raw_input('Press Enter to continue: ')
63 for n in xrange(nchan):
64 #df = gr.fft_filter_ccc(decim, taps)
65 df = gr.fir_filter_ccf(decim, taps)
66 self.connect((deint, n), df)
67 dst_filename = make_filename(date, time, freq, n, short_output)
69 c2s = gr.complex_to_interleaved_short()
70 dst = gr.file_sink(gr.sizeof_short, dst_filename)
71 self.connect(df, c2s, dst)
73 dst = gr.file_sink(gr.sizeof_gr_complex, dst_filename)
77 def split_1_file(filename, short_output):
78 my_graph(filename, short_output).run()
82 usage="%prog: [options] file_to_split..."
83 parser = OptionParser (option_class=eng_option, usage=usage)
84 parser.add_option("-s", "--short", action="store_true", default=False,
85 help="short output if set, else complex")
86 (options, args) = parser.parse_args()
89 split_1_file(filename, options.short)
92 if __name__ == '__main__':