Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-examples / python / usrp / ayfabtu.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2005 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 #
24 # All Your Frequencies are Belong to Us!
25 #
26 #   Transmit NBFM message on 25 channels simultaneously!
27 #
28
29 from gnuradio import gr, gru, eng_notation
30 from gnuradio import usrp
31 from gnuradio import audio
32 from gnuradio import blks
33 from gnuradio import optfir
34 from gnuradio.eng_option import eng_option
35 from optparse import OptionParser
36 import math
37 import sys
38 import random
39
40 from gnuradio.wxgui import stdgui, fftsink
41 import wx
42
43
44 def make_random_complex_tuple(L):
45     result = []
46     for x in range(L):
47         result.append(complex(random.gauss(0, 1),random.gauss(0, 1)))
48                       
49     return tuple(result)
50
51 def random_noise_c():
52     src = gr.vector_source_c(make_random_complex_tuple(32*1024), True)
53     return src
54
55
56 def plot_taps(taps, sample_rate=2):
57     return gru.gnuplot_freqz (gru.freqz (taps, 1), sample_rate)
58     
59
60 class ayfabtu_graph (stdgui.gui_flow_graph):
61     def __init__(self, frame, panel, vbox, argv):
62         stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)
63
64         parser = OptionParser (option_class=eng_option)
65         parser.add_option ("-c", "--duc-freq", type="eng_float", default=29.325e6,
66                            help="set Tx ddc frequency to FREQ", metavar="FREQ")
67         (options, args) = parser.parse_args ()
68
69         nchan = 25
70         IF_GAIN = 80000
71         AUDIO_GAIN = 100
72         
73         self.dac_rate = 128e6
74         self.usrp_interp = 256
75         self.usrp_rate = self.dac_rate / self.usrp_interp    # 500 kS/s
76         self.audio_rate = 32000                              # 32 kS/s
77
78         self.audio_src = gr.file_source(gr.sizeof_float, "ayfabtu.dat", True)
79
80         ahp_taps = gr.firdes.high_pass(1,     # gain
81                                        32e3,  # Fs
82                                        300,   # cutoff
83                                        600,   # trans width
84                                        gr.firdes.WIN_HANN)
85         self.audio_hp = gr.fir_filter_fff(1, ahp_taps)
86
87         self.audio_gain = gr.multiply_const_ff(AUDIO_GAIN)
88
89         null_src = gr.null_source(gr.sizeof_gr_complex)
90         #noise_src = gr.noise_source_c(gr.GR_UNIFORM, 1, 0)
91         noise_src = random_noise_c()
92
93         if 0:
94             artaps = optfir.low_pass(1,       # gain
95                                      2,       # Fs
96                                      .75/32,  # freq1
97                                      1.0/32,  # freq2
98                                      1,       # pb ripple in dB
99                                      50,      # stopband atten in dB
100                                      2)       # + extra taps
101         else:
102             artaps = gr.firdes.low_pass(1,      # gain
103                                         32e3*15,# Fs
104                                         2.7e3,  # cutoff
105                                          .3e3,  # trans width
106                                         gr.firdes.WIN_HANN)
107         print "len(artaps) =", len(artaps)
108         self.audio_resampler = blks.rational_resampler_fff(self, 15, 32, artaps)
109
110         self.fm_mod = blks.nbfm_tx(self, 15000, 15000, max_dev=4.5e3)
111
112
113         fbtaps = gr.firdes.low_pass(1,                # gain
114                                     25*15e3,          # rate
115                                     13e3,             # cutoff
116                                     2e3,              # trans width
117                                     gr.firdes.WIN_HANN)
118         print "len(fbtabs) =", len(fbtaps)
119         #self.plot = plot_taps(fbtaps, 25*15e3)
120         self.filter_bank = blks.synthesis_filterbank(self, nchan, fbtaps)
121         
122         self.if_gain = gr.multiply_const_cc(IF_GAIN)
123
124         if 0:
125             ifrtaps = optfir.low_pass(1,
126                                       2,       # Fs
127                                       .75/3,   # freq1
128                                       1.0/3,   # freq2
129                                       1,       # pb ripple in dB
130                                       50,      # stopband atten in dB
131                                       2)       # + extra taps
132         else:
133             ifrtaps = gr.firdes.low_pass(1,
134                                          2,       # Fs
135                                          .75/3,   # freq1
136                                          .25/3,   # trans width
137                                          gr.firdes.WIN_HANN)
138
139
140         print "len(ifrtaps) =", len(ifrtaps)
141         self.if_resampler = blks.rational_resampler_ccf(self, 4, 3, ifrtaps)
142
143
144         self.u = usrp.sink_c(0, 256)
145         self.u.set_tx_freq(0, options.duc_freq)
146         self.u.set_pga(0, self.u.pga_max())
147
148         # wire it all together
149         
150         self.connect(self.audio_src, self.audio_hp, self.audio_gain,
151                      self.audio_resampler, self.fm_mod)
152
153         null_sink = gr.null_sink(gr.sizeof_gr_complex)
154
155         for i in range(nchan):
156             if True or i == 0:
157                 self.connect(self.fm_mod, (self.filter_bank, i))
158             else:
159                 self.connect(null_src, (self.filter_bank, i))
160
161         self.connect(self.filter_bank, self.if_gain, self.if_resampler, self.u)
162         
163
164 def main ():
165     app = stdgui.stdapp (ayfabtu_graph, "All Your Frequency Are Belong to Us")
166     app.MainLoop ()
167
168 if __name__ == '__main__':
169     main ()