diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-05-02 12:43:43 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-05-02 12:43:43 -0400 |
commit | a247889d7ad212cf3a69df8ec95dc2436e4cc400 (patch) | |
tree | 6b71b5bf9d58a806c0f8bfe5b4e9ecfa6fb04335 /gr-filter | |
parent | 417337cd4a6cef95bbec7c5d04bbacdab0eb9f47 (diff) |
filter: adding examples folder.
First example compares old filter in gr to new one in filter.
Diffstat (limited to 'gr-filter')
-rw-r--r-- | gr-filter/examples/CMakeLists.txt | 27 | ||||
-rwxr-xr-x | gr-filter/examples/fir_filter_fff.py | 93 |
2 files changed, 120 insertions, 0 deletions
diff --git a/gr-filter/examples/CMakeLists.txt b/gr-filter/examples/CMakeLists.txt new file mode 100644 index 0000000000..c798a8403b --- /dev/null +++ b/gr-filter/examples/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright 2011 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. + +include(GrPython) + +# Base stuff +GR_PYTHON_INSTALL(PROGRAMS + fir_filter_fff.py + DESTINATION ${GR_PKG_DIGITAL_EXAMPLES_DIR} + COMPONENT "filter_python" +) diff --git a/gr-filter/examples/fir_filter_fff.py b/gr-filter/examples/fir_filter_fff.py new file mode 100755 index 0000000000..538aded443 --- /dev/null +++ b/gr-filter/examples/fir_filter_fff.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python + +from gnuradio import gr, filter +from gnuradio import eng_notation +from gnuradio.eng_option import eng_option +from optparse import OptionParser + +try: + import scipy +except ImportError: + print "Error: could not import scipy (http://www.scipy.org/)" + sys.exit(1) + +try: + import pylab +except ImportError: + print "Error: could not import pylab (http://matplotlib.sourceforge.net/)" + sys.exit(1) + +class example_fir_filter_fff(gr.top_block): + def __init__(self, N, fs, bw, tw, atten, D): + gr.top_block.__init__(self) + + self._nsamps = N + self._fs = fs + self._bw = bw + self._tw = tw + self._at = atten + self._decim = D + taps = gr.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) + print "Num. Taps: ", len(taps) + + self.src = gr.noise_source_f(gr.GR_GAUSSIAN, 1) + self.head = gr.head(gr.sizeof_float, self._nsamps) + + self.filt0 = filter.fir_filter_fff(self._decim, taps) + self.filt1 = gr.fir_filter_fff(self._decim, taps) + + self.vsnk_src = gr.vector_sink_f() + self.vsnk_out = gr.vector_sink_f() + self.vsnk_gr = gr.vector_sink_f() + + self.connect(self.src, self.head, self.vsnk_src) + self.connect(self.head, self.filt0, self.vsnk_out) + self.connect(self.head, self.filt1, self.vsnk_gr) + +def main(): + parser = OptionParser(option_class=eng_option, conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=10000, + help="Number of samples to process [default=%default]") + parser.add_option("-s", "--samplerate", type="eng_float", default=8000, + help="System sample rate [default=%default]") + parser.add_option("-B", "--bandwidth", type="eng_float", default=1000, + help="Filter bandwidth [default=%default]") + parser.add_option("-T", "--transition", type="eng_float", default=100, + help="Transition band [default=%default]") + parser.add_option("-A", "--attenuation", type="eng_float", default=80, + help="Stopband attenuation [default=%default]") + parser.add_option("-D", "--decimation", type="int", default=1, + help="Decmation factor [default=%default]") + (options, args) = parser.parse_args () + + put = example_fir_filter_fff(options.nsamples, + options.samplerate, + options.bandwidth, + options.transition, + options.attenuation, + options.decimation) + put.run() + + data_src = scipy.array(put.vsnk_src.data()) + data_snk = scipy.array(put.vsnk_out.data()) + data_gr = scipy.array(put.vsnk_gr.data()) + + # Plot the signals PSDs + nfft = 1024 + f1 = pylab.figure(1, figsize=(12,10)) + s1 = f1.add_subplot(1,1,1) + s1.psd(data_src, NFFT=nfft, noverlap=nfft/4, + Fs=options.samplerate) + s1.psd(data_snk, NFFT=nfft, noverlap=nfft/4, + Fs=options.samplerate) + s1.psd(data_gr, NFFT=nfft, noverlap=nfft/4, + Fs=options.samplerate) + + pylab.show() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + |