Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blks2impl / nbfm_tx.py
1 #
2 # Copyright 2005 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
20
21
22 import math
23 from gnuradio import gr, optfir
24 from gnuradio.blks2impl.fm_emph import fm_preemph
25
26 #from gnuradio import ctcss
27
28 class nbfm_tx(gr.hier_block2):
29     def __init__(self, audio_rate, quad_rate, tau=75e-6, max_dev=5e3):
30         """
31         Narrow Band FM Transmitter.
32
33         Takes a single float input stream of audio samples in the range [-1,+1]
34         and produces a single FM modulated complex baseband output.
35
36         @param audio_rate: sample rate of audio stream, >= 16k
37         @type audio_rate: integer
38         @param quad_rate: sample rate of output stream
39         @type quad_rate: integer
40         @param tau: preemphasis time constant (default 75e-6)
41         @type tau: float
42         @param max_dev: maximum deviation in Hz (default 5e3)
43         @type max_dev: float
44
45         quad_rate must be an integer multiple of audio_rate.
46         """
47
48         gr.hier_block2.__init__(self, "nbfm_tx",
49                                 gr.io_signature(1, 1, gr.sizeof_float),      # Input signature
50                                 gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
51         
52         # FIXME audio_rate and quad_rate ought to be exact rationals
53         audio_rate = int(audio_rate)
54         quad_rate = int(quad_rate)
55
56         if quad_rate % audio_rate != 0:
57             raise ValueError, "quad_rate is not an integer multiple of audio_rate"
58
59         
60         do_interp = audio_rate != quad_rate
61         
62         if do_interp:
63             interp_factor = quad_rate / audio_rate
64             interp_taps = optfir.low_pass (interp_factor,   # gain
65                                            quad_rate,       # Fs
66                                            4500,            # passband cutoff
67                                            7000,            # stopband cutoff
68                                            0.1,             # passband ripple dB
69                                            40)              # stopband atten dB
70
71             #print "len(interp_taps) =", len(interp_taps)
72             self.interpolator = gr.interp_fir_filter_fff (interp_factor, interp_taps)
73
74         self.preemph = fm_preemph (quad_rate, tau=tau)
75         
76         k = 2 * math.pi * max_dev / quad_rate
77         self.modulator = gr.frequency_modulator_fc (k)
78
79         if do_interp:
80             self.connect (self, self.interpolator, self.preemph, self.modulator, self)
81         else:
82             self.connect(self, self.preemph, self.modulator, self)
83         
84        
85 class ctcss_gen_f(gr.hier_block2):
86     def __init__(self, sample_rate, tone_freq):
87         gr.hier_block2.__init__(self, "ctcss_gen_f",
88                                 gr.io_signature(0, 0, 0),               # Input signature
89                                 gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
90
91         self.plgen = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, tone_freq, 0.1, 0.0)
92         self.connect(self.plgen, self)