summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/usrp/limbo/ayfabtu.py
blob: de6c26f58aa8252e1cedea0260cbd9f2f48b1bd7 (plain)
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
#!/usr/bin/env python
#
# Copyright 2005 Free Software Foundation, Inc.
# 
# This file is part of GNU Radio
# 
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# 
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

#
# All Your Frequencies are Belong to Us!
#
#   Transmit NBFM message on 25 channels simultaneously!
#

from gnuradio import gr, gru, eng_notation
from gnuradio import usrp
from gnuradio import audio
from gnuradio import blks
from gnuradio import optfir
from gnuradio.eng_option import eng_option
from optparse import OptionParser
import math
import sys
import random

from gnuradio.wxgui import stdgui, fftsink
import wx


def make_random_complex_tuple(L):
    result = []
    for x in range(L):
        result.append(complex(random.gauss(0, 1),random.gauss(0, 1)))
                      
    return tuple(result)

def random_noise_c():
    src = gr.vector_source_c(make_random_complex_tuple(32*1024), True)
    return src


def plot_taps(taps, sample_rate=2):
    return gru.gnuplot_freqz (gru.freqz (taps, 1), sample_rate)
    

class ayfabtu_graph (stdgui.gui_flow_graph):
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv)

        parser = OptionParser (option_class=eng_option)
        parser.add_option ("-c", "--duc-freq", type="eng_float", default=29.325e6,
                           help="set Tx ddc frequency to FREQ", metavar="FREQ")
        (options, args) = parser.parse_args ()

        nchan = 25
        IF_GAIN = 80000
        AUDIO_GAIN = 100
        
        self.dac_rate = 128e6
        self.usrp_interp = 256
        self.usrp_rate = self.dac_rate / self.usrp_interp    # 500 kS/s
        self.audio_rate = 32000                              # 32 kS/s

        self.audio_src = gr.file_source(gr.sizeof_float, "ayfabtu.dat", True)

        ahp_taps = gr.firdes.high_pass(1,     # gain
                                       32e3,  # Fs
                                       300,   # cutoff
                                       600,   # trans width
                                       gr.firdes.WIN_HANN)
        self.audio_hp = gr.fir_filter_fff(1, ahp_taps)

        self.audio_gain = gr.multiply_const_ff(AUDIO_GAIN)

        null_src = gr.null_source(gr.sizeof_gr_complex)
        #noise_src = gr.noise_source_c(gr.GR_UNIFORM, 1, 0)
        noise_src = random_noise_c()

        if 0:
            artaps = optfir.low_pass(1,       # gain
                                     2,       # Fs
                                     .75/32,  # freq1
                                     1.0/32,  # freq2
                                     1,       # pb ripple in dB
                                     50,      # stopband atten in dB
                                     2)       # + extra taps
        else:
            artaps = gr.firdes.low_pass(1,      # gain
                                        32e3*15,# Fs
                                        2.7e3,  # cutoff
                                         .3e3,  # trans width
                                        gr.firdes.WIN_HANN)
        print "len(artaps) =", len(artaps)
        self.audio_resampler = blks.rational_resampler_fff(self, 15, 32, artaps)

        self.fm_mod = blks.nbfm_tx(self, 15000, 15000, max_dev=4.5e3)


        fbtaps = gr.firdes.low_pass(1,                # gain
                                    25*15e3,          # rate
                                    13e3,             # cutoff
                                    2e3,              # trans width
                                    gr.firdes.WIN_HANN)
        print "len(fbtabs) =", len(fbtaps)
        #self.plot = plot_taps(fbtaps, 25*15e3)
        self.filter_bank = blks.synthesis_filterbank(self, nchan, fbtaps)
        
        self.if_gain = gr.multiply_const_cc(IF_GAIN)

        if 0:
            ifrtaps = optfir.low_pass(1,
                                      2,       # Fs
                                      .75/3,   # freq1
                                      1.0/3,   # freq2
                                      1,       # pb ripple in dB
                                      50,      # stopband atten in dB
                                      2)       # + extra taps
        else:
            ifrtaps = gr.firdes.low_pass(1,
                                         2,       # Fs
                                         .75/3,   # freq1
                                         .25/3,   # trans width
                                         gr.firdes.WIN_HANN)


        print "len(ifrtaps) =", len(ifrtaps)
        self.if_resampler = blks.rational_resampler_ccf(self, 4, 3, ifrtaps)


        self.u = usrp.sink_c(0, 256)
        self.u.set_tx_freq(0, options.duc_freq)
        self.u.set_pga(0, self.u.pga_max())

        # wire it all together
        
        self.connect(self.audio_src, self.audio_hp, self.audio_gain,
                     self.audio_resampler, self.fm_mod)

        null_sink = gr.null_sink(gr.sizeof_gr_complex)

        for i in range(nchan):
            if True or i == 0:
                self.connect(self.fm_mod, (self.filter_bank, i))
            else:
                self.connect(null_src, (self.filter_bank, i))

        self.connect(self.filter_bank, self.if_gain, self.if_resampler, self.u)
        

def main ():
    app = stdgui.stdapp (ayfabtu_graph, "All Your Frequency Are Belong to Us")
    app.MainLoop ()

if __name__ == '__main__':
    main ()