Imported Upstream version 3.0.4
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / blksimpl / wfm_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.blksimpl.fm_emph import fm_preemph
25
26 class wfm_tx(gr.hier_block):
27     def __init__(self, fg, audio_rate, quad_rate, tau=75e-6, max_dev=75e3):
28         """
29         Wide Band FM Transmitter.
30
31         Takes a single float input stream of audio samples in the range [-1,+1]
32         and produces a single FM modulated complex baseband output.
33
34         @param fg: flow graph
35         @param audio_rate: sample rate of audio stream, >= 16k
36         @type audio_rate: integer
37         @param quad_rate: sample rate of output stream
38         @type quad_rate: integer
39         @param tau: preemphasis time constant (default 75e-6)
40         @type tau: float
41         @param max_dev: maximum deviation in Hz (default 75e3)
42         @type max_dev: float
43
44         quad_rate must be an integer multiple of audio_rate.
45         """
46         
47         # FIXME audio_rate and quad_rate ought to be exact rationals
48         audio_rate = int(audio_rate)
49         quad_rate = int(quad_rate)
50
51         if quad_rate % audio_rate != 0:
52             raise ValueError, "quad_rate is not an integer multiple of audio_rate"
53
54         
55         do_interp = audio_rate != quad_rate
56         
57         if do_interp:
58             interp_factor = quad_rate / audio_rate
59             interp_taps = optfir.low_pass (interp_factor,   # gain
60                                            quad_rate,       # Fs
61                                            16000,           # passband cutoff
62                                            18000,           # stopband cutoff
63                                            0.1,             # passband ripple dB
64                                            40)              # stopband atten dB
65
66             print "len(interp_taps) =", len(interp_taps)
67             self.interpolator = gr.interp_fir_filter_fff (interp_factor, interp_taps)
68
69         self.preemph = fm_preemph (fg, quad_rate, tau=tau)
70         
71         k = 2 * math.pi * max_dev / quad_rate
72         self.modulator = gr.frequency_modulator_fc (k)
73
74         if do_interp:
75             fg.connect (self.interpolator, self.preemph, self.modulator)
76             gr.hier_block.__init__(self, fg, self.interpolator, self.modulator)
77         else:
78             fg.connect(self.preemph, self.modulator)
79             gr.hier_block.__init__(self, fg, self.preemph, self.modulator)