diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-12-21 15:11:39 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-12-21 21:19:13 -0500 |
commit | 55d3e4a47958be287648a2021f7e92d81086b2d9 (patch) | |
tree | ae0195c457f2cf2734376679cc88c2d728040680 /gnuradio-core/src/python | |
parent | fa781237f341a74a243a9fb930daee7e62c3a682 (diff) |
blocks: removes blocks moved to gr-blocks from gnuradio-core.
Also fixes up some other missing moves.
Diffstat (limited to 'gnuradio-core/src/python')
38 files changed, 55 insertions, 3837 deletions
diff --git a/gnuradio-core/src/python/gnuradio/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/CMakeLists.txt index 0acb893538..9b75f20f33 100644 --- a/gnuradio-core/src/python/gnuradio/CMakeLists.txt +++ b/gnuradio-core/src/python/gnuradio/CMakeLists.txt @@ -22,8 +22,6 @@ include(GrPython) add_subdirectory(gr) add_subdirectory(gru) add_subdirectory(gruimpl) -add_subdirectory(blks2) -add_subdirectory(blks2impl) if(ENABLE_GR_CTRLPORT) add_subdirectory(ctrlport) @@ -35,8 +33,6 @@ GR_PYTHON_INSTALL(FILES eng_option.py gr_unittest.py gr_xmlrunner.py - optfir.py - window.py DESTINATION ${GR_PYTHON_DIR}/gnuradio COMPONENT "core_python" ) diff --git a/gnuradio-core/src/python/gnuradio/blks2/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/blks2/CMakeLists.txt deleted file mode 100644 index 83d11dd831..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2010-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) - -GR_PYTHON_INSTALL( - FILES __init__.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/blks2 - COMPONENT "core_python" -) diff --git a/gnuradio-core/src/python/gnuradio/blks2/__init__.py b/gnuradio-core/src/python/gnuradio/blks2/__init__.py deleted file mode 100644 index 1d3203ec79..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2/__init__.py +++ /dev/null @@ -1,40 +0,0 @@ -# -# 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. -# -""" -Miscellaneous contents implemented in python. -""" - -import glob -import os.path - -# Semi-hideous kludge to import everything in the blksimpl2 directory -# into the gnuradio.blks2 namespace. This keeps us from having to remember -# to manually update this file. - -for p in __path__: - filenames = glob.glob (os.path.join (p, "..", "blks2impl", "*.py")) - for f in filenames: - f = os.path.basename(f).lower() - f = f[:-3] - if f == '__init__': - continue - # print f - exec "from gnuradio.blks2impl.%s import *" % (f,) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/blks2impl/CMakeLists.txt deleted file mode 100644 index dae287ca3a..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2010-2012 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) - -GR_PYTHON_INSTALL(FILES - __init__.py - filterbank.py - rational_resampler.py - stream_to_vector_decimator.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/blks2impl - COMPONENT "core_python" -) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/__init__.py b/gnuradio-core/src/python/gnuradio/blks2impl/__init__.py deleted file mode 100644 index a4917cf64c..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# make this a package diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/digital_voice.py.real b/gnuradio-core/src/python/gnuradio/blks2impl/digital_voice.py.real deleted file mode 100644 index 6ec66825c1..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/digital_voice.py.real +++ /dev/null @@ -1,102 +0,0 @@ -#!/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. -# - -""" -Digital voice Tx and Rx using GSM 13kbit vocoder and GMSK. - -Runs channel at 32kbit/sec. Currently uses fake channel coding, -but there's room for a rate 1/2 coder. -""" - -from gnuradio import gr, gru -from gnuradio.blksimpl.gmsk import gmsk_mod, gmsk_demod - -from gnuradio.vocoder import gsm_full_rate - -# Size of gsm full rate speech encoder output packet in bytes - -GSM_FRAME_SIZE = 33 - -# Size of packet in bytes that we send to GMSK modulator: -# -# Target: 256kS/sec air rate. -# -# 256kS 1 sym 1 bit 1 byte 0.020 sec 80 bytes -# ---- * ----- * ----- * ------ * --------- = -------- -# sec 8 S 1 sym 8 bits frame frame -# -# gr_simple_framer add 10 bytes of overhead. - -AIR_FRAME_SIZE = 70 - - -class digital_voice_tx(gr.hier_block): - """ - Hierarchical block for digital voice tranmission. - - The input is 8kS/sec floating point audio in the range [-1,+1] - The output is 256kS/sec GMSK modulated complex baseband signal in the range [-1,+1]. - """ - def __init__(self, fg): - samples_per_symbol = 8 - symbol_rate = 32000 - bt = 0.3 # Gaussian filter bandwidth * symbol time - - src_scale = gr.multiply_const_ff(32767) - f2s = gr.float_to_short() - voice_coder = gsm_full_rate.encode_sp() - - channel_coder = gr.fake_channel_encoder_pp(GSM_FRAME_SIZE, AIR_FRAME_SIZE) - p2s = gr.parallel_to_serial(gr.sizeof_char, AIR_FRAME_SIZE) - - mod = gmsk_mod(fg, sps=samples_per_symbol, - symbol_rate=symbol_rate, bt=bt, - p_size=AIR_FRAME_SIZE) - - fg.connect(src_scale, f2s, voice_coder, channel_coder, p2s, mod) - gr.hier_block.__init__(self, fg, src_scale, mod) - - -class digital_voice_rx(gr.hier_block): - """ - Hierarchical block for digital voice reception. - - The input is 256kS/sec GMSK modulated complex baseband signal. - The output is 8kS/sec floating point audio in the range [-1,+1] - """ - def __init__(self, fg): - samples_per_symbol = 8 - symbol_rate = 32000 - - demod = gmsk_demod(fg, sps=samples_per_symbol, - symbol_rate=symbol_rate, - p_size=AIR_FRAME_SIZE) - - s2p = gr.serial_to_parallel(gr.sizeof_char, AIR_FRAME_SIZE) - channel_decoder = gr.fake_channel_decoder_pp(AIR_FRAME_SIZE, GSM_FRAME_SIZE) - - voice_decoder = gsm_full_rate.decode_ps() - s2f = gr.short_to_float () - sink_scale = gr.multiply_const_ff(1.0/32767.) - - fg.connect(demod, s2p, channel_decoder, voice_decoder, s2f, sink_scale) - gr.hier_block.__init__(self, fg, demod, sink_scale) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/filterbank.py b/gnuradio-core/src/python/gnuradio/blks2impl/filterbank.py deleted file mode 100644 index 29e50bc2a3..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/filterbank.py +++ /dev/null @@ -1,171 +0,0 @@ -# -# Copyright 2005,2007 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. -# - -import sys -from gnuradio import gr, gru - -def _generate_synthesis_taps(mpoints): - return [] # FIXME - - -def _split_taps(taps, mpoints): - assert (len(taps) % mpoints) == 0 - result = [list() for x in range(mpoints)] - for i in xrange(len(taps)): - (result[i % mpoints]).append(taps[i]) - return [tuple(x) for x in result] - - -class synthesis_filterbank(gr.hier_block2): - """ - Uniformly modulated polyphase DFT filter bank: synthesis - - See http://cnx.org/content/m10424/latest - """ - def __init__(self, mpoints, taps=None): - """ - Takes M complex streams in, produces single complex stream out - that runs at M times the input sample rate - - Args: - mpoints: number of freq bins/interpolation factor/subbands - taps: filter taps for subband filter - - The channel spacing is equal to the input sample rate. - The total bandwidth and output sample rate are equal the input - sample rate * nchannels. - - Output stream to frequency mapping: - - channel zero is at zero frequency. - - if mpoints is odd: - - Channels with increasing positive frequencies come from - channels 1 through (N-1)/2. - - Channel (N+1)/2 is the maximum negative frequency, and - frequency increases through N-1 which is one channel lower - than the zero frequency. - - if mpoints is even: - - Channels with increasing positive frequencies come from - channels 1 through (N/2)-1. - - Channel (N/2) is evenly split between the max positive and - negative bins. - - Channel (N/2)+1 is the maximum negative frequency, and - frequency increases through N-1 which is one channel lower - than the zero frequency. - - Channels near the frequency extremes end up getting cut - off by subsequent filters and therefore have diminished - utility. - """ - item_size = gr.sizeof_gr_complex - gr.hier_block2.__init__(self, "synthesis_filterbank", - gr.io_signature(mpoints, mpoints, item_size), # Input signature - gr.io_signature(1, 1, item_size)) # Output signature - - - if taps is None: - taps = _generate_synthesis_taps(mpoints) - - # pad taps to multiple of mpoints - r = len(taps) % mpoints - if r != 0: - taps = taps + (mpoints - r) * (0,) - - # split in mpoints separate set of taps - sub_taps = _split_taps(taps, mpoints) - - self.ss2v = gr.streams_to_vector(item_size, mpoints) - self.ifft = gr.fft_vcc(mpoints, False, []) - self.v2ss = gr.vector_to_streams(item_size, mpoints) - # mpoints filters go in here... - self.ss2s = gr.streams_to_stream(item_size, mpoints) - - for i in range(mpoints): - self.connect((self, i), (self.ss2v, i)) - - self.connect(self.ss2v, self.ifft, self.v2ss) - - # build mpoints fir filters... - for i in range(mpoints): - f = gr.fft_filter_ccc(1, sub_taps[i]) - self.connect((self.v2ss, i), f) - self.connect(f, (self.ss2s, i)) - - self.connect(self.ss2s, self) - -class analysis_filterbank(gr.hier_block2): - """ - Uniformly modulated polyphase DFT filter bank: analysis - - See http://cnx.org/content/m10424/latest - """ - def __init__(self, mpoints, taps=None): - """ - Takes 1 complex stream in, produces M complex streams out - that runs at 1/M times the input sample rate - - Args: - mpoints: number of freq bins/interpolation factor/subbands - taps: filter taps for subband filter - - Same channel to frequency mapping as described above. - """ - item_size = gr.sizeof_gr_complex - gr.hier_block2.__init__(self, "analysis_filterbank", - gr.io_signature(1, 1, item_size), # Input signature - gr.io_signature(mpoints, mpoints, item_size)) # Output signature - - if taps is None: - taps = _generate_synthesis_taps(mpoints) - - # pad taps to multiple of mpoints - r = len(taps) % mpoints - if r != 0: - taps = taps + (mpoints - r) * (0,) - - # split in mpoints separate set of taps - sub_taps = _split_taps(taps, mpoints) - - # print >> sys.stderr, "mpoints =", mpoints, "len(sub_taps) =", len(sub_taps) - - self.s2ss = gr.stream_to_streams(item_size, mpoints) - # filters here - self.ss2v = gr.streams_to_vector(item_size, mpoints) - self.fft = gr.fft_vcc(mpoints, True, []) - self.v2ss = gr.vector_to_streams(item_size, mpoints) - - self.connect(self, self.s2ss) - - # build mpoints fir filters... - for i in range(mpoints): - f = gr.fft_filter_ccc(1, sub_taps[mpoints-i-1]) - self.connect((self.s2ss, i), f) - self.connect(f, (self.ss2v, i)) - self.connect((self.v2ss, i), (self, i)) - - self.connect(self.ss2v, self.fft, self.v2ss) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/rational_resampler.py b/gnuradio-core/src/python/gnuradio/blks2impl/rational_resampler.py deleted file mode 100644 index 33b5b0b1f3..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/rational_resampler.py +++ /dev/null @@ -1,127 +0,0 @@ -# -# Copyright 2005,2007 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. -# - -from gnuradio import gr, gru, filter - -_plot = None - -def design_filter(interpolation, decimation, fractional_bw): - """ - Given the interpolation rate, decimation rate and a fractional bandwidth, - design a set of taps. - - Args: - interpolation: interpolation factor (integer > 0) - decimation: decimation factor (integer > 0) - fractional_bw: fractional bandwidth in (0, 0.5) 0.4 works well. (float) - Returns: - : sequence of numbers - """ - - if fractional_bw >= 0.5 or fractional_bw <= 0: - raise ValueError, "Invalid fractional_bandwidth, must be in (0, 0.5)" - - beta = 5.0 - trans_width = 0.5 - fractional_bw - mid_transition_band = 0.5 - trans_width/2 - - taps = gr.firdes.low_pass(interpolation, # gain - 1, # Fs - mid_transition_band/interpolation, # trans mid point - trans_width/interpolation, # transition width - gr.firdes.WIN_KAISER, - beta # beta - ) - - return taps - - - -class _rational_resampler_base(gr.hier_block2): - """ - base class for all rational resampler variants. - """ - def __init__(self, resampler_base, - interpolation, decimation, taps=None, fractional_bw=None): - """ - Rational resampling polyphase FIR filter. - - Either taps or fractional_bw may be specified, but not both. - If neither is specified, a reasonable default, 0.4, is used as - the fractional_bw. - - Args: - interpolation: interpolation factor (integer > 0) - decimation: decimation factor (integer > 0) - taps: optional filter coefficients (sequence) - fractional_bw: fractional bandwidth in (0, 0.5), measured at final freq (use 0.4) (float) - """ - - if not isinstance(interpolation, int) or interpolation < 1: - raise ValueError, "interpolation must be an integer >= 1" - - if not isinstance(decimation, int) or decimation < 1: - raise ValueError, "decimation must be an integer >= 1" - - if taps is None and fractional_bw is None: - fractional_bw = 0.4 - - d = gru.gcd(interpolation, decimation) - interpolation = interpolation // d - decimation = decimation // d - - if taps is None: - taps = design_filter(interpolation, decimation, fractional_bw) - - resampler = resampler_base(interpolation, decimation, taps) - gr.hier_block2.__init__(self, "rational_resampler", - gr.io_signature(1, 1, resampler.input_signature().sizeof_stream_item(0)), - gr.io_signature(1, 1, resampler.output_signature().sizeof_stream_item(0))) - - self.connect(self, resampler, self) - - -class rational_resampler_fff(_rational_resampler_base): - def __init__(self, interpolation, decimation, taps=None, fractional_bw=None): - """ - Rational resampling polyphase FIR filter with - float input, float output and float taps. - """ - _rational_resampler_base.__init__(self, filter.rational_resampler_base_fff, - interpolation, decimation, taps, fractional_bw) - -class rational_resampler_ccf(_rational_resampler_base): - def __init__(self, interpolation, decimation, taps=None, fractional_bw=None): - """ - Rational resampling polyphase FIR filter with - complex input, complex output and float taps. - """ - _rational_resampler_base.__init__(self, filter.rational_resampler_base_ccf, - interpolation, decimation, taps, fractional_bw) - -class rational_resampler_ccc(_rational_resampler_base): - def __init__(self, interpolation, decimation, taps=None, fractional_bw=None): - """ - Rational resampling polyphase FIR filter with - complex input, complex output and complex taps. - """ - _rational_resampler_base.__init__(self, filter.rational_resampler_base_ccc, - interpolation, decimation, taps, fractional_bw) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py b/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py deleted file mode 100644 index d6808b722f..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py +++ /dev/null @@ -1,101 +0,0 @@ -# -# Copyright 2008 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. -# - -from gnuradio import gr - -class stream_to_vector_decimator(gr.hier_block2): - """ - Convert the stream to a vector, decimate the vector stream to achieve the vector rate. - """ - - def __init__(self, item_size, sample_rate, vec_rate, vec_len): - """ - Create the block chain. - - Args: - item_size: the number of bytes per sample - sample_rate: the rate of incoming samples - vec_rate: the rate of outgoing vectors (same units as sample_rate) - vec_len: the length of the outgoing vectors in items - """ - self._vec_rate = vec_rate - self._vec_len = vec_len - self._sample_rate = sample_rate - - gr.hier_block2.__init__(self, "stream_to_vector_decimator", - gr.io_signature(1, 1, item_size), # Input signature - gr.io_signature(1, 1, item_size*vec_len)) # Output signature - - s2v = gr.stream_to_vector(item_size, vec_len) - self.one_in_n = gr.keep_one_in_n(item_size*vec_len, 1) - self._update_decimator() - self.connect(self, s2v, self.one_in_n, self) - - def set_sample_rate(self, sample_rate): - """ - Set the new sampling rate and update the decimator. - - Args: - sample_rate: the new rate - """ - self._sample_rate = sample_rate - self._update_decimator() - - def set_vec_rate(self, vec_rate): - """ - Set the new vector rate and update the decimator. - - Args: - vec_rate: the new rate - """ - self._vec_rate = vec_rate - self._update_decimator() - - def set_decimation(self, decim): - """ - Set the decimation parameter directly. - - Args: - decim: the new decimation - """ - self._decim = max(1, int(round(decim))) - self.one_in_n.set_n(self._decim) - - def _update_decimator(self): - self.set_decimation(self._sample_rate/self._vec_len/self._vec_rate) - - def decimation(self): - """ - Returns the actual decimation. - """ - return self._decim - - def sample_rate(self): - """ - Returns configured sample rate. - """ - return self._sample_rate - - def frame_rate(self): - """ - Returns actual frame rate - """ - return self._sample_rate/self._vec_len/self._decim diff --git a/gnuradio-core/src/python/gnuradio/gr/__init__.py b/gnuradio-core/src/python/gnuradio/gr/__init__.py index 3ece4b2676..2735f500fb 100644 --- a/gnuradio-core/src/python/gnuradio/gr/__init__.py +++ b/gnuradio-core/src/python/gnuradio/gr/__init__.py @@ -34,19 +34,5 @@ from hier_block2 import * from top_block import * from gateway import basic_block, sync_block, decim_block, interp_block -# create a couple of aliases -serial_to_parallel = stream_to_vector -parallel_to_serial = vector_to_stream - # Force the preference database to be initialized from prefs import prefs - -#alias old gr_add_vXX and gr_multiply_vXX -add_vcc = add_cc -add_vff = add_ff -add_vii = add_ii -add_vss = add_ss -multiply_vcc = multiply_cc -multiply_vff = multiply_ff -multiply_vii = multiply_ii -multiply_vss = multiply_ss diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py b/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py deleted file mode 100755 index 7ccbbe8ad4..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_add_and_friends.py +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,2010 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. -# - -from gnuradio import gr, gr_unittest - -class test_add_and_friends (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def help_ii (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_i (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_i () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_ff (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_f (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_f () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_cc (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_c (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_c () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def test_add_const_ii (self): - src_data = (1, 2, 3, 4, 5) - expected_result = (6, 7, 8, 9, 10) - op = gr.add_const_ii (5) - self.help_ii ((src_data,), expected_result, op) - - def test_add_const_cc (self): - src_data = (1, 2, 3, 4, 5) - expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j) - op = gr.add_const_cc (5j) - self.help_cc ((src_data,), expected_result, op) - - def test_mult_const_ii (self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_ii (5) - self.help_ii ((src_data,), expected_result, op) - - def test_mult_const_ff (self): - src_data = (-1, 0, 1, 2, 3) - expected_result = (-5, 0, 5, 10, 15) - op = gr.multiply_const_cc (5) - self.help_cc ((src_data,), expected_result, op) - - def test_mult_const_cc (self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j) - op = gr.multiply_const_cc (5) - self.help_cc ((src_data,), expected_result, op) - - def test_mult_const_cc2 (self): - src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j) - expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j) - op = gr.multiply_const_cc (5+2j) - self.help_cc ((src_data,), expected_result, op) - - def test_add_ii (self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (9, -1, 7, 12, 7) - op = gr.add_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_mult_ii (self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8, -6, 12, 32, 10) - op = gr.multiply_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_mult_ff (self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8, -6, 12, 32, 10) - op = gr.multiply_ff () - self.help_ff ((src1_data, src2_data), - expected_result, op) - - def test_mult_cc (self): - src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j) - src2_data = (8, -3, 4, 8, 2) - expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j) - op = gr.multiply_cc () - self.help_cc ((src1_data, src2_data), - expected_result, op) - - def test_sub_ii_1 (self): - src1_data = (1, 2, 3, 4, 5) - expected_result = (-1, -2, -3, -4, -5) - op = gr.sub_ii () - self.help_ii ((src1_data,), - expected_result, op) - - def test_sub_ii_2 (self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (8, -3, 4, 8, 2) - expected_result = (-7, 5, -1, -4, 3) - op = gr.sub_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_div_ff_1 (self): - src1_data = (1, 2, 4, -8) - expected_result = (1, 0.5, 0.25, -.125) - op = gr.divide_ff () - self.help_ff ((src1_data,), - expected_result, op) - - def test_div_ff_2 (self): - src1_data = ( 5, 9, -15, 1024) - src2_data = (10, 3, -5, 64) - expected_result = (0.5, 3, 3, 16) - op = gr.divide_ff () - self.help_ff ((src1_data, src2_data), - expected_result, op) - - -if __name__ == '__main__': - gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_add_v_and_friends.py b/gnuradio-core/src/python/gnuradio/gr/qa_add_v_and_friends.py deleted file mode 100755 index c8df47b392..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_add_v_and_friends.py +++ /dev/null @@ -1,353 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,2010 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. -# - -from gnuradio import gr, gr_unittest - -class test_add_v_and_friends(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def help_ss(self, size, src_data, exp_data, op): - for s in zip(range (len (src_data)), src_data): - src = gr.vector_source_s(s[1]) - srcv = gr.stream_to_vector(gr.sizeof_short, size) - self.tb.connect(src, srcv) - self.tb.connect(srcv, (op, s[0])) - rhs = gr.vector_to_stream(gr.sizeof_short, size) - dst = gr.vector_sink_s() - self.tb.connect(op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_ii(self, size, src_data, exp_data, op): - for s in zip(range (len (src_data)), src_data): - src = gr.vector_source_i(s[1]) - srcv = gr.stream_to_vector(gr.sizeof_int, size) - self.tb.connect(src, srcv) - self.tb.connect(srcv, (op, s[0])) - rhs = gr.vector_to_stream(gr.sizeof_int, size) - dst = gr.vector_sink_i() - self.tb.connect(op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_ff(self, size, src_data, exp_data, op): - for s in zip(range (len (src_data)), src_data): - src = gr.vector_source_f(s[1]) - srcv = gr.stream_to_vector(gr.sizeof_float, size) - self.tb.connect(src, srcv) - self.tb.connect(srcv, (op, s[0])) - rhs = gr.vector_to_stream(gr.sizeof_float, size) - dst = gr.vector_sink_f() - self.tb.connect(op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_cc(self, size, src_data, exp_data, op): - for s in zip(range (len (src_data)), src_data): - src = gr.vector_source_c(s[1]) - srcv = gr.stream_to_vector(gr.sizeof_gr_complex, size) - self.tb.connect(src, srcv) - self.tb.connect(srcv, (op, s[0])) - rhs = gr.vector_to_stream(gr.sizeof_gr_complex, size) - dst = gr.vector_sink_c() - self.tb.connect(op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_const_ss(self, src_data, exp_data, op): - src = gr.vector_source_s(src_data) - srcv = gr.stream_to_vector(gr.sizeof_short, len(src_data)) - rhs = gr.vector_to_stream(gr.sizeof_short, len(src_data)) - dst = gr.vector_sink_s() - self.tb.connect(src, srcv, op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_const_ii(self, src_data, exp_data, op): - src = gr.vector_source_i(src_data) - srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data)) - rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data)) - dst = gr.vector_sink_i() - self.tb.connect(src, srcv, op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_const_ff(self, src_data, exp_data, op): - src = gr.vector_source_f(src_data) - srcv = gr.stream_to_vector(gr.sizeof_float, len(src_data)) - rhs = gr.vector_to_stream(gr.sizeof_float, len(src_data)) - dst = gr.vector_sink_f() - self.tb.connect(src, srcv, op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - def help_const_cc(self, src_data, exp_data, op): - src = gr.vector_source_c(src_data) - srcv = gr.stream_to_vector(gr.sizeof_gr_complex, len(src_data)) - rhs = gr.vector_to_stream(gr.sizeof_gr_complex, len(src_data)) - dst = gr.vector_sink_c() - self.tb.connect(src, srcv, op, rhs, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(exp_data, result_data) - - - def test_add_vss_one(self): - src1_data = (1,) - src2_data = (2,) - src3_data = (3,) - expected_result = (6,) - op = gr.add_vss(1) - self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vss_five(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (6, 7, 8, 9, 10) - src3_data = (11, 12, 13, 14, 15) - expected_result = (18, 21, 24, 27, 30) - op = gr.add_vss(5) - self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vii_one(self): - src1_data = (1,) - src2_data = (2,) - src3_data = (3,) - expected_result = (6,) - op = gr.add_vii(1) - self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vii_five(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (6, 7, 8, 9, 10) - src3_data = (11, 12, 13, 14, 15) - expected_result = (18, 21, 24, 27, 30) - op = gr.add_vii(5) - self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vff_one(self): - src1_data = (1.0,) - src2_data = (2.0,) - src3_data = (3.0,) - expected_result = (6.0,) - op = gr.add_vff(1) - self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vff_five(self): - src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) - src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) - src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) - expected_result = (18.0, 21.0, 24.0, 27.0, 30.0) - op = gr.add_vff(5) - self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vcc_one(self): - src1_data = (1.0+2.0j,) - src2_data = (3.0+4.0j,) - src3_data = (5.0+6.0j,) - expected_result = (9.0+12j,) - op = gr.add_vcc(1) - self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_vcc_five(self): - src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) - src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) - src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) - expected_result = (33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j) - op = gr.add_vcc(5) - self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_add_const_vss_one(self): - src_data = (1,) - op = gr.add_const_vss((2,)) - exp_data = (3,) - self.help_const_ss(src_data, exp_data, op) - - def test_add_const_vss_five(self): - src_data = (1, 2, 3, 4, 5) - op = gr.add_const_vss((6, 7, 8, 9, 10)) - exp_data = (7, 9, 11, 13, 15) - self.help_const_ss(src_data, exp_data, op) - - def test_add_const_vii_one(self): - src_data = (1,) - op = gr.add_const_vii((2,)) - exp_data = (3,) - self.help_const_ii(src_data, exp_data, op) - - def test_add_const_vii_five(self): - src_data = (1, 2, 3, 4, 5) - op = gr.add_const_vii((6, 7, 8, 9, 10)) - exp_data = (7, 9, 11, 13, 15) - self.help_const_ii(src_data, exp_data, op) - - def test_add_const_vff_one(self): - src_data = (1.0,) - op = gr.add_const_vff((2.0,)) - exp_data = (3.0,) - self.help_const_ff(src_data, exp_data, op) - - def test_add_const_vff_five(self): - src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - op = gr.add_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) - exp_data = (7.0, 9.0, 11.0, 13.0, 15.0) - self.help_const_ff(src_data, exp_data, op) - - def test_add_const_vcc_one(self): - src_data = (1.0+2.0j,) - op = gr.add_const_vcc((2.0+3.0j,)) - exp_data = (3.0+5.0j,) - self.help_const_cc(src_data, exp_data, op) - - def test_add_const_vcc_five(self): - src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) - op = gr.add_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) - exp_data = (12.0+14.0j, 16.0+18.0j, 20.0+22.0j, 24.0+26.0j, 28.0+30.0j) - self.help_const_cc(src_data, exp_data, op) - - - def test_multiply_vss_one(self): - src1_data = (1,) - src2_data = (2,) - src3_data = (3,) - expected_result = (6,) - op = gr.multiply_vss(1) - self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vss_five(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (6, 7, 8, 9, 10) - src3_data = (11, 12, 13, 14, 15) - expected_result = (66, 168, 312, 504, 750) - op = gr.multiply_vss(5) - self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vii_one(self): - src1_data = (1,) - src2_data = (2,) - src3_data = (3,) - expected_result = (6,) - op = gr.multiply_vii(1) - self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vii_five(self): - src1_data = (1, 2, 3, 4, 5) - src2_data = (6, 7, 8, 9, 10) - src3_data = (11, 12, 13, 14, 15) - expected_result = (66, 168, 312, 504, 750) - op = gr.multiply_vii(5) - self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vff_one(self): - src1_data = (1.0,) - src2_data = (2.0,) - src3_data = (3.0,) - expected_result = (6.0,) - op = gr.multiply_vff(1) - self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vff_five(self): - src1_data = (1.0, 2.0, 3.0, 4.0, 5.0) - src2_data = (6.0, 7.0, 8.0, 9.0, 10.0) - src3_data = (11.0, 12.0, 13.0, 14.0, 15.0) - expected_result = (66.0, 168.0, 312.0, 504.0, 750.0) - op = gr.multiply_vff(5) - self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vcc_one(self): - src1_data = (1.0+2.0j,) - src2_data = (3.0+4.0j,) - src3_data = (5.0+6.0j,) - expected_result = (-85+20j,) - op = gr.multiply_vcc(1) - self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_vcc_five(self): - src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) - src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j) - src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j) - expected_result = (-1021.0+428.0j, -2647.0+1754.0j, -4945.0+3704.0j, -8011.0+6374.0j, -11941.0+9860.0j) - op = gr.multiply_vcc(5) - self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op) - - def test_multiply_const_vss_one(self): - src_data = (2,) - op = gr.multiply_const_vss((3,)) - exp_data = (6,) - self.help_const_ss(src_data, exp_data, op) - - def test_multiply_const_vss_five(self): - src_data = (1, 2, 3, 4, 5) - op = gr.multiply_const_vss((6, 7, 8, 9, 10)) - exp_data = (6, 14, 24, 36, 50) - self.help_const_ss(src_data, exp_data, op) - - def test_multiply_const_vii_one(self): - src_data = (2,) - op = gr.multiply_const_vii((3,)) - exp_data = (6,) - self.help_const_ii(src_data, exp_data, op) - - def test_multiply_const_vii_five(self): - src_data = (1, 2, 3, 4, 5) - op = gr.multiply_const_vii((6, 7, 8, 9, 10)) - exp_data = (6, 14, 24, 36, 50) - self.help_const_ii(src_data, exp_data, op) - - def test_multiply_const_vff_one(self): - src_data = (2.0,) - op = gr.multiply_const_vff((3.0,)) - exp_data = (6.0,) - self.help_const_ff(src_data, exp_data, op) - - def test_multiply_const_vff_five(self): - src_data = (1.0, 2.0, 3.0, 4.0, 5.0) - op = gr.multiply_const_vff((6.0, 7.0, 8.0, 9.0, 10.0)) - exp_data = (6.0, 14.0, 24.0, 36.0, 50.0) - self.help_const_ff(src_data, exp_data, op) - - def test_multiply_const_vcc_one(self): - src_data = (1.0+2.0j,) - op = gr.multiply_const_vcc((2.0+3.0j,)) - exp_data = (-4.0+7.0j,) - self.help_const_cc(src_data, exp_data, op) - - def test_multiply_const_vcc_five(self): - src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j) - op = gr.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)) - exp_data = (-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j) - self.help_const_cc(src_data, exp_data, op) - - -if __name__ == '__main__': - gr_unittest.run(test_add_v_and_friends, "test_add_v_and_friends.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_argmax.py b/gnuradio-core/src/python/gnuradio/gr/qa_argmax.py deleted file mode 100644 index 564eb620b0..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_argmax.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2007,2010 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. -# - -from gnuradio import gr, gr_unittest -import math - - -class test_arg_max (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - - def tearDown (self): - self.tb = None - - - def test_001(self): - tb = self.tb - - src1_data = (0,0.2,-0.3,0,12,0) - src2_data = (0,0.0,3.0,0,10,0) - src3_data = (0,0.0,3.0,0,1,0) - - src1 = gr.vector_source_f (src1_data) - s2v1 = gr.stream_to_vector(gr.sizeof_float, len(src1_data)) - tb.connect( src1, s2v1 ) - - src2 = gr.vector_source_f (src2_data) - s2v2 = gr.stream_to_vector(gr.sizeof_float, len(src1_data)) - tb.connect( src2, s2v2 ) - - src3 = gr.vector_source_f (src3_data) - s2v3 = gr.stream_to_vector(gr.sizeof_float, len(src1_data)) - tb.connect( src3, s2v3 ) - - dst1 = gr.vector_sink_s () - dst2 = gr.vector_sink_s () - argmax = gr.argmax_fs (len(src1_data)) - - tb.connect (s2v1, (argmax, 0)) - tb.connect (s2v2, (argmax, 1)) - tb.connect (s2v3, (argmax, 2)) - - tb.connect ((argmax,0), dst1) - tb.connect ((argmax,1), dst2) - - tb.run () - index = dst1.data () - source = dst2.data () - self.assertEqual ( index, (4,)) - self.assertEqual ( source, (0,)) - - - -if __name__ == '__main__': - gr_unittest.run(test_arg_max, "test_arg_max.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py b/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py deleted file mode 100755 index 8a6dd9056f..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_bin_statistics.py +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2006,2007,2010 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. -# - -from gnuradio import gr, gr_unittest -import random -import struct - -#import os -#print "pid =", os.getpid() -#raw_input("Attach gdb and press return...") - -""" -Note: The QA tests below have been disabled by renaming them from test_* -to xtest_*. See ticket:199 on http://gnuradio.org/trac/ticket/199 -""" - -class counter(gr.feval_dd): - def __init__(self, step_size=1): - gr.feval_dd.__init__(self) - self.step_size = step_size - self.count = 0 - - def eval(self, input): - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - return t - - -class counter3(gr.feval_dd): - def __init__(self, f, step_size): - gr.feval_dd.__init__(self) - self.f = f - self.step_size = step_size - self.count = 0 - - def eval(self, input): - try: - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - self.f(self.count) - except Exception, e: - print "Exception: ", e - return t - -def foobar3(new_t): - #print "foobar3: new_t =", new_t - pass - - -class counter4(gr.feval_dd): - def __init__(self, obj_instance, step_size): - gr.feval_dd.__init__(self) - self.obj_instance = obj_instance - self.step_size = step_size - self.count = 0 - - def eval(self, input): - try: - #print "eval: self.count =", self.count - t = self.count - self.count = self.count + self.step_size - self.obj_instance.foobar4(self.count) - except Exception, e: - print "Exception: ", e - return t - - -class parse_msg(object): - def __init__(self, msg): - self.center_freq = msg.arg1() - self.vlen = int(msg.arg2()) - assert(msg.length() == self.vlen * gr.sizeof_float) - self.data = struct.unpack('%df' % (self.vlen,), msg.to_string()) - -# FIXME: see ticket:199 -class xtest_bin_statistics(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block () - - def tearDown(self): - self.tb = None - - def xtest_001(self): - vlen = 4 - tune = counter(1) - tune_delay = 0 - dwell_delay = 1 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16 - )]) - - src = gr.vector_source_f(src_data, False) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) - self.tb.connect(src, s2v, stats) - self.tb.run() - self.assertEqual(4, msgq.count()) - for i in range(4): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - def xtest_002(self): - vlen = 4 - tune = counter(1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = gr.vector_source_f(src_data, False) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) - self.tb.connect(src, s2v, stats) - self.tb.run() - self.assertEqual(1, msgq.count()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - - - def xtest_003(self): - vlen = 4 - tune = counter3(foobar3, 1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = gr.vector_source_f(src_data, False) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) - self.tb.connect(src, s2v, stats) - self.tb.run() - self.assertEqual(1, msgq.count()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - - def foobar4(self, new_t): - #print "foobar4: new_t =", new_t - pass - - def xtest_004(self): - vlen = 4 - tune = counter4(self, 1) - tune_delay = 1 - dwell_delay = 2 - msgq = gr.msg_queue() - - src_data = tuple([float(x) for x in - ( 1, 2, 3, 4, - 9, 6, 11, 8, - 5, 10, 7, 12, - 13, 14, 15, 16 - )]) - - expected_results = tuple([float(x) for x in - ( 9, 10, 11, 12)]) - - src = gr.vector_source_f(src_data, False) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) - self.tb.connect(src, s2v, stats) - self.tb.run() - self.assertEqual(1, msgq.count()) - for i in range(1): - m = parse_msg(msgq.delete_head()) - #print "m =", m.center_freq, m.data - self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data) - - -if __name__ == '__main__': - gr_unittest.run(xtest_bin_statistics, "test_bin_statistics.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py b/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py index 911879f6ff..374d87c5ca 100644 --- a/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py @@ -158,6 +158,26 @@ class fc32_to_f32_2(gr.sync_block): output_items[0][::,1] = numpy.imag(input_items[0]) return len(output_items[0]) +class vector_to_stream(gr.interp_block): + def __init__(self, itemsize, nitems_per_block): + gr.interp_block.__init__( + self, + name = "vector_to_stream", + in_sig = [(itemsize, nitems_per_block)], + out_sig = [itemsize], + interp = nitems_per_block + ) + self.block_size = nitems_per_block + + def work(self, input_items, output_items): + n = 0 + for i in xrange(len(input_items[0])): + for j in xrange(self.block_size): + output_items[0][n] = input_items[0][i][j] + n += 1 + + return len(output_items[0]) + class test_block_gateway(gr_unittest.TestCase): def test_add_f32(self): @@ -224,7 +244,7 @@ class test_block_gateway(gr_unittest.TestCase): tb = gr.top_block() src = gr.vector_source_c([1+2j, 3+4j, 5+6j, 7+8j, 9+10j], False) convert = fc32_to_f32_2() - v2s = gr.vector_to_stream(gr.sizeof_float, 2) + v2s = vector_to_stream(numpy.float32, 2) sink = gr.vector_sink_f() tb.connect(src, convert, v2s, sink) tb.run() diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py b/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py deleted file mode 100755 index d7d134dcbe..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_boolean_operators.py +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,2008,2010 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. -# - -from gnuradio import gr, gr_unittest - -class test_boolean_operators (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def help_ss (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_s (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_s () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_bb (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_b (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_b () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def help_ii (self, src_data, exp_data, op): - for s in zip (range (len (src_data)), src_data): - src = gr.vector_source_i (s[1]) - self.tb.connect (src, (op, s[0])) - dst = gr.vector_sink_i () - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (exp_data, result_data) - - def test_xor_ss (self): - src1_data = (1, 2, 3, 0x5004, 0x1150) - src2_data = (8, 2, 1 , 0x0508, 0x1105) - expected_result = (9, 0, 2, 0x550C, 0x0055) - op = gr.xor_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_xor_bb (self): - src1_data = (1, 2, 3, 4, 0x50) - src2_data = (8, 2, 1 , 8, 0x05) - expected_result = (9, 0, 2, 0xC, 0x55) - op = gr.xor_bb () - self.help_bb ((src1_data, src2_data), - expected_result, op) - - - def test_xor_ii (self): - src1_data = (1, 2, 3, 0x5000004, 0x11000050) - src2_data = (8, 2, 1 , 0x0500008, 0x11000005) - expected_result = (9, 0, 2, 0x550000C, 0x00000055) - op = gr.xor_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_and_ss (self): - src1_data = (1, 2, 3, 0x5004, 0x1150) - src2_data = (8, 2, 1 , 0x0508, 0x1105) - expected_result = (0, 2, 1, 0x0000, 0x1100) - op = gr.and_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_and_bb (self): - src1_data = (1, 2, 2, 3, 0x04, 0x50) - src2_data = (8, 2, 2, 1, 0x08, 0x05) - src3_data = (8, 2, 1, 1, 0x08, 0x05) - expected_result = (0, 2, 0, 1, 0x00, 0x00) - op = gr.and_bb () - self.help_bb ((src1_data, src2_data, src3_data), - expected_result, op) - - def test_and_ii (self): - src1_data = (1, 2, 3, 0x50005004, 0x11001150) - src2_data = (8, 2, 1 , 0x05000508, 0x11001105) - expected_result = (0, 2, 1, 0x00000000, 0x11001100) - op = gr.and_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_or_ss (self): - src1_data = (1, 2, 3, 0x5004, 0x1150) - src2_data = (8, 2, 1 , 0x0508, 0x1105) - expected_result = (9, 2, 3, 0x550C, 0x1155) - op = gr.or_ss () - self.help_ss ((src1_data, src2_data), - expected_result, op) - - def test_or_bb (self): - src1_data = (1, 2, 2, 3, 0x04, 0x50) - src2_data = (8, 2, 2, 1 , 0x08, 0x05) - src3_data = (8, 2, 1, 1 , 0x08, 0x05) - expected_result = (9, 2, 3, 3, 0x0C, 0x55) - op = gr.or_bb () - self.help_bb ((src1_data, src2_data, src3_data), - expected_result, op) - - def test_or_ii (self): - src1_data = (1, 2, 3, 0x50005004, 0x11001150) - src2_data = (8, 2, 1 , 0x05000508, 0x11001105) - expected_result = (9, 2, 3, 0x5500550C, 0x11001155) - op = gr.or_ii () - self.help_ii ((src1_data, src2_data), - expected_result, op) - - def test_not_ss (self): - src1_data = (1, 2, 3, 0x5004, 0x1150) - expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150) - op = gr.not_ss () - self.help_ss ((((src1_data),)), - expected_result, op) - - def test_not_bb (self): - src1_data = (1, 2, 2, 3, 0x04, 0x50) - expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF) - op = gr.not_bb () - self.help_bb (((src1_data), ), - expected_result, op) - - def test_not_ii (self): - src1_data = (1, 2, 3, 0x50005004, 0x11001150) - expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150) - op = gr.not_ii () - self.help_ii (((src1_data),), - expected_result, op) - - - -if __name__ == '__main__': - gr_unittest.run(test_boolean_operators, "test_boolean_operators.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_conjugate.py b/gnuradio-core/src/python/gnuradio/gr/qa_conjugate.py deleted file mode 100644 index 17fa891e21..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_conjugate.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012 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. -# - -from gnuradio import gr, gr_unittest - -class test_conjugate (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_000 (self): - src_data = (-2-2j, -1-1j, -2+2j, -1+1j, - 2-2j, 1-1j, 2+2j, 1+1j, - 0+0j) - - exp_data = (-2+2j, -1+1j, -2-2j, -1-1j, - 2+2j, 1+1j, 2-2j, 1-1j, - 0-0j) - - src = gr.vector_source_c(src_data) - op = gr.conjugate_cc () - dst = gr.vector_sink_c () - - self.tb.connect(src, op) - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data () - self.assertEqual (exp_data, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_conjugate, "test_conjugate.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py deleted file mode 100755 index 057e297f91..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011,2012 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. -# - -from gnuradio import gr, gr_unittest -class test_float_to_char (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) - expected_result = [0, 1, 2, 3, 4, 5, 255, 254, 253] - src = gr.vector_source_f(src_data) - op = gr.float_to_char() - dst = gr.vector_sink_b() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - src_data = ( 126.0, 127.0, 128.0) - expected_result = [ 126, 127, 127 ] - - src = gr.vector_source_f(src_data) - op = gr.float_to_char() - # Note: vector_sink_b returns uchar - dst = gr.vector_sink_b() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_003(self): - - scale = 2 - vlen = 3 - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) - expected_result = [0, 2, 4, 6, 8, 11, 254, 252, 250] - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - op = gr.float_to_char(vlen, scale) - v2s = gr.vector_to_stream(gr.sizeof_char, vlen) - dst = gr.vector_sink_b() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_float_to_char, "test_float_to_char.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py deleted file mode 100755 index 5c7a412d2c..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python -# -# 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. -# - -from gnuradio import gr, gr_unittest - -class test_float_to_int (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3, -4.4, -5.5) - expected_result = [0, 1, 2, 3, 4, 6, -1, -2, -3, -4, -6] - - src = gr.vector_source_f(src_data) - op = gr.float_to_int() - dst = gr.vector_sink_i() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - src_data = ( 2147483647, 2147483648, 2200000000, - -2147483648, -2147483649, -2200000000) - expected_result = [ 2147483647, 2147483647, 2147483647, - -2147483647, -2147483647, -2147483647] - src = gr.vector_source_f(src_data) - op = gr.float_to_int() - dst = gr.vector_sink_i() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - - def test_003(self): - - scale = 2 - vlen = 3 - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) - expected_result = [0, 2, 4, 7, 9, 11, -2, -4, -7,] - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - op = gr.float_to_int(vlen, scale) - v2s = gr.vector_to_stream(gr.sizeof_int, vlen) - dst = gr.vector_sink_i() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_float_to_int, "test_float_to_int.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py deleted file mode 100755 index 3f8b66975f..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011,2012 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. -# - -from gnuradio import gr, gr_unittest -import ctypes - -class test_float_to_short (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3, -4.4, -5.5) - expected_result = [0, 1, 2, 3, 4, 6, -1, -2, -3, -4, -6] - - src = gr.vector_source_f(src_data) - op = gr.float_to_short() - dst = gr.vector_sink_s() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - src_data = ( 32766, 32767, 32768, - -32767, -32768, -32769) - expected_result = [ 32766, 32767, 32767, - -32767, -32768, -32768 ] - - src = gr.vector_source_f(src_data) - op = gr.float_to_short() - dst = gr.vector_sink_s() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_003(self): - - scale = 2 - vlen = 3 - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) - expected_result = [0, 2, 4, 7, 9, 11, -2, -4, -7] - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, vlen) - op = gr.float_to_short(vlen, scale) - v2s = gr.vector_to_stream(gr.sizeof_short, vlen) - dst = gr.vector_sink_s() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_float_to_short, "test_float_to_short.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_uchar.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_uchar.py deleted file mode 100755 index 831bed93ef..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_uchar.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# -# 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. -# - -from gnuradio import gr, gr_unittest -import ctypes - -class test_float_to_uchar (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3, -4.4, -5.5) - expected_result = [0, 1, 2, 3, 4, 6, 0, 0, 0, 0, 0] - src = gr.vector_source_f(src_data) - op = gr.float_to_uchar() - dst = gr.vector_sink_b() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - src_data = ( 254.0, 255.0, 256.0) - expected_result = [ 254, 255, 255 ] - src = gr.vector_source_f(src_data) - op = gr.float_to_uchar() - dst = gr.vector_sink_b() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_float_to_uchar, "test_float_to_uchar.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py b/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py index 3132d91b05..9ba48599af 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py @@ -1,6 +1,34 @@ #!/usr/bin/env python from gnuradio import gr, gr_unittest +import numpy + +class add_ff(gr.sync_block): + def __init__(self): + gr.sync_block.__init__( + self, + name = "add_ff", + in_sig = [numpy.float32, numpy.float32], + out_sig = [numpy.float32], + ) + + def work(self, input_items, output_items): + output_items[0][:] = input_items[0] + input_items[1] + return len(output_items[0]) + +class multiply_const_ff(gr.sync_block): + def __init__(self, k): + gr.sync_block.__init__( + self, + name = "multiply_ff", + in_sig = [numpy.float32], + out_sig = [numpy.float32], + ) + self.k = k + + def work(self, input_items, output_items): + output_items[0][:] = map(lambda x: self.k*x, input_items[0]) + return len(output_items[0]) class test_hier_block2(gr_unittest.TestCase): @@ -327,9 +355,9 @@ class test_hier_block2(gr_unittest.TestCase): hb = gr.hier_block2("hb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) - m1 = gr.multiply_const_ff(1.0) - m2 = gr.multiply_const_ff(2.0) - add = gr.add_ff() + m1 = multiply_const_ff(1.0) + m2 = multiply_const_ff(2.0) + add = add_ff() hb.connect(hb, m1) # m1 is connected to hb external input #0 hb.connect(hb, m2) # m2 is also connected to hb external input #0 hb.connect(m1, (add, 0)) @@ -350,9 +378,9 @@ class test_hier_block2(gr_unittest.TestCase): gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) - m1 = gr.multiply_const_ff(1.0) - m2 = gr.multiply_const_ff(2.0) - add = gr.add_ff() + m1 = multiply_const_ff(1.0) + m2 = multiply_const_ff(2.0) + add = add_ff() hb2.connect(hb2, m1) # m1 is connected to hb2 external input #0 hb2.connect(hb2, m2) # m2 is also connected to hb2 external input #0 hb2.connect(m1, (add, 0)) diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_int_to_float.py b/gnuradio-core/src/python/gnuradio/gr/qa_int_to_float.py deleted file mode 100755 index 7536b3820a..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_int_to_float.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -# 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. -# - -from gnuradio import gr, gr_unittest - -class test_int_to_float (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5) - expected_result = [float(s) for s in src_data] - src = gr.vector_source_i(src_data) - op = gr.int_to_float() - dst = gr.vector_sink_f() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = dst.data() - - self.assertFloatTuplesAlmostEqual(expected_result, result_data) - - def test_002(self): - - vlen = 3 - src_data = ( 65000, 65001, 65002, 65003, 65004, 65005, - -65001, -65002, -65003) - expected_result = [ 65000.0, 65001.0, 65002.0, - 65003.0, 65004.0, 65005.0, - -65001.0, -65002.0, -65003.0] - src = gr.vector_source_i(src_data) - s2v = gr.stream_to_vector(gr.sizeof_int, vlen) - op = gr.int_to_float(vlen) - v2s = gr.vector_to_stream(gr.sizeof_float, vlen) - dst = gr.vector_sink_f() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_int_to_float, "test_int_to_float.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_integrate.py b/gnuradio-core/src/python/gnuradio/gr/qa_integrate.py deleted file mode 100755 index ddb1310b69..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_integrate.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008,2010 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. -# - -from gnuradio import gr, gr_unittest -import math - -class test_integrate (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_000_ss(self): - src_data = (1, 2, 3, 4, 5, 6) - dst_data = (6, 15) - src = gr.vector_source_s(src_data) - itg = gr.integrate_ss(3) - dst = gr.vector_sink_s() - self.tb.connect(src, itg, dst) - self.tb.run() - self.assertEqual(dst_data, dst.data()) - - def test_001_ii(self): - src_data = (1, 2, 3, 4, 5, 6) - dst_data = (6, 15) - src = gr.vector_source_i(src_data) - itg = gr.integrate_ii(3) - dst = gr.vector_sink_i() - self.tb.connect(src, itg, dst) - self.tb.run() - self.assertEqual(dst_data, dst.data()) - - def test_002_ff(self): - src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] - dst_data = [6.0, 15.0] - src = gr.vector_source_f(src_data) - itg = gr.integrate_ff(3) - dst = gr.vector_sink_f() - self.tb.connect(src, itg, dst) - self.tb.run() - self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) - - def test_003_cc(self): - src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j] - dst_data = [6.0+6.0j, 15.0+15.0j] - src = gr.vector_source_c(src_data) - itg = gr.integrate_cc(3) - dst = gr.vector_sink_c() - self.tb.connect(src, itg, dst) - self.tb.run() - self.assertComplexTuplesAlmostEqual(dst_data, dst.data(), 6) - -if __name__ == '__main__': - gr_unittest.run(test_integrate, "test_integrate.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_interleave.py b/gnuradio-core/src/python/gnuradio/gr/qa_interleave.py deleted file mode 100755 index 1ff1782519..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_interleave.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,2010 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. -# - -from gnuradio import gr, gr_unittest -import math - -class test_interleave (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_int_001 (self): - lenx = 64 - src0 = gr.vector_source_f (range (0, lenx, 4)) - src1 = gr.vector_source_f (range (1, lenx, 4)) - src2 = gr.vector_source_f (range (2, lenx, 4)) - src3 = gr.vector_source_f (range (3, lenx, 4)) - op = gr.interleave (gr.sizeof_float) - dst = gr.vector_sink_f () - - self.tb.connect (src0, (op, 0)) - self.tb.connect (src1, (op, 1)) - self.tb.connect (src2, (op, 2)) - self.tb.connect (src3, (op, 3)) - self.tb.connect (op, dst) - self.tb.run () - expected_result = tuple (range (lenx)) - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_deint_001 (self): - lenx = 64 - src = gr.vector_source_f (range (lenx)) - op = gr.deinterleave (gr.sizeof_float) - dst0 = gr.vector_sink_f () - dst1 = gr.vector_sink_f () - dst2 = gr.vector_sink_f () - dst3 = gr.vector_sink_f () - - self.tb.connect (src, op) - self.tb.connect ((op, 0), dst0) - self.tb.connect ((op, 1), dst1) - self.tb.connect ((op, 2), dst2) - self.tb.connect ((op, 3), dst3) - self.tb.run () - - expected_result0 = tuple (range (0, lenx, 4)) - expected_result1 = tuple (range (1, lenx, 4)) - expected_result2 = tuple (range (2, lenx, 4)) - expected_result3 = tuple (range (3, lenx, 4)) - - self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ()) - self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ()) - self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ()) - self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ()) - -if __name__ == '__main__': - gr_unittest.run(test_interleave, "test_interleave.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py deleted file mode 100755 index 922671d024..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008,2010 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 this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -from gnuradio import gr, gr_unittest -import sys -import random - -class test_keep_m_in_n(gr_unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def test_001(self): - self.maxDiff = None; - tb = gr.top_block() - src = gr.vector_source_b( range(0,100) ) - - # itemsize, M, N, offset - km2 = gr.keep_m_in_n( 1, 1, 2, 0 ); - km3 = gr.keep_m_in_n( 1, 1, 3, 1 ); - km7 = gr.keep_m_in_n( 1, 1, 7, 2 ); - snk2 = gr.vector_sink_b(); - snk3 = gr.vector_sink_b(); - snk7 = gr.vector_sink_b(); - tb.connect(src,km2,snk2); - tb.connect(src,km3,snk3); - tb.connect(src,km7,snk7); - tb.run(); - - self.assertEqual(range(0,100,2), list(snk2.data())); - self.assertEqual(range(1,100,3), list(snk3.data())); - self.assertEqual(range(2,100,7), list(snk7.data())); - - -if __name__ == '__main__': - gr_unittest.run(test_keep_m_in_n, "test_keep_m_in_n.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_max.py b/gnuradio-core/src/python/gnuradio/gr/qa_max.py deleted file mode 100755 index f962df457d..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_max.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2007,2010 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. -# - -from gnuradio import gr, gr_unittest -import math - - -class test_max (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - - def tearDown (self): - self.tb = None - - - def test_001(self): - - src_data = (0,0.2,-0.3,0,12,0) - expected_result = (float(max(src_data)), ) - - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, len(src_data)) - op = gr.max_ff( len(src_data) ) - dst = gr.vector_sink_f() - - - self.tb.connect(src, s2v, op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(expected_result, result_data) - - def test_002(self): - - src_data=(-100,-99,-98,-97,-96,-1) - expected_result = (float(max(src_data)), ) - - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, len(src_data)) - op = gr.max_ff( len(src_data) ) - dst = gr.vector_sink_f() - - self.tb.connect(src, s2v, op, dst) - self.tb.run() - result_data = dst.data() - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_max, "test_max.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_multiply_conjugate.py b/gnuradio-core/src/python/gnuradio/gr/qa_multiply_conjugate.py deleted file mode 100644 index 1601a109e4..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_multiply_conjugate.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012 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. -# - -from gnuradio import gr, gr_unittest - -class test_multiply_conjugate (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_000 (self): - src_data0 = (-2-2j, -1-1j, -2+2j, -1+1j, - 2-2j, 1-1j, 2+2j, 1+1j, - 0+0j) - src_data1 = (-3-3j, -4-4j, -3+3j, -4+4j, - 3-3j, 4-4j, 3+3j, 4+4j, - 0+0j) - - exp_data = (12+0j, 8+0j, 12+0j, 8+0j, - 12+0j, 8+0j, 12+0j, 8+0j, - 0+0j) - src0 = gr.vector_source_c(src_data0) - src1 = gr.vector_source_c(src_data1) - op = gr.multiply_conjugate_cc () - dst = gr.vector_sink_c () - - self.tb.connect(src0, (op,0)) - self.tb.connect(src1, (op,1)) - self.tb.connect(op, dst) - self.tb.run() - result_data = dst.data () - self.assertEqual (exp_data, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_multiply_conjugate, "test_multiply_conjugate.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_nlog10.py b/gnuradio-core/src/python/gnuradio/gr/qa_nlog10.py deleted file mode 100755 index 239911851c..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_nlog10.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005,2007,2010 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. -# - -import sys, time, random, numpy -from gnuradio import gr, gr_unittest - -class test_nlog10(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - src_data = (-10, 0, 10, 100, 1000, 10000, 100000) - expected_result = (-180, -180, 10, 20, 30, 40, 50) - src = gr.vector_source_f(src_data) - op = gr.nlog10_ff(10) - dst = gr.vector_sink_f() - self.tb.connect (src, op, dst) - self.tb.run() - result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - -if __name__ == '__main__': - gr_unittest.run(test_nlog10, "test_nlog10.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pipe_fittings.py b/gnuradio-core/src/python/gnuradio/gr/qa_pipe_fittings.py deleted file mode 100755 index 1f24062b14..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pipe_fittings.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005,2007,2010 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. -# - -from gnuradio import gr, gr_unittest - -if 0: - import os - print "pid =", os.getpid() - raw_input("Attach, then press Enter to continue") - - -def calc_expected_result(src_data, n): - assert (len(src_data) % n) == 0 - result = [list() for x in range(n)] - #print "len(result) =", len(result) - for i in xrange(len(src_data)): - (result[i % n]).append(src_data[i]) - return [tuple(x) for x in result] - - -class test_pipe_fittings(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block () - - def tearDown(self): - self.tb = None - - def test_001(self): - """ - Test stream_to_streams. - """ - n = 8 - src_len = n * 8 - src_data = range(src_len) - - expected_results = calc_expected_result(src_data, n) - #print "expected results: ", expected_results - src = gr.vector_source_i(src_data) - op = gr.stream_to_streams(gr.sizeof_int, n) - self.tb.connect(src, op) - - dsts = [] - for i in range(n): - dst = gr.vector_sink_i() - self.tb.connect((op, i), (dst, 0)) - dsts.append(dst) - - self.tb.run() - - for d in range(n): - self.assertEqual(expected_results[d], dsts[d].data()) - - def test_002(self): - """ - Test streams_to_stream (using stream_to_streams). - """ - n = 8 - src_len = n * 8 - src_data = tuple(range(src_len)) - expected_results = src_data - - src = gr.vector_source_i(src_data) - op1 = gr.stream_to_streams(gr.sizeof_int, n) - op2 = gr.streams_to_stream(gr.sizeof_int, n) - dst = gr.vector_sink_i() - - self.tb.connect(src, op1) - for i in range(n): - self.tb.connect((op1, i), (op2, i)) - self.tb.connect(op2, dst) - - self.tb.run() - self.assertEqual(expected_results, dst.data()) - - def test_003(self): - """ - Test streams_to_vector (using stream_to_streams & vector_to_stream). - """ - n = 8 - src_len = n * 8 - src_data = tuple(range(src_len)) - expected_results = src_data - - src = gr.vector_source_i(src_data) - op1 = gr.stream_to_streams(gr.sizeof_int, n) - op2 = gr.streams_to_vector(gr.sizeof_int, n) - op3 = gr.vector_to_stream(gr.sizeof_int, n) - dst = gr.vector_sink_i() - - self.tb.connect(src, op1) - for i in range(n): - self.tb.connect((op1, i), (op2, i)) - self.tb.connect(op2, op3, dst) - - self.tb.run() - self.assertEqual(expected_results, dst.data()) - - def test_004(self): - """ - Test vector_to_streams. - """ - n = 8 - src_len = n * 8 - src_data = tuple(range(src_len)) - expected_results = src_data - - src = gr.vector_source_i(src_data) - op1 = gr.stream_to_vector(gr.sizeof_int, n) - op2 = gr.vector_to_streams(gr.sizeof_int, n) - op3 = gr.streams_to_stream(gr.sizeof_int, n) - dst = gr.vector_sink_i() - - self.tb.connect(src, op1, op2) - for i in range(n): - self.tb.connect((op2, i), (op3, i)) - self.tb.connect(op3, dst) - - self.tb.run() - self.assertEqual(expected_results, dst.data()) - -if __name__ == '__main__': - gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_probe_signal.py b/gnuradio-core/src/python/gnuradio/gr/qa_probe_signal.py deleted file mode 100644 index 4e10afdb64..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_probe_signal.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2012 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. -# - -import time - -from gnuradio import gr, gr_unittest - -class test_probe_signal (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block() - - def tearDown (self): - self.tb = None - - def test_001(self): - - value = 12.3 - repeats = 100 - src_data = [value] * repeats - - src = gr.vector_source_f(src_data) - dst = gr.probe_signal_f() - - self.tb.connect(src, dst) - self.tb.run() - output = dst.level() - self.assertAlmostEqual(value, output, places=6) - - def test_002(self): - - vector_length = 10 - repeats = 10 - value = [0.5+i for i in range(0, vector_length)] - src_data = value * repeats - - src = gr.vector_source_f(src_data) - s2v = gr.stream_to_vector(gr.sizeof_float, vector_length) - dst = gr.probe_signal_vf(vector_length) - - self.tb.connect(src, s2v, dst) - self.tb.run() - output = dst.level() - self.assertEqual(len(output), vector_length) - self.assertAlmostEqual(value[3], output[3], places=6) - -if __name__ == '__main__': - gr_unittest.run(test_probe_signal, "test_probe_signal.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_rational_resampler.py b/gnuradio-core/src/python/gnuradio/gr/qa_rational_resampler.py deleted file mode 100755 index cc963d7572..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_rational_resampler.py +++ /dev/null @@ -1,298 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005,2006,2007,2010 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. -# - -from gnuradio import gr, gr_unittest -from gnuradio import blks2 -import math -import random -import sys - -#import os -#print os.getpid() -#raw_input('Attach with gdb, then press Enter: ') - - -def random_floats(n): - r = [] - for x in xrange(n): - r.append(float(random.randint(-32768, 32768))) - return tuple(r) - - -def reference_dec_filter(src_data, decim, taps): - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.fir_filter_fff(decim, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - tb = None - return result_data - -def reference_interp_filter(src_data, interp, taps): - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.interp_fir_filter_fff(interp, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - tb = None - return result_data - -def reference_interp_dec_filter(src_data, interp, decim, taps): - tb = gr.top_block() - src = gr.vector_source_f(src_data) - up = gr.interp_fir_filter_fff(interp, (1,)) - dn = gr.fir_filter_fff(decim, taps) - dst = gr.vector_sink_f() - tb.connect(src, up, dn, dst) - tb.run() - result_data = dst.data() - tb = None - return result_data - - -class test_rational_resampler (gr_unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - # - # test the gr.rational_resampler_base primitives... - # - - def test_000_1_to_1(self): - taps = (-4, 5) - src_data = (234, -4, 23, -56, 45, 98, -23, -7) - xr = (-936, 1186, -112, 339, -460, -167, 582) - expected_result = tuple([float(x) for x in xr]) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(1, 1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - self.assertEqual(expected_result, result_data) - - def test_001_interp(self): - taps = [1, 10, 100, 1000, 10000] - src_data = (0, 2, 3, 5, 7, 11, 13, 17) - interpolation = 3 - xr = (0,0,0,0,2,20,200,2003,20030,300,3005,30050,500,5007,50070,700,7011,70110,1100,11013,110130,1300,13017,130170,1700.0,17000.0,170000.0) - expected_result = tuple([float(x) for x in xr]) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(interpolation, 1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - self.assertEqual(expected_result, result_data) - - def test_002_interp(self): - taps = random_floats(31) - #src_data = random_floats(10000) # FIXME the 10k case fails! - src_data = random_floats(1000) - interpolation = 3 - - expected_result = reference_interp_filter(src_data, interpolation, taps) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(interpolation, 1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - - L1 = len(result_data) - L2 = len(expected_result) - L = min(L1, L2) - if False: - sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' % - (L2 - L1, len(taps), interpolation, len(src_data))) - sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - (len(result_data), len(expected_result))) - #self.assertEqual(expected_result[0:L], result_data[0:L]) - # FIXME check first 3 answers - self.assertEqual(expected_result[3:L], result_data[3:L]) - - def test_003_interp(self): - taps = random_floats(31) - src_data = random_floats(10000) - decimation = 3 - - expected_result = reference_dec_filter(src_data, decimation, taps) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(1, decimation, taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - - L1 = len(result_data) - L2 = len(expected_result) - L = min(L1, L2) - if False: - sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % - (L2 - L1, len(taps), decimation, len(src_data))) - sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - (len(result_data), len(expected_result))) - self.assertEqual(expected_result[0:L], result_data[0:L]) - - # FIXME disabled. Triggers hang on SuSE 10.0 - def xtest_004_decim_random_vals(self): - MAX_TAPS = 9 - MAX_DECIM = 7 - OUTPUT_LEN = 9 - - random.seed(0) # we want reproducibility - - for ntaps in xrange(1, MAX_TAPS + 1): - for decim in xrange(1, MAX_DECIM+1): - for ilen in xrange(ntaps + decim, ntaps + OUTPUT_LEN*decim): - src_data = random_floats(ilen) - taps = random_floats(ntaps) - expected_result = reference_dec_filter(src_data, decim, taps) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(1, decim, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - tb = None - result_data = dst.data() - L1 = len(result_data) - L2 = len(expected_result) - L = min(L1, L2) - if False: - sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % (L2 - L1, ntaps, decim, ilen)) - sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - (len(result_data), len(expected_result))) - self.assertEqual(expected_result[0:L], result_data[0:L]) - - - # FIXME disabled. Triggers hang on SuSE 10.0 - def xtest_005_interp_random_vals(self): - MAX_TAPS = 9 - MAX_INTERP = 7 - INPUT_LEN = 9 - - random.seed(0) # we want reproducibility - - for ntaps in xrange(1, MAX_TAPS + 1): - for interp in xrange(1, MAX_INTERP+1): - for ilen in xrange(ntaps, ntaps + INPUT_LEN): - src_data = random_floats(ilen) - taps = random_floats(ntaps) - expected_result = reference_interp_filter(src_data, interp, taps) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(interp, 1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - tb = None - result_data = dst.data() - L1 = len(result_data) - L2 = len(expected_result) - L = min(L1, L2) - #if True or abs(L1-L2) > 1: - if False: - sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' % (L2 - L1, ntaps, interp, ilen)) - #sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - # (len(result_data), len(expected_result))) - #self.assertEqual(expected_result[0:L], result_data[0:L]) - # FIXME check first ntaps+1 answers - self.assertEqual(expected_result[ntaps+1:L], result_data[ntaps+1:L]) - - - def test_006_interp_decim(self): - taps = (0,1,0,0) - src_data = range(10000) - interp = 3 - decimation = 2 - - expected_result = reference_interp_dec_filter(src_data, interp, decimation, taps) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = gr.rational_resampler_base_fff(interp, decimation, taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - - L1 = len(result_data) - L2 = len(expected_result) - L = min(L1, L2) - if False: - sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % - (L2 - L1, len(taps), decimation, len(src_data))) - sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' % - (len(result_data), len(expected_result))) - self.assertEqual(expected_result[1:L], result_data[1:L]) - - # - # test the blks2.rational_resampler_??? primitives... - # - - def test_101_interp(self): - taps = [1, 10, 100, 1000, 10000] - src_data = (0, 2, 3, 5, 7, 11, 13, 17) - interpolation = 3 - xr = (0,0,0,0,2,20,200,2003,20030,300,3005,30050,500,5007,50070,700,7011,70110,1100,11013,110130,1300,13017,130170,1700.0,17000.0,170000.0) - expected_result = tuple([float(x) for x in xr]) - - tb = gr.top_block() - src = gr.vector_source_f(src_data) - op = blks2.rational_resampler_fff(interpolation, 1, taps=taps) - dst = gr.vector_sink_f() - tb.connect(src, op) - tb.connect(op, dst) - tb.run() - result_data = dst.data() - self.assertEqual(expected_result, result_data) - - -if __name__ == '__main__': - pass - # FIXME: Disabled, see ticket:210 - # gr_unittest.run(test_rational_resampler, "test_rational_resampler.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py b/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py deleted file mode 100755 index 116f37115a..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008,2010 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. -# - -from gnuradio import gr, gr_unittest -import math - -class test_repeat (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001_float(self): - src_data = [n*1.0 for n in range(100)]; - dst_data = [] - for n in range(100): - dst_data += [1.0*n, 1.0*n, 1.0*n] - - src = gr.vector_source_f(src_data) - rpt = gr.repeat(gr.sizeof_float, 3) - dst = gr.vector_sink_f() - self.tb.connect(src, rpt, dst) - self.tb.run() - self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6) - -if __name__ == '__main__': - gr_unittest.run(test_repeat, "test_repeat.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py deleted file mode 100755 index 490b149c7c..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011,2012 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. -# - -from gnuradio import gr, gr_unittest -import ctypes - -class test_short_to_char (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = range(0, 32767, 32767/127) - src_data = [int(s) for s in src_data] - expected_result = range(0, 128) - src = gr.vector_source_s(src_data) - op = gr.short_to_char() - dst = gr.vector_sink_b() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - vlen = 3 - src_data = range(0, 32400, 32767/127) - src_data = [int(s) for s in src_data] - expected_result = range(0, 126) - src = gr.vector_source_s(src_data) - s2v = gr.stream_to_vector(gr.sizeof_short, vlen) - op = gr.short_to_char(vlen) - v2s = gr.vector_to_stream(gr.sizeof_char, vlen) - dst = gr.vector_sink_b() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_short_to_char, "test_short_to_char.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py deleted file mode 100755 index 130f034ec3..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2011,2012 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. -# - -from gnuradio import gr, gr_unittest -import ctypes - -class test_short_to_float (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - - src_data = (0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5) - expected_result = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, - -1.0, -2.0, -3.0, -4.0, -5.0] - - src = gr.vector_source_s(src_data) - op = gr.short_to_float() - dst = gr.vector_sink_f() - - self.tb.connect(src, op, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - - def test_002(self): - - vlen = 3 - src_data = (0, 1, 2, 3, 4, 5, -1, -2, -3) - expected_result = [0.0, 1.0, 2.0, 3.0, 4.0, - 5.0, -1.0, -2.0, -3.0] - src = gr.vector_source_s(src_data) - s2v = gr.stream_to_vector(gr.sizeof_short, vlen) - op = gr.short_to_float(vlen) - v2s = gr.vector_to_stream(gr.sizeof_float, vlen) - dst = gr.vector_sink_f() - - self.tb.connect(src, s2v, op, v2s, dst) - self.tb.run() - result_data = list(dst.data()) - - self.assertEqual(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_short_to_float, "test_short_to_float.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_stream_mux.py b/gnuradio-core/src/python/gnuradio/gr/qa_stream_mux.py deleted file mode 100755 index 779d0b25e3..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_stream_mux.py +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2005,2007,2010 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. -# - -from gnuradio import gr, gr_unittest - -class test_stream_mux (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def help_stream_2ff(self, N, stream_sizes): - v0 = gr.vector_source_f(N*[1,], False) - v1 = gr.vector_source_f(N*[2,], False) - - mux = gr.stream_mux(gr.sizeof_float, stream_sizes) - - dst = gr.vector_sink_f () - - self.tb.connect (v0, (mux,0)) - self.tb.connect (v1, (mux,1)) - self.tb.connect (mux, dst) - self.tb.run () - - return dst.data () - - def help_stream_ramp_2ff(self, N, stream_sizes): - r1 = range(N) - r2 = range(N) - r2.reverse() - - v0 = gr.vector_source_f(r1, False) - v1 = gr.vector_source_f(r2, False) - - mux = gr.stream_mux(gr.sizeof_float, stream_sizes) - - dst = gr.vector_sink_f () - - self.tb.connect (v0, (mux,0)) - self.tb.connect (v1, (mux,1)) - self.tb.connect (mux, dst) - self.tb.run () - - return dst.data () - - def test_stream_2NN_ff(self): - N = 40 - stream_sizes = [10, 10] - result_data = self.help_stream_2ff(N, stream_sizes) - - exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0) - self.assertEqual (exp_data, result_data) - - def test_stream_ramp_2NN_ff(self): - N = 40 - stream_sizes = [10, 10] - result_data = self.help_stream_ramp_2ff(N, stream_sizes) - - exp_data = ( 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, - 39.0, 38.0, 37.0, 36.0, 35.0, 34.0, 33.0, 32.0, 31.0, 30.0, - 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, - 29.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0, 20.0, - 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, - 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, - 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, - 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0) - self.assertEqual (exp_data, result_data) - - def test_stream_2NM_ff(self): - N = 40 - stream_sizes = [7, 9] - self.help_stream_2ff(N, stream_sizes) - - result_data = self.help_stream_2ff(N, stream_sizes) - - exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0) - - self.assertEqual (exp_data, result_data) - - - def test_stream_2MN_ff(self): - N = 37 - stream_sizes = [7, 9] - self.help_stream_2ff(N, stream_sizes) - - result_data = self.help_stream_2ff(N, stream_sizes) - - exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 2.0) - - self.assertEqual (exp_data, result_data) - - def test_stream_2N0_ff(self): - N = 30 - stream_sizes = [7, 0] - self.help_stream_2ff(N, stream_sizes) - - result_data = self.help_stream_2ff(N, stream_sizes) - - exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0) - - self.assertEqual (exp_data, result_data) - - def test_stream_20N_ff(self): - N = 30 - stream_sizes = [0, 9] - self.help_stream_2ff(N, stream_sizes) - - result_data = self.help_stream_2ff(N, stream_sizes) - - exp_data = (2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, - 2.0, 2.0, 2.0) - - self.assertEqual (exp_data, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_stream_mux, "test_stream_mux.xml") diff --git a/gnuradio-core/src/python/gnuradio/optfir.py b/gnuradio-core/src/python/gnuradio/optfir.py deleted file mode 100644 index bbd48dae75..0000000000 --- a/gnuradio-core/src/python/gnuradio/optfir.py +++ /dev/null @@ -1,359 +0,0 @@ -# -# Copyright 2004,2005,2009 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. -# - -''' -Routines for designing optimal FIR filters. - -For a great intro to how all this stuff works, see section 6.6 of -"Digital Signal Processing: A Practical Approach", Emmanuael C. Ifeachor -and Barrie W. Jervis, Adison-Wesley, 1993. ISBN 0-201-54413-X. -''' - -import math, cmath -from gnuradio import gr - -remez = gr.remez - -def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, - nextra_taps=2): - """ - Builds a low pass filter. - - Args: - gain: Filter gain in the passband (linear) - Fs: Sampling rate (sps) - freq1: End of pass band (in Hz) - freq2: Start of stop band (in Hz) - passband_ripple_db: Pass band ripple in dB (should be small, < 1) - stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) - nextra_taps: Extra taps to use in the filter (default=2) - """ - passband_dev = passband_ripple_to_dev (passband_ripple_db) - stopband_dev = stopband_atten_to_dev (stopband_atten_db) - desired_ampls = (gain, 0) - (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls, - [passband_dev, stopband_dev], Fs) - # The remezord typically under-estimates the filter order, so add 2 taps by default - taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass") - return taps - -def band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=2): - """ - Builds a band pass filter. - - Args: - gain: Filter gain in the passband (linear) - Fs: Sampling rate (sps) - freq_sb1: End of stop band (in Hz) - freq_pb1: Start of pass band (in Hz) - freq_pb2: End of pass band (in Hz) - freq_sb2: Start of stop band (in Hz) - passband_ripple_db: Pass band ripple in dB (should be small, < 1) - stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) - nextra_taps: Extra taps to use in the filter (default=2) - """ - passband_dev = passband_ripple_to_dev (passband_ripple_db) - stopband_dev = stopband_atten_to_dev (stopband_atten_db) - desired_ampls = (0, gain, 0) - desired_freqs = [freq_sb1, freq_pb1, freq_pb2, freq_sb2] - desired_ripple = [stopband_dev, passband_dev, stopband_dev] - (n, fo, ao, w) = remezord (desired_freqs, desired_ampls, - desired_ripple, Fs) - # The remezord typically under-estimates the filter order, so add 2 taps by default - taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass") - return taps - - -def complex_band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=2): - """ - Builds a band pass filter with complex taps by making an LPF and - spinning it up to the right center frequency - - Args: - gain: Filter gain in the passband (linear) - Fs: Sampling rate (sps) - freq_sb1: End of stop band (in Hz) - freq_pb1: Start of pass band (in Hz) - freq_pb2: End of pass band (in Hz) - freq_sb2: Start of stop band (in Hz) - passband_ripple_db: Pass band ripple in dB (should be small, < 1) - stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) - nextra_taps: Extra taps to use in the filter (default=2) - """ - center_freq = (freq_pb2 + freq_pb1) / 2.0 - lp_pb = (freq_pb2 - center_freq)/1.0 - lp_sb = freq_sb2 - center_freq - lptaps = low_pass(gain, Fs, lp_pb, lp_sb, passband_ripple_db, - stopband_atten_db, nextra_taps) - spinner = [cmath.exp(2j*cmath.pi*center_freq/Fs*i) for i in xrange(len(lptaps))] - taps = [s*t for s,t in zip(spinner, lptaps)] - return taps - - -def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=2): - """ - Builds a band reject filter - spinning it up to the right center frequency - - Args: - gain: Filter gain in the passband (linear) - Fs: Sampling rate (sps) - freq_pb1: End of pass band (in Hz) - freq_sb1: Start of stop band (in Hz) - freq_sb2: End of stop band (in Hz) - freq_pb2: Start of pass band (in Hz) - passband_ripple_db: Pass band ripple in dB (should be small, < 1) - stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) - nextra_taps: Extra taps to use in the filter (default=2) - """ - passband_dev = passband_ripple_to_dev (passband_ripple_db) - stopband_dev = stopband_atten_to_dev (stopband_atten_db) - desired_ampls = (gain, 0, gain) - desired_freqs = [freq_pb1, freq_sb1, freq_sb2, freq_pb2] - desired_ripple = [passband_dev, stopband_dev, passband_dev] - (n, fo, ao, w) = remezord (desired_freqs, desired_ampls, - desired_ripple, Fs) - # Make sure we use an odd number of taps - if((n+nextra_taps)%2 == 1): - n += 1 - # The remezord typically under-estimates the filter order, so add 2 taps by default - taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass") - return taps - - -def high_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, - nextra_taps=2): - """ - Builds a high pass filter. - - Args: - gain: Filter gain in the passband (linear) - Fs: Sampling rate (sps) - freq1: End of stop band (in Hz) - freq2: Start of pass band (in Hz) - passband_ripple_db: Pass band ripple in dB (should be small, < 1) - stopband_atten_db: Stop band attenuation in dB (should be large, >= 60) - nextra_taps: Extra taps to use in the filter (default=2) - """ - passband_dev = passband_ripple_to_dev (passband_ripple_db) - stopband_dev = stopband_atten_to_dev (stopband_atten_db) - desired_ampls = (0, 1) - (n, fo, ao, w) = remezord ([freq1, freq2], desired_ampls, - [stopband_dev, passband_dev], Fs) - # For a HPF, we need to use an odd number of taps - # In gr.remez, ntaps = n+1, so n must be even - if((n+nextra_taps)%2 == 1): - n += 1 - - # The remezord typically under-estimates the filter order, so add 2 taps by default - taps = gr.remez (n + nextra_taps, fo, ao, w, "bandpass") - return taps - -# ---------------------------------------------------------------- - -def stopband_atten_to_dev (atten_db): - """Convert a stopband attenuation in dB to an absolute value""" - return 10**(-atten_db/20) - -def passband_ripple_to_dev (ripple_db): - """Convert passband ripple spec expressed in dB to an absolute value""" - return (10**(ripple_db/20)-1)/(10**(ripple_db/20)+1) - -# ---------------------------------------------------------------- - -def remezord (fcuts, mags, devs, fsamp = 2): - ''' - FIR order estimator (lowpass, highpass, bandpass, mulitiband). - - (n, fo, ao, w) = remezord (f, a, dev) - (n, fo, ao, w) = remezord (f, a, dev, fs) - - (n, fo, ao, w) = remezord (f, a, dev) finds the approximate order, - normalized frequency band edges, frequency band amplitudes, and - weights that meet input specifications f, a, and dev, to use with - the remez command. - - * f is a sequence of frequency band edges (between 0 and Fs/2, where - Fs is the sampling frequency), and a is a sequence specifying the - desired amplitude on the bands defined by f. The length of f is - twice the length of a, minus 2. The desired function is - piecewise constant. - - * dev is a sequence the same size as a that specifies the maximum - allowable deviation or ripples between the frequency response - and the desired amplitude of the output filter, for each band. - - Use remez with the resulting order n, frequency sequence fo, - amplitude response sequence ao, and weights w to design the filter b - which approximately meets the specifications given by remezord - input parameters f, a, and dev: - - b = remez (n, fo, ao, w) - - (n, fo, ao, w) = remezord (f, a, dev, Fs) specifies a sampling frequency Fs. - - Fs defaults to 2 Hz, implying a Nyquist frequency of 1 Hz. You can - therefore specify band edges scaled to a particular applications - sampling frequency. - - In some cases remezord underestimates the order n. If the filter - does not meet the specifications, try a higher order such as n+1 - or n+2. - ''' - # get local copies - fcuts = fcuts[:] - mags = mags[:] - devs = devs[:] - - for i in range (len (fcuts)): - fcuts[i] = float (fcuts[i]) / fsamp - - nf = len (fcuts) - nm = len (mags) - nd = len (devs) - nbands = nm - - if nm != nd: - raise ValueError, "Length of mags and devs must be equal" - - if nf != 2 * (nbands - 1): - raise ValueError, "Length of f must be 2 * len (mags) - 2" - - for i in range (len (mags)): - if mags[i] != 0: # if not stopband, get relative deviation - devs[i] = devs[i] / mags[i] - - # separate the passband and stopband edges - f1 = fcuts[0::2] - f2 = fcuts[1::2] - - n = 0 - min_delta = 2 - for i in range (len (f1)): - if f2[i] - f1[i] < min_delta: - n = i - min_delta = f2[i] - f1[i] - - if nbands == 2: - # lowpass or highpass case (use formula) - l = lporder (f1[n], f2[n], devs[0], devs[1]) - else: - # bandpass or multipass case - # try different lowpasses and take the worst one that - # goes through the BP specs - l = 0 - for i in range (1, nbands-1): - l1 = lporder (f1[i-1], f2[i-1], devs[i], devs[i-1]) - l2 = lporder (f1[i], f2[i], devs[i], devs[i+1]) - l = max (l, l1, l2) - - n = int (math.ceil (l)) - 1 # need order, not length for remez - - # cook up remez compatible result - ff = [0] + fcuts + [1] - for i in range (1, len (ff) - 1): - ff[i] *= 2 - - aa = [] - for a in mags: - aa = aa + [a, a] - - max_dev = max (devs) - wts = [1] * len(devs) - for i in range (len (wts)): - wts[i] = max_dev / devs[i] - - return (n, ff, aa, wts) - -# ---------------------------------------------------------------- - -def lporder (freq1, freq2, delta_p, delta_s): - ''' - FIR lowpass filter length estimator. freq1 and freq2 are - normalized to the sampling frequency. delta_p is the passband - deviation (ripple), delta_s is the stopband deviation (ripple). - - Note, this works for high pass filters too (freq1 > freq2), but - doesnt work well if the transition is near f == 0 or f == fs/2 - - From Herrmann et al (1973), Practical design rules for optimum - finite impulse response filters. Bell System Technical J., 52, 769-99 - ''' - df = abs (freq2 - freq1) - ddp = math.log10 (delta_p) - dds = math.log10 (delta_s) - - a1 = 5.309e-3 - a2 = 7.114e-2 - a3 = -4.761e-1 - a4 = -2.66e-3 - a5 = -5.941e-1 - a6 = -4.278e-1 - - b1 = 11.01217 - b2 = 0.5124401 - - t1 = a1 * ddp * ddp - t2 = a2 * ddp - t3 = a4 * ddp * ddp - t4 = a5 * ddp - - dinf=((t1 + t2 + a3) * dds) + (t3 + t4 + a6) - ff = b1 + b2 * (ddp - dds) - n = dinf / df - ff * df + 1 - return n - - -def bporder (freq1, freq2, delta_p, delta_s): - ''' - FIR bandpass filter length estimator. freq1 and freq2 are - normalized to the sampling frequency. delta_p is the passband - deviation (ripple), delta_s is the stopband deviation (ripple). - - From Mintzer and Liu (1979) - ''' - df = abs (freq2 - freq1) - ddp = math.log10 (delta_p) - dds = math.log10 (delta_s) - - a1 = 0.01201 - a2 = 0.09664 - a3 = -0.51325 - a4 = 0.00203 - a5 = -0.57054 - a6 = -0.44314 - - t1 = a1 * ddp * ddp - t2 = a2 * ddp - t3 = a4 * ddp * ddp - t4 = a5 * ddp - - cinf = dds * (t1 + t2 + a3) + t3 + t4 + a6 - ginf = -14.6 * math.log10 (delta_p / delta_s) - 16.9 - n = cinf / df + ginf * df + 1 - return n - diff --git a/gnuradio-core/src/python/gnuradio/window.py b/gnuradio-core/src/python/gnuradio/window.py deleted file mode 100644 index 4a1d0c5161..0000000000 --- a/gnuradio-core/src/python/gnuradio/window.py +++ /dev/null @@ -1,180 +0,0 @@ -# -# Copyright 2004,2005,2009 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. -# - -''' -Routines for designing window functions. -''' - -import math -from gnuradio import gr - -def izero(x): - izeroepsilon = 1e-21 - halfx = x/2.0 - accum = u = n = 1 - while 1: - temp = halfx/n - n += 1 - temp *= temp - u *= temp - accum += u - if u >= IzeroEPSILON*sum: - break - return accum - -def midm1(fft_size): - return (fft_size - 1)/2 - -def midp1(fft_size): - return (fft_size+1)/2 - -def freq(fft_size): - return 2.0*math.pi/fft_size - -def rate(fft_size): - return 1.0/(fft_size >> 1) - -def expn(fft_size): - math.log(2.0)/(midn(fft_size) + 1.0) - -def hamming(fft_size): - window = [] - for index in xrange(fft_size): - window.append(0.54 - 0.46 * math.cos (2 * math.pi / fft_size * index)) # Hamming window - return window - -def hanning(fft_size): - window = [] - for index in xrange(fft_size): - window.append(0.5 - 0.5 * math.cos (2 * math.pi / fft_size * index)) # von Hann window - return window - -def welch(fft_size): - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - window[j] = window[index] = (1.0 - math.sqrt((index - midm1(fft_size)) / midp1(fft_size))) - j -= 1 - return window - -def parzen(fft_size): - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - window[j] = window[index] = (1.0 - math.abs((index - midm1(fft_size)) / midp1(fft_size))) - j -= 1 - return window - -def bartlett(fft_size): - mfrq = freq(fft_size) - angle = 0 - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - window[j] = window[index] = angle - angle += freq - j -= 1 - return window - -def blackman2(fft_size): - mfrq = freq(fft_size) - angle = 0 - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - cx = math.cos(angle) - window[j] = window[index] = (.34401 + (cx * (-.49755 + (cx * .15844)))) - angle += freq - j -= 1 - return window - -def blackman3(fft_size): - mfrq = freq(fft_size) - angle = 0 - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - cx = math.cos(angle) - window[j] = window[index] = (.21747 + (cx * (-.45325 + (cx * (.28256 - (cx * .04672)))))) - angle += freq - j -= 1 - return window - -def blackman4(fft_size): - mfrq = freq(fft_size) - angle = 0 - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - cx = math.cos(angle) - window[j] = window[index] = (.084037 + (cx * (-.29145 + (cx * (.375696 + (cx * (-.20762 + (cx * .041194)))))))) - angle += freq - j -= 1 - return window - -def exponential(fft_size): - expsum = 1.0 - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)+1): - window[j] = window[i] = (expsum - 1.0) - expsum *= expn(fft_size) - j -= 1 - return window - -def riemann(fft_size): - sr1 = freq(fft_size) - window = [0 for i in range(fft_size)] - j = fft_size-1 - for index in xrange(midn(fft_size)): - if index == midn(fft_size): - window[index] = window[j] = 1.0 - else: - cx = sr1*midn(fft_size) - index - window[index] = window[j] = math.sin(cx)/cx - j -= 1 - return window - -def kaiser(fft_size,beta): - ibeta = 1.0/izero(beta) - inm1 = 1.0/(fft_size) - window = [0 for i in range(fft_size)] - for index in xrange(fft_size): - window[index] = izero(beta*math.sqrt(1.0 - (index * inm1)*(index * inm1))) * ibeta - return window - -# Closure to generate functions to create cos windows - -def coswindow(coeffs): - def closure(fft_size): - window = [0] * fft_size - #print list(enumerate(coeffs)) - for w_index in range(fft_size): - for (c_index, coeff) in enumerate(coeffs): - window[w_index] += (-1)**c_index * coeff * math.cos(2.0*c_index*math.pi*(w_index+0.5)/(fft_size-1)) - return window - return closure - -blackmanharris = coswindow((0.35875,0.48829,0.14128,0.01168)) -nuttall = coswindow((0.3635819,0.4891775,0.1365995,0.0106411)) # Wikipedia calls this Blackman-Nuttall -nuttall_cfd = coswindow((0.355768,0.487396,0.144232,0.012604)) # Wikipedia calls this Nuttall, continuous first deriv -flattop = coswindow((1.0,1.93,1.29,0.388,0.032)) # Flat top window, coeffs from Wikipedia -rectangular = lambda fft_size: [1]*fft_size |