diff options
Diffstat (limited to 'gnuradio-core/src/python')
98 files changed, 2012 insertions, 8753 deletions
diff --git a/gnuradio-core/src/python/gnuradio/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/CMakeLists.txt index bf696e0d34..9b75f20f33 100644 --- a/gnuradio-core/src/python/gnuradio/CMakeLists.txt +++ b/gnuradio-core/src/python/gnuradio/CMakeLists.txt @@ -22,8 +22,10 @@ include(GrPython) add_subdirectory(gr) add_subdirectory(gru) add_subdirectory(gruimpl) -add_subdirectory(blks2) -add_subdirectory(blks2impl) + +if(ENABLE_GR_CTRLPORT) +add_subdirectory(ctrlport) +endif(ENABLE_GR_CTRLPORT) GR_PYTHON_INSTALL(FILES __init__.py @@ -31,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/__init__.py b/gnuradio-core/src/python/gnuradio/__init__.py index a4917cf64c..d55dac79db 100644 --- a/gnuradio-core/src/python/gnuradio/__init__.py +++ b/gnuradio-core/src/python/gnuradio/__init__.py @@ -1 +1,12 @@ -# make this a package +""" +GNU Radio is a free & open-source software development toolkit that provides signal processing blocks to implement software radios. It can be used with readily-available low-cost external RF hardware to create software-defined radios, or without hardware in a simulation-like environment. It is widely used in hobbyist, academic and commercial environments to support both wireless communications research and real-world radio systems. + +GNU Radio applications are primarily written using the Python programming language, while the supplied performance-critical signal-processing path is implemented in C++ using processor floating-point extensions, where available. Thus, the developer is able to implement real-time, high-throughput radio systems in a simple-to-use, rapid-application-development environment. + +While not primarily a simulation tool, GNU Radio does support development of signal processing algorithms using pre-recorded or generated data, avoiding the need for actual RF hardware. + +GNU Radio is licensed under the GNU General Public License (GPL) version 3. All of the code is copyright of the Free Software Foundation. +""" + +# This file makes gnuradio a package +# The docstring will be associated with the top level of the package. 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 2dfdc77f46..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2/__init__.py +++ /dev/null @@ -1,37 +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. -# - -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 61fcdda42d..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/CMakeLists.txt +++ /dev/null @@ -1,45 +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 - am_demod.py - channel_model.py - filterbank.py - fm_demod.py - fm_emph.py - logpwrfft.py - nbfm_rx.py - nbfm_tx.py - pfb_arb_resampler.py - pfb_channelizer.py - pfb_decimator.py - pfb_interpolator.py - rational_resampler.py - standard_squelch.py - stream_to_vector_decimator.py - wfm_rcv.py - wfm_rcv_fmdet.py - wfm_rcv_pll.py - wfm_tx.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/am_demod.py b/gnuradio-core/src/python/gnuradio/blks2impl/am_demod.py deleted file mode 100644 index 68d024565a..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/am_demod.py +++ /dev/null @@ -1,75 +0,0 @@ -# -# Copyright 2006,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, optfir - -class am_demod_cf(gr.hier_block2): - """ - Generalized AM demodulation block with audio filtering. - - This block demodulates a band-limited, complex down-converted AM - channel into the the original baseband signal, applying low pass - filtering to the audio output. It produces a float stream in the - range [-1.0, +1.0]. - - @param channel_rate: incoming sample rate of the AM baseband - @type sample_rate: integer - @param audio_decim: input to output decimation rate - @type audio_decim: integer - @param audio_pass: audio low pass filter passband frequency - @type audio_pass: float - @param audio_stop: audio low pass filter stop frequency - @type audio_stop: float - """ - def __init__(self, channel_rate, audio_decim, audio_pass, audio_stop): - gr.hier_block2.__init__(self, "am_demod_cf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Input signature - - MAG = gr.complex_to_mag() - DCR = gr.add_const_ff(-1.0) - - audio_taps = optfir.low_pass(0.5, # Filter gain - channel_rate, # Sample rate - audio_pass, # Audio passband - audio_stop, # Audio stopband - 0.1, # Passband ripple - 60) # Stopband attenuation - LPF = gr.fir_filter_fff(audio_decim, audio_taps) - - self.connect(self, MAG, DCR, LPF, self) - -class demod_10k0a3e_cf(am_demod_cf): - """ - AM demodulation block, 10 KHz channel. - - This block demodulates an AM channel conformant to 10K0A3E emission - standards, such as broadcast band AM transmissions. - - @param channel_rate: incoming sample rate of the AM baseband - @type sample_rate: integer - @param audio_decim: input to output decimation rate - @type audio_decim: integer - """ - def __init__(self, channel_rate, audio_decim): - am_demod_cf.__init__(self, channel_rate, audio_decim, - 5000, # Audio passband - 5500) # Audio stopband diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/channel_model.py b/gnuradio-core/src/python/gnuradio/blks2impl/channel_model.py deleted file mode 100644 index e5cd471df5..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/channel_model.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 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. -# - -from gnuradio import gr - -# This block is now a C++ hierarchical block, gr.channel_model -channel_model = gr.channel_model 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 08f1d450ba..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/filterbank.py +++ /dev/null @@ -1,169 +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 - - @param mpoints: number of freq bins/interpolation factor/subbands - @param 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 - - @param mpoints: number of freq bins/interpolation factor/subbands - @param 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/fm_demod.py b/gnuradio-core/src/python/gnuradio/blks2impl/fm_demod.py deleted file mode 100644 index 6bc0d7ed0d..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/fm_demod.py +++ /dev/null @@ -1,111 +0,0 @@ -# -# Copyright 2006,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, optfir -from gnuradio.blks2impl.fm_emph import fm_deemph -from math import pi - -class fm_demod_cf(gr.hier_block2): - """ - Generalized FM demodulation block with deemphasis and audio - filtering. - - This block demodulates a band-limited, complex down-converted FM - channel into the the original baseband signal, optionally applying - deemphasis. Low pass filtering is done on the resultant signal. It - produces an output float strem in the range of [-1.0, +1.0]. - - @param channel_rate: incoming sample rate of the FM baseband - @type sample_rate: integer - @param deviation: maximum FM deviation (default = 5000) - @type deviation: float - @param audio_decim: input to output decimation rate - @type audio_decim: integer - @param audio_pass: audio low pass filter passband frequency - @type audio_pass: float - @param audio_stop: audio low pass filter stop frequency - @type audio_stop: float - @param gain: gain applied to audio output (default = 1.0) - @type gain: float - @param tau: deemphasis time constant (default = 75e-6), specify 'None' - to prevent deemphasis - """ - def __init__(self, channel_rate, audio_decim, deviation, - audio_pass, audio_stop, gain=1.0, tau=75e-6): - gr.hier_block2.__init__(self, "fm_demod_cf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - k = channel_rate/(2*pi*deviation) - QUAD = gr.quadrature_demod_cf(k) - - audio_taps = optfir.low_pass(gain, # Filter gain - channel_rate, # Sample rate - audio_pass, # Audio passband - audio_stop, # Audio stopband - 0.1, # Passband ripple - 60) # Stopband attenuation - LPF = gr.fir_filter_fff(audio_decim, audio_taps) - - if tau is not None: - DEEMPH = fm_deemph(channel_rate, tau) - self.connect(self, QUAD, DEEMPH, LPF, self) - else: - self.connect(self, QUAD, LPF, self) - -class demod_20k0f3e_cf(fm_demod_cf): - """ - NBFM demodulation block, 20 KHz channels - - This block demodulates a complex, downconverted, narrowband FM - channel conforming to 20K0F3E emission standards, outputting - floats in the range [-1.0, +1.0]. - - @param sample_rate: incoming sample rate of the FM baseband - @type sample_rate: integer - @param audio_decim: input to output decimation rate - @type audio_decim: integer - """ - def __init__(self, channel_rate, audio_decim): - fm_demod_cf.__init__(self, channel_rate, audio_decim, - 5000, # Deviation - 3000, # Audio passband frequency - 4500) # Audio stopband frequency - -class demod_200kf3e_cf(fm_demod_cf): - """ - WFM demodulation block, mono. - - This block demodulates a complex, downconverted, wideband FM - channel conforming to 200KF3E emission standards, outputting - floats in the range [-1.0, +1.0]. - - @param sample_rate: incoming sample rate of the FM baseband - @type sample_rate: integer - @param audio_decim: input to output decimation rate - @type audio_decim: integer - """ - def __init__(self, channel_rate, audio_decim): - fm_demod_cf.__init__(self, channel_rate, audio_decim, - 75000, # Deviation - 15000, # Audio passband - 16000, # Audio stopband - 20.0) # Audio gain diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/fm_emph.py b/gnuradio-core/src/python/gnuradio/blks2impl/fm_emph.py deleted file mode 100644 index fc3f2d60d2..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/fm_emph.py +++ /dev/null @@ -1,151 +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 -import math - - -# -# 1 -# H(s) = ------- -# 1 + s -# -# tau is the RC time constant. -# critical frequency: w_p = 1/tau -# -# We prewarp and use the bilinear z-transform to get our IIR coefficients. -# See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis -# - -class fm_deemph(gr.hier_block2): - """ - FM Deemphasis IIR filter. - """ - - - def __init__(self, fs, tau=75e-6): - """ - @param fs: sampling frequency in Hz - @type fs: float - @param tau: Time constant in seconds (75us in US, 50us in EUR) - @type tau: float - """ - gr.hier_block2.__init__(self, "fm_deemph", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - w_p = 1/tau - w_pp = math.tan (w_p / (fs * 2)) # prewarped analog freq - - a1 = (w_pp - 1)/(w_pp + 1) - b0 = w_pp/(1 + w_pp) - b1 = b0 - - btaps = [b0, b1] - ataps = [1, a1] - - if 0: - print "btaps =", btaps - print "ataps =", ataps - global plot1 - plot1 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True) - - deemph = gr.iir_filter_ffd(btaps, ataps) - self.connect(self, deemph, self) - -# -# 1 + s*t1 -# H(s) = ---------- -# 1 + s*t2 -# -# I think this is the right transfer function. -# -# -# This fine ASCII rendition is based on Figure 5-15 -# in "Digital and Analog Communication Systems", Leon W. Couch II -# -# -# R1 -# +-----||------+ -# | | -# o------+ +-----+--------o -# | C1 | | -# +----/\/\/\/--+ \ -# / -# \ R2 -# / -# \ -# | -# o--------------------------+--------o -# -# f1 = 1/(2*pi*t1) = 1/(2*pi*R1*C) -# -# 1 R1 + R2 -# f2 = ------- = ------------ -# 2*pi*t2 2*pi*R1*R2*C -# -# t1 is 75us in US, 50us in EUR -# f2 should be higher than our audio bandwidth. -# -# -# The Bode plot looks like this: -# -# -# /---------------- -# / -# / <-- slope = 20dB/decade -# / -# -------------/ -# f1 f2 -# -# We prewarp and use the bilinear z-transform to get our IIR coefficients. -# See "Digital Signal Processing: A Practical Approach" by Ifeachor and Jervis -# - -class fm_preemph(gr.hier_block2): - """ - FM Preemphasis IIR filter. - """ - def __init__(self, fs, tau=75e-6): - """ - @param fs: sampling frequency in Hz - @type fs: float - @param tau: Time constant in seconds (75us in US, 50us in EUR) - @type tau: float - """ - - gr.hier_block2.__init__(self, "fm_deemph", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - # FIXME make this compute the right answer - - btaps = [1] - ataps = [1] - - if 0: - print "btaps =", btaps - print "ataps =", ataps - global plot2 - plot2 = gru.gnuplot_freqz (gru.freqz (btaps, ataps), fs, True) - - preemph = gr.iir_filter_ffd(btaps, ataps) - self.connect(self, preemph, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/logpwrfft.py b/gnuradio-core/src/python/gnuradio/blks2impl/logpwrfft.py deleted file mode 100644 index 6f7fc520fa..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/logpwrfft.py +++ /dev/null @@ -1,155 +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, window -from stream_to_vector_decimator import stream_to_vector_decimator -import math - -class _logpwrfft_base(gr.hier_block2): - """ - Create a log10(abs(fft)) stream chain, with real or complex input. - """ - - def __init__(self, sample_rate, fft_size, ref_scale, frame_rate, avg_alpha, average, win=None): - """ - Create an log10(abs(fft)) stream chain. - Provide access to the setting the filter and sample rate. - @param sample_rate Incoming stream sample rate - @param fft_size Number of FFT bins - @param ref_scale Sets 0 dB value input amplitude - @param frame_rate Output frame rate - @param avg_alpha FFT averaging (over time) constant [0.0-1.0] - @param average Whether to average [True, False] - @param win the window taps generation function - """ - gr.hier_block2.__init__(self, self._name, - gr.io_signature(1, 1, self._item_size), # Input signature - gr.io_signature(1, 1, gr.sizeof_float*fft_size)) # Output signature - - self._sd = stream_to_vector_decimator(item_size=self._item_size, - sample_rate=sample_rate, - vec_rate=frame_rate, - vec_len=fft_size) - - if win is None: win = window.blackmanharris - fft_window = win(fft_size) - fft = self._fft_block[0](fft_size, True, fft_window) - window_power = sum(map(lambda x: x*x, fft_window)) - - c2magsq = gr.complex_to_mag_squared(fft_size) - self._avg = gr.single_pole_iir_filter_ff(1.0, fft_size) - self._log = gr.nlog10_ff(10, fft_size, - -20*math.log10(fft_size) # Adjust for number of bins - -10*math.log10(window_power/fft_size) # Adjust for windowing loss - -20*math.log10(ref_scale/2)) # Adjust for reference scale - self.connect(self, self._sd, fft, c2magsq, self._avg, self._log, self) - - self._average = average - self._avg_alpha = avg_alpha - self.set_avg_alpha(avg_alpha) - self.set_average(average) - - def set_decimation(self, decim): - """ - Set the decimation on stream decimator. - @param decim the new decimation - """ - self._sd.set_decimation(decim) - - def set_vec_rate(self, vec_rate): - """ - Set the vector rate on stream decimator. - @param vec_rate the new vector rate - """ - self._sd.set_vec_rate(vec_rate) - - def set_sample_rate(self, sample_rate): - """ - Set the new sampling rate - @param sample_rate the new rate - """ - self._sd.set_sample_rate(sample_rate) - - def set_average(self, average): - """ - Set the averaging filter on/off. - @param average true to set averaging on - """ - self._average = average - if self._average: - self._avg.set_taps(self._avg_alpha) - else: - self._avg.set_taps(1.0) - - def set_avg_alpha(self, avg_alpha): - """ - Set the average alpha and set the taps if average was on. - @param avg_alpha the new iir filter tap - """ - self._avg_alpha = avg_alpha - self.set_average(self._average) - - def sample_rate(self): - """ - Return the current sample rate. - """ - return self._sd.sample_rate() - - def decimation(self): - """ - Return the current decimation. - """ - return self._sd.decimation() - - def frame_rate(self): - """ - Return the current frame rate. - """ - return self._sd.frame_rate() - - def average(self): - """ - Return whether or not averaging is being performed. - """ - return self._average - - def avg_alpha(self): - """ - Return averaging filter constant. - """ - return self._avg_alpha - -class logpwrfft_f(_logpwrfft_base): - """ - Create an fft block chain, with real input. - """ - _name = "logpwrfft_f" - _item_size = gr.sizeof_float - _fft_block = (gr.fft_vfc, ) - -class logpwrfft_c(_logpwrfft_base): - """ - Create an fft block chain, with complex input. - """ - _name = "logpwrfft_c" - _item_size = gr.sizeof_gr_complex - _fft_block = (gr.fft_vcc, ) - diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_rx.py b/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_rx.py deleted file mode 100644 index 8bcb47ae19..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_rx.py +++ /dev/null @@ -1,88 +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. -# - -import math -from gnuradio import gr, optfir -from gnuradio.blks2impl.fm_emph import fm_deemph -#from gnuradio.blks2impl.standard_squelch import standard_squelch - -class nbfm_rx(gr.hier_block2): - def __init__(self, audio_rate, quad_rate, tau=75e-6, max_dev=5e3): - """ - Narrow Band FM Receiver. - - Takes a single complex baseband input stream and produces a single - float output stream of audio sample in the range [-1, +1]. - - @param audio_rate: sample rate of audio stream, >= 16k - @type audio_rate: integer - @param quad_rate: sample rate of output stream - @type quad_rate: integer - @param tau: preemphasis time constant (default 75e-6) - @type tau: float - @param max_dev: maximum deviation in Hz (default 5e3) - @type max_dev: float - - quad_rate must be an integer multiple of audio_rate. - - Exported sub-blocks (attributes): - squelch - quad_demod - deemph - audio_filter - """ - - gr.hier_block2.__init__(self, "nbfm_rx", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - # FIXME audio_rate and quad_rate ought to be exact rationals - audio_rate = int(audio_rate) - quad_rate = int(quad_rate) - - if quad_rate % audio_rate != 0: - raise ValueError, "quad_rate is not an integer multiple of audio_rate" - - squelch_threshold = 20 # dB - #self.squelch = gr.simple_squelch_cc(squelch_threshold, 0.001) - - # FM Demodulator input: complex; output: float - k = quad_rate/(2*math.pi*max_dev) - self.quad_demod = gr.quadrature_demod_cf(k) - - # FM Deemphasis IIR filter - self.deemph = fm_deemph (quad_rate, tau=tau) - - # compute FIR taps for audio filter - audio_decim = quad_rate // audio_rate - audio_taps = gr.firdes.low_pass (1.0, # gain - quad_rate, # sampling rate - 2.7e3, # Audio LPF cutoff - 0.5e3, # Transition band - gr.firdes.WIN_HAMMING) # filter type - - print "len(audio_taps) =", len(audio_taps) - - # Decimating audio filter - # input: float; output: float; taps: float - self.audio_filter = gr.fir_filter_fff(audio_decim, audio_taps) - - self.connect(self, self.quad_demod, self.deemph, self.audio_filter, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_tx.py b/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_tx.py deleted file mode 100644 index 839cf6784a..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/nbfm_tx.py +++ /dev/null @@ -1,92 +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. -# - -import math -from gnuradio import gr, optfir -from gnuradio.blks2impl.fm_emph import fm_preemph - -#from gnuradio import ctcss - -class nbfm_tx(gr.hier_block2): - def __init__(self, audio_rate, quad_rate, tau=75e-6, max_dev=5e3): - """ - Narrow Band FM Transmitter. - - Takes a single float input stream of audio samples in the range [-1,+1] - and produces a single FM modulated complex baseband output. - - @param audio_rate: sample rate of audio stream, >= 16k - @type audio_rate: integer - @param quad_rate: sample rate of output stream - @type quad_rate: integer - @param tau: preemphasis time constant (default 75e-6) - @type tau: float - @param max_dev: maximum deviation in Hz (default 5e3) - @type max_dev: float - - quad_rate must be an integer multiple of audio_rate. - """ - - gr.hier_block2.__init__(self, "nbfm_tx", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature - - # FIXME audio_rate and quad_rate ought to be exact rationals - audio_rate = int(audio_rate) - quad_rate = int(quad_rate) - - if quad_rate % audio_rate != 0: - raise ValueError, "quad_rate is not an integer multiple of audio_rate" - - - do_interp = audio_rate != quad_rate - - if do_interp: - interp_factor = quad_rate / audio_rate - interp_taps = optfir.low_pass (interp_factor, # gain - quad_rate, # Fs - 4500, # passband cutoff - 7000, # stopband cutoff - 0.1, # passband ripple dB - 40) # stopband atten dB - - #print "len(interp_taps) =", len(interp_taps) - self.interpolator = gr.interp_fir_filter_fff (interp_factor, interp_taps) - - self.preemph = fm_preemph (quad_rate, tau=tau) - - k = 2 * math.pi * max_dev / quad_rate - self.modulator = gr.frequency_modulator_fc (k) - - if do_interp: - self.connect (self, self.interpolator, self.preemph, self.modulator, self) - else: - self.connect(self, self.preemph, self.modulator, self) - - -class ctcss_gen_f(gr.hier_block2): - def __init__(self, sample_rate, tone_freq): - gr.hier_block2.__init__(self, "ctcss_gen_f", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - self.plgen = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, tone_freq, 0.1, 0.0) - self.connect(self.plgen, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py deleted file mode 100644 index e83c327fc8..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_arb_resampler.py +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 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. -# - -from gnuradio import gr, optfir - -class pfb_arb_resampler_ccf(gr.hier_block2): - ''' - Convenience wrapper for the polyphase filterbank arbitrary resampler. - - The block takes a single complex stream in and outputs a single complex - stream out. As such, it requires no extra glue to handle the input/output - streams. This block is provided to be consistent with the interface to the - other PFB block. - ''' - def __init__(self, rate, taps=None, flt_size=32, atten=100): - gr.hier_block2.__init__(self, "pfb_arb_resampler_ccf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature - - self._rate = rate - self._size = flt_size - - if taps is not None: - self._taps = taps - else: - # Create a filter that covers the full bandwidth of the input signal - bw = 0.4 - tb = 0.2 - ripple = 0.1 - #self._taps = gr.firdes.low_pass_2(self._size, self._size, bw, tb, atten) - made = False - while not made: - try: - self._taps = optfir.low_pass(self._size, self._size, bw, bw+tb, ripple, atten) - made = True - except RuntimeError: - ripple += 0.01 - made = False - print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple)) - - # Build in an exit strategy; if we've come this far, it ain't working. - if(ripple >= 1.0): - raise RuntimeError("optfir could not generate an appropriate filter.") - - self.pfb = gr.pfb_arb_resampler_ccf(self._rate, self._taps, self._size) - #print "PFB has %d taps\n" % (len(self._taps),) - - self.connect(self, self.pfb) - self.connect(self.pfb, self) - - # Note -- set_taps not implemented in base class yet - def set_taps(self, taps): - self.pfb.set_taps(taps) - - def set_rate(self, rate): - self.pfb.set_rate(rate) - - -class pfb_arb_resampler_fff(gr.hier_block2): - ''' - Convenience wrapper for the polyphase filterbank arbitrary resampler. - - The block takes a single float stream in and outputs a single float - stream out. As such, it requires no extra glue to handle the input/output - streams. This block is provided to be consistent with the interface to the - other PFB block. - ''' - def __init__(self, rate, taps=None, flt_size=32, atten=100): - gr.hier_block2.__init__(self, "pfb_arb_resampler_fff", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - self._rate = rate - self._size = flt_size - - if taps is not None: - self._taps = taps - else: - # Create a filter that covers the full bandwidth of the input signal - bw = 0.4 - tb = 0.2 - ripple = 0.1 - #self._taps = gr.firdes.low_pass_2(self._size, self._size, bw, tb, atten) - made = False - while not made: - try: - self._taps = optfir.low_pass(self._size, self._size, bw, bw+tb, ripple, atten) - made = True - except RuntimeError: - ripple += 0.01 - made = False - print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple)) - - # Build in an exit strategy; if we've come this far, it ain't working. - if(ripple >= 1.0): - raise RuntimeError("optfir could not generate an appropriate filter.") - - self.pfb = gr.pfb_arb_resampler_fff(self._rate, self._taps, self._size) - #print "PFB has %d taps\n" % (len(self._taps),) - - self.connect(self, self.pfb) - self.connect(self.pfb, self) - - # Note -- set_taps not implemented in base class yet - def set_taps(self, taps): - self.pfb.set_taps(taps) - - def set_rate(self, rate): - self.pfb.set_rate(rate) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py deleted file mode 100644 index 4bbe1bec6c..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2009,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, optfir - -class pfb_channelizer_ccf(gr.hier_block2): - ''' - Make a Polyphase Filter channelizer (complex in, complex out, floating-point taps) - - This simplifies the interface by allowing a single input stream to connect to this block. - It will then output a stream for each channel. - ''' - def __init__(self, numchans, taps=None, oversample_rate=1, atten=100): - gr.hier_block2.__init__(self, "pfb_channelizer_ccf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(numchans, numchans, gr.sizeof_gr_complex)) # Output signature - - self._nchans = numchans - self._oversample_rate = oversample_rate - - if taps is not None: - self._taps = taps - else: - # Create a filter that covers the full bandwidth of the input signal - bw = 0.4 - tb = 0.2 - ripple = 0.1 - made = False - while not made: - try: - self._taps = optfir.low_pass(1, self._nchans, bw, bw+tb, ripple, atten) - made = True - except RuntimeError: - ripple += 0.01 - made = False - print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple)) - - # Build in an exit strategy; if we've come this far, it ain't working. - if(ripple >= 1.0): - raise RuntimeError("optfir could not generate an appropriate filter.") - - self.s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, self._nchans) - self.pfb = gr.pfb_channelizer_ccf(self._nchans, self._taps, - self._oversample_rate) - self.connect(self, self.s2ss) - - for i in xrange(self._nchans): - self.connect((self.s2ss,i), (self.pfb,i)) - self.connect((self.pfb,i), (self,i)) - - def set_channel_map(self, newmap): - self.pfb.set_channel_map(newmap) - - diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py deleted file mode 100644 index adcdfe9ba1..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_decimator.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 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. -# - -from gnuradio import gr, optfir - -class pfb_decimator_ccf(gr.hier_block2): - ''' - Make a Polyphase Filter decimator (complex in, complex out, floating-point taps) - - This simplifies the interface by allowing a single input stream to connect to this block. - It will then output a stream that is the decimated output stream. - ''' - def __init__(self, decim, taps=None, channel=0, atten=100): - gr.hier_block2.__init__(self, "pfb_decimator_ccf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature - - self._decim = decim - self._channel = channel - - if taps is not None: - self._taps = taps - else: - # Create a filter that covers the full bandwidth of the input signal - bw = 0.4 - tb = 0.2 - ripple = 0.1 - made = False - while not made: - try: - self._taps = optfir.low_pass(1, self._decim, bw, bw+tb, ripple, atten) - made = True - except RuntimeError: - ripple += 0.01 - made = False - print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple)) - - # Build in an exit strategy; if we've come this far, it ain't working. - if(ripple >= 1.0): - raise RuntimeError("optfir could not generate an appropriate filter.") - - self.s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, self._decim) - self.pfb = gr.pfb_decimator_ccf(self._decim, self._taps, self._channel) - - self.connect(self, self.s2ss) - - for i in xrange(self._decim): - self.connect((self.s2ss,i), (self.pfb,i)) - - self.connect(self.pfb, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_interpolator.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_interpolator.py deleted file mode 100644 index 5492dfcac6..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_interpolator.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 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. -# - -from gnuradio import gr, optfir - -class pfb_interpolator_ccf(gr.hier_block2): - ''' - Make a Polyphase Filter interpolator (complex in, complex out, floating-point taps) - - The block takes a single complex stream in and outputs a single complex - stream out. As such, it requires no extra glue to handle the input/output - streams. This block is provided to be consistent with the interface to the - other PFB block. - ''' - def __init__(self, interp, taps=None, atten=100): - gr.hier_block2.__init__(self, "pfb_interpolator_ccf", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature - - self._interp = interp - self._taps = taps - - if taps is not None: - self._taps = taps - else: - # Create a filter that covers the full bandwidth of the input signal - bw = 0.4 - tb = 0.2 - ripple = 0.99 - made = False - while not made: - try: - self._taps = optfir.low_pass(self._interp, self._interp, bw, bw+tb, ripple, atten) - made = True - except RuntimeError: - ripple += 0.01 - made = False - print("Warning: set ripple to %.4f dB. If this is a problem, adjust the attenuation or create your own filter taps." % (ripple)) - - # Build in an exit strategy; if we've come this far, it ain't working. - if(ripple >= 1.0): - raise RuntimeError("optfir could not generate an appropriate filter.") - - self.pfb = gr.pfb_interpolator_ccf(self._interp, self._taps) - - self.connect(self, self.pfb) - self.connect(self.pfb, self) - - - - 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 eea12af958..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/rational_resampler.py +++ /dev/null @@ -1,131 +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 - -_plot = None - -def design_filter(interpolation, decimation, fractional_bw): - """ - Given the interpolation rate, decimation rate and a fractional bandwidth, - design a set of taps. - - @param interpolation: interpolation factor - @type interpolation: integer > 0 - @param decimation: decimation factor - @type decimation: integer > 0 - @param fractional_bw: fractional bandwidth in (0, 0.5) 0.4 works well. - @type fractional_bw: 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. - - @param interpolation: interpolation factor - @type interpolation: integer > 0 - @param decimation: decimation factor - @type decimation: integer > 0 - @param taps: optional filter coefficients - @type taps: sequence - @param fractional_bw: fractional bandwidth in (0, 0.5), measured at final freq (use 0.4) - @type fractional_bw: 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, gr.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, gr.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, gr.rational_resampler_base_ccc, - interpolation, decimation, taps, fractional_bw) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/standard_squelch.py b/gnuradio-core/src/python/gnuradio/blks2impl/standard_squelch.py deleted file mode 100644 index bd7fb535ae..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/standard_squelch.py +++ /dev/null @@ -1,76 +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 math -from gnuradio import gr, optfir - -class standard_squelch(gr.hier_block2): - def __init__(self, audio_rate): - gr.hier_block2.__init__(self, "standard_squelch", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - self.input_node = gr.add_const_ff(0) # FIXME kludge - - self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) - self.low_square = gr.multiply_ff() - self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant - - self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) - self.hi_square = gr.multiply_ff() - self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) - - self.sub = gr.sub_ff(); - self.add = gr.add_ff(); - self.gate = gr.threshold_ff(0.3,0.43,0) - self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) - - self.div = gr.divide_ff() - self.squelch_mult = gr.multiply_ff() - - self.connect (self, self.input_node) - self.connect (self.input_node, (self.squelch_mult, 0)) - - self.connect (self.input_node,self.low_iir) - self.connect (self.low_iir,(self.low_square,0)) - self.connect (self.low_iir,(self.low_square,1)) - self.connect (self.low_square,self.low_smooth,(self.sub,0)) - self.connect (self.low_smooth, (self.add,0)) - - self.connect (self.input_node,self.hi_iir) - self.connect (self.hi_iir,(self.hi_square,0)) - self.connect (self.hi_iir,(self.hi_square,1)) - self.connect (self.hi_square,self.hi_smooth,(self.sub,1)) - self.connect (self.hi_smooth, (self.add,1)) - - self.connect (self.sub, (self.div, 0)) - self.connect (self.add, (self.div, 1)) - self.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) - self.connect (self.squelch_mult, self) - - def set_threshold(self, threshold): - self.gate.set_hi(threshold) - - def threshold(self): - return self.gate.hi() - - def squelch_range(self): - return (0.0, 1.0, 1.0/100) 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 8f75729c91..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/stream_to_vector_decimator.py +++ /dev/null @@ -1,93 +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. - @param item_size the number of bytes per sample - @param sample_rate the rate of incoming samples - @param vec_rate the rate of outgoing vectors (same units as sample_rate) - @param 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. - @param 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. - @param vec_rate the new rate - """ - self._vec_rate = vec_rate - self._update_decimator() - - def set_decimation(self, decim): - """ - Set the decimation parameter directly. - @param 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/blks2impl/wfm_rcv.py b/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv.py deleted file mode 100644 index d1cbcf9127..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv.py +++ /dev/null @@ -1,69 +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 -from gnuradio.blks2impl.fm_emph import fm_deemph -import math - -class wfm_rcv(gr.hier_block2): - def __init__ (self, quad_rate, audio_decimation): - """ - Hierarchical block for demodulating a broadcast FM signal. - - The input is the downconverted complex baseband signal (gr_complex). - The output is the demodulated audio (float). - - @param quad_rate: input sample rate of complex baseband input. - @type quad_rate: float - @param audio_decimation: how much to decimate quad_rate to get to audio. - @type audio_decimation: integer - """ - gr.hier_block2.__init__(self, "wfm_rcv", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_float)) # Output signature - - volume = 20. - - max_dev = 75e3 - fm_demod_gain = quad_rate/(2*math.pi*max_dev) - audio_rate = quad_rate / audio_decimation - - - # We assign to self so that outsiders can grab the demodulator - # if they need to. E.g., to plot its output. - # - # input: complex; output: float - self.fm_demod = gr.quadrature_demod_cf (fm_demod_gain) - - # input: float; output: float - self.deemph = fm_deemph (audio_rate) - - # compute FIR filter taps for audio filter - width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0, # gain - quad_rate, # sampling rate - audio_rate/2 - width_of_transition_band, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - # input: float; output: float - self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - - self.connect (self, self.fm_demod, self.audio_filter, self.deemph, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_fmdet.py b/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_fmdet.py deleted file mode 100755 index e229bcc2e6..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_fmdet.py +++ /dev/null @@ -1,216 +0,0 @@ -# -# Copyright 2005,2006 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 -from gnuradio.blks2impl.fm_emph import fm_deemph -import math - -class wfm_rcv_fmdet(gr.hier_block2): - def __init__ (self, demod_rate, audio_decimation): - """ - Hierarchical block for demodulating a broadcast FM signal. - - The input is the downconverted complex baseband signal - (gr_complex). The output is two streams of the demodulated - audio (float) 0=Left, 1=Right. - - @param demod_rate: input sample rate of complex baseband input. - @type demod_rate: float - @param audio_decimation: how much to decimate demod_rate to get to audio. - @type audio_decimation: integer - """ - gr.hier_block2.__init__(self, "wfm_rcv_fmdet", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(2, 2, gr.sizeof_float)) # Output signature - lowfreq = -125e3/demod_rate - highfreq = 125e3/demod_rate - audio_rate = demod_rate / audio_decimation - - # We assign to self so that outsiders can grab the demodulator - # if they need to. E.g., to plot its output. - # - # input: complex; output: float - - self.fm_demod = gr.fmdet_cf (demod_rate, lowfreq, highfreq, 0.05) - - # input: float; output: float - self.deemph_Left = fm_deemph (audio_rate) - self.deemph_Right = fm_deemph (audio_rate) - - # compute FIR filter taps for audio filter - width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0 , # gain - demod_rate, # sampling rate - 15000 , - width_of_transition_band, - gr.firdes.WIN_HAMMING) - - # input: float; output: float - self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - if 1: - # Pick off the stereo carrier/2 with this filter. It - # attenuated 10 dB so apply 10 dB gain We pick off the - # negative frequency half because we want to base band by - # it! - ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO - ## DEEMPHASIS - - stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass(10.0, - demod_rate, - -19020, - -18980, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - - #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) - #print "stereo carrier filter ", stereo_carrier_filter_coeffs - #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate - - # Pick off the double side band suppressed carrier - # Left-Right audio. It is attenuated 10 dB so apply 10 dB - # gain - - stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass(20.0, - demod_rate, - 38000-15000/2, - 38000+15000/2, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) - #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs - - # construct overlap add filter system from coefficients - # for stereo carrier - self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, - stereo_carrier_filter_coeffs) - - # carrier is twice the picked off carrier so arrange to do - # a commplex multiply - self.stereo_carrier_generator = gr.multiply_cc(); - - # Pick off the rds signal - stereo_rds_filter_coeffs = gr.firdes.complex_band_pass(30.0, - demod_rate, - 57000 - 1500, - 57000 + 1500, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) - #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs - # construct overlap add filter system from coefficients for stereo carrier - - self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, - stereo_rds_filter_coeffs) - self.rds_carrier_generator = gr.multiply_cc(); - self.rds_signal_generator = gr.multiply_cc(); - self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex); - - loop_bw = 2*math.pi/100.0 - max_freq = -2.0*math.pi*18990/audio_rate; - min_freq = -2.0*math.pi*19010/audio_rate; - self.stereo_carrier_pll_recovery = gr.pll_refout_cc(loop_bw, - max_freq, - min_freq); - - #self.stereo_carrier_pll_recovery.squelch_enable(False) - ##pll_refout does not have squelch yet, so disabled for - #now - - # set up mixer (multiplier) to get the L-R signal at - # baseband - - self.stereo_basebander = gr.multiply_cc(); - - # pick off the real component of the basebanded L-R - # signal. The imaginary SHOULD be zero - - self.LmR_real = gr.complex_to_real(); - self.Make_Left = gr.add_ff(); - self.Make_Right = gr.sub_ff(); - - self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, - stereo_dsbsc_filter_coeffs) - - - if 1: - - # send the real signal to complex filter to pick off the - # carrier and then to one side of a multiplier - self.connect (self, self.fm_demod, self.stereo_carrier_filter, - self.stereo_carrier_pll_recovery, - (self.stereo_carrier_generator,0)) - - # send the already filtered carrier to the otherside of the carrier - # the resulting signal from this multiplier is the carrier - # with correct phase but at -38000 Hz. - self.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1)) - - # send the new carrier to one side of the mixer (multiplier) - self.connect (self.stereo_carrier_generator, (self.stereo_basebander,0)) - - # send the demphasized audio to the DSBSC pick off filter, the complex - # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier - # the result is BASEBANDED DSBSC with phase zero! - self.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1)) - - # Pick off the real part since the imaginary is - # theoretically zero and then to one side of a summer - self.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0)) - - #take the same real part of the DSBSC baseband signal and - #send it to negative side of a subtracter - self.connect (self.LmR_real,(self.Make_Right,1)) - - # Make rds carrier by taking the squared pilot tone and - # multiplying by pilot tone - self.connect (self.stereo_basebander,(self.rds_carrier_generator,0)) - self.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1)) - - # take signal, filter off rds, send into mixer 0 channel - self.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0)) - - # take rds_carrier_generator output and send into mixer 1 - # channel - self.connect (self.rds_carrier_generator,(self.rds_signal_generator,1)) - - # send basebanded rds signal and send into "processor" - # which for now is a null sink - self.connect (self.rds_signal_generator,self_rds_signal_processor) - - - if 1: - # pick off the audio, L+R that is what we used to have and - # send it to the summer - self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) - - # take the picked off L+R audio and send it to the PLUS - # side of the subtractor - self.connect(self.audio_filter,(self.Make_Right, 0)) - - # The result of Make_Left gets (L+R) + (L-R) and results in 2*L - # The result of Make_Right gets (L+R) - (L-R) and results in 2*R - self.connect(self.Make_Left , self.deemph_Left, (self, 0)) - self.connect(self.Make_Right, self.deemph_Right, (self, 1)) - - # NOTE: mono support will require variable number of outputs in hier_block2s - # See ticket:174 in Trac database - #else: - # self.connect (self.fm_demod, self.audio_filter, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_pll.py b/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_pll.py deleted file mode 100644 index d4ce6d2231..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_rcv_pll.py +++ /dev/null @@ -1,190 +0,0 @@ -# -# Copyright 2005,2006 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 -from gnuradio.blks2impl.fm_emph import fm_deemph -import math - -class wfm_rcv_pll(gr.hier_block2): - def __init__ (self, demod_rate, audio_decimation): - """ - Hierarchical block for demodulating a broadcast FM signal. - - The input is the downconverted complex baseband signal (gr_complex). - The output is two streams of the demodulated audio (float) 0=Left, 1=Right. - - @param demod_rate: input sample rate of complex baseband input. - @type demod_rate: float - @param audio_decimation: how much to decimate demod_rate to get to audio. - @type audio_decimation: integer - """ - gr.hier_block2.__init__(self, "wfm_rcv_pll", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(2, 2, gr.sizeof_float)) # Output signature - bandwidth = 250e3 - audio_rate = demod_rate / audio_decimation - - - # We assign to self so that outsiders can grab the demodulator - # if they need to. E.g., to plot its output. - # - # input: complex; output: float - loop_bw = 2*math.pi/100.0 - max_freq = 2.0*math.pi*90e3/demod_rate - self.fm_demod = gr.pll_freqdet_cf (loop_bw, max_freq,-max_freq) - - # input: float; output: float - self.deemph_Left = fm_deemph (audio_rate) - self.deemph_Right = fm_deemph (audio_rate) - - # compute FIR filter taps for audio filter - width_of_transition_band = audio_rate / 32 - audio_coeffs = gr.firdes.low_pass (1.0 , # gain - demod_rate, # sampling rate - 15000 , - width_of_transition_band, - gr.firdes.WIN_HAMMING) - # input: float; output: float - self.audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs) - if 1: - # Pick off the stereo carrier/2 with this filter. It attenuated 10 dB so apply 10 dB gain - # We pick off the negative frequency half because we want to base band by it! - ## NOTE THIS WAS HACKED TO OFFSET INSERTION LOSS DUE TO DEEMPHASIS - - stereo_carrier_filter_coeffs = gr.firdes.complex_band_pass(10.0, - demod_rate, - -19020, - -18980, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - - #print "len stereo carrier filter = ",len(stereo_carrier_filter_coeffs) - #print "stereo carrier filter ", stereo_carrier_filter_coeffs - #print "width of transition band = ",width_of_transition_band, " audio rate = ", audio_rate - - # Pick off the double side band suppressed carrier Left-Right audio. It is attenuated 10 dB so apply 10 dB gain - - stereo_dsbsc_filter_coeffs = gr.firdes.complex_band_pass(20.0, - demod_rate, - 38000-15000/2, - 38000+15000/2, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) - #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs - # construct overlap add filter system from coefficients for stereo carrier - - self.stereo_carrier_filter = gr.fir_filter_fcc(audio_decimation, stereo_carrier_filter_coeffs) - - # carrier is twice the picked off carrier so arrange to do a commplex multiply - - self.stereo_carrier_generator = gr.multiply_cc(); - - # Pick off the rds signal - - stereo_rds_filter_coeffs = gr.firdes.complex_band_pass(30.0, - demod_rate, - 57000 - 1500, - 57000 + 1500, - width_of_transition_band, - gr.firdes.WIN_HAMMING) - #print "len stereo dsbsc filter = ",len(stereo_dsbsc_filter_coeffs) - #print "stereo dsbsc filter ", stereo_dsbsc_filter_coeffs - # construct overlap add filter system from coefficients for stereo carrier - - self.rds_signal_filter = gr.fir_filter_fcc(audio_decimation, stereo_rds_filter_coeffs) - - - - - - - self.rds_carrier_generator = gr.multiply_cc(); - self.rds_signal_generator = gr.multiply_cc(); - self_rds_signal_processor = gr.null_sink(gr.sizeof_gr_complex); - - - - loop_bw = 2*math.pi/100.0 - max_freq = -2.0*math.pi*18990/audio_rate; - min_freq = -2.0*math.pi*19010/audio_rate; - - self.stereo_carrier_pll_recovery = gr.pll_refout_cc(loop_bw, max_freq, min_freq); - #self.stereo_carrier_pll_recovery.squelch_enable(False) #pll_refout does not have squelch yet, so disabled for now - - - # set up mixer (multiplier) to get the L-R signal at baseband - - self.stereo_basebander = gr.multiply_cc(); - - # pick off the real component of the basebanded L-R signal. The imaginary SHOULD be zero - - self.LmR_real = gr.complex_to_real(); - self.Make_Left = gr.add_ff(); - self.Make_Right = gr.sub_ff(); - - self.stereo_dsbsc_filter = gr.fir_filter_fcc(audio_decimation, stereo_dsbsc_filter_coeffs) - - - if 1: - - # send the real signal to complex filter to pick off the carrier and then to one side of a multiplier - self.connect (self, self.fm_demod,self.stereo_carrier_filter,self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,0)) - # send the already filtered carrier to the otherside of the carrier - self.connect (self.stereo_carrier_pll_recovery, (self.stereo_carrier_generator,1)) - # the resulting signal from this multiplier is the carrier with correct phase but at -38000 Hz. - - # send the new carrier to one side of the mixer (multiplier) - self.connect (self.stereo_carrier_generator, (self.stereo_basebander,0)) - # send the demphasized audio to the DSBSC pick off filter, the complex - # DSBSC signal at +38000 Hz is sent to the other side of the mixer/multiplier - self.connect (self.fm_demod,self.stereo_dsbsc_filter, (self.stereo_basebander,1)) - # the result is BASEBANDED DSBSC with phase zero! - - # Pick off the real part since the imaginary is theoretically zero and then to one side of a summer - self.connect (self.stereo_basebander, self.LmR_real, (self.Make_Left,0)) - #take the same real part of the DSBSC baseband signal and send it to negative side of a subtracter - self.connect (self.LmR_real,(self.Make_Right,1)) - - # Make rds carrier by taking the squared pilot tone and multiplying by pilot tone - self.connect (self.stereo_basebander,(self.rds_carrier_generator,0)) - self.connect (self.stereo_carrier_pll_recovery,(self.rds_carrier_generator,1)) - # take signal, filter off rds, send into mixer 0 channel - self.connect (self.fm_demod,self.rds_signal_filter,(self.rds_signal_generator,0)) - # take rds_carrier_generator output and send into mixer 1 channel - self.connect (self.rds_carrier_generator,(self.rds_signal_generator,1)) - # send basebanded rds signal and send into "processor" which for now is a null sink - self.connect (self.rds_signal_generator,self_rds_signal_processor) - - - if 1: - # pick off the audio, L+R that is what we used to have and send it to the summer - self.connect(self.fm_demod, self.audio_filter, (self.Make_Left, 1)) - # take the picked off L+R audio and send it to the PLUS side of the subtractor - self.connect(self.audio_filter,(self.Make_Right, 0)) - # The result of Make_Left gets (L+R) + (L-R) and results in 2*L - # The result of Make_Right gets (L+R) - (L-R) and results in 2*R - self.connect(self.Make_Left , self.deemph_Left, (self, 0)) - self.connect(self.Make_Right, self.deemph_Right, (self, 1)) - # NOTE: mono support will require variable number of outputs in hier_block2s - # See ticket:174 in Trac database - #else: - # self.connect (self.fm_demod, self.audio_filter, self) diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_tx.py b/gnuradio-core/src/python/gnuradio/blks2impl/wfm_tx.py deleted file mode 100644 index 3fcf98f891..0000000000 --- a/gnuradio-core/src/python/gnuradio/blks2impl/wfm_tx.py +++ /dev/null @@ -1,79 +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 math -from gnuradio import gr, optfir -from gnuradio.blks2impl.fm_emph import fm_preemph - -class wfm_tx(gr.hier_block2): - def __init__(self, audio_rate, quad_rate, tau=75e-6, max_dev=75e3): - """ - Wide Band FM Transmitter. - - Takes a single float input stream of audio samples in the range [-1,+1] - and produces a single FM modulated complex baseband output. - - @param audio_rate: sample rate of audio stream, >= 16k - @type audio_rate: integer - @param quad_rate: sample rate of output stream - @type quad_rate: integer - @param tau: preemphasis time constant (default 75e-6) - @type tau: float - @param max_dev: maximum deviation in Hz (default 75e3) - @type max_dev: float - - quad_rate must be an integer multiple of audio_rate. - """ - gr.hier_block2.__init__(self, "wfm_tx", - gr.io_signature(1, 1, gr.sizeof_float), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature - - # FIXME audio_rate and quad_rate ought to be exact rationals - audio_rate = int(audio_rate) - quad_rate = int(quad_rate) - - if quad_rate % audio_rate != 0: - raise ValueError, "quad_rate is not an integer multiple of audio_rate" - - - do_interp = audio_rate != quad_rate - - if do_interp: - interp_factor = quad_rate / audio_rate - interp_taps = optfir.low_pass (interp_factor, # gain - quad_rate, # Fs - 16000, # passband cutoff - 18000, # stopband cutoff - 0.1, # passband ripple dB - 40) # stopband atten dB - - print "len(interp_taps) =", len(interp_taps) - self.interpolator = gr.interp_fir_filter_fff (interp_factor, interp_taps) - - self.preemph = fm_preemph (quad_rate, tau=tau) - - k = 2 * math.pi * max_dev / quad_rate - self.modulator = gr.frequency_modulator_fc (k) - - if do_interp: - self.connect (self, self.interpolator, self.preemph, self.modulator, self) - else: - self.connect(self, self.preemph, self.modulator, self) diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/ctrlport/CMakeLists.txt new file mode 100644 index 0000000000..994e3a48cf --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/CMakeLists.txt @@ -0,0 +1,112 @@ +# 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. + +######################################################################## +include(GrPython) + +EXECUTE_PROCESS( + COMMAND ${ICE_SLICE2PY} -I${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime + --output-dir=${CMAKE_BINARY_DIR}/gnuradio-core/src/python + ${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime/gnuradio.ice +) + +EXECUTE_PROCESS( + COMMAND ${ICE_SLICE2PY} -I${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime + --output-dir=${CMAKE_BINARY_DIR}/gnuradio-core/src/python + ${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime/frontend.ice +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py + ${CMAKE_CURRENT_SOURCE_DIR}/IceRadioClient.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport/ + COMPONENT "core_python" +) + +# We don't want to install these in the root Python directory, but we +# aren't given a choice based on the way slice2py generates the +# information. +GR_PYTHON_INSTALL( + FILES + ${CMAKE_BINARY_DIR}/gnuradio-core/src/python/gnuradio_ice.py + ${CMAKE_BINARY_DIR}/gnuradio-core/src/python/frontend_ice.py + DESTINATION ${GR_PYTHON_DIR} + COMPONENT "core_python" +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/GNURadio/__init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport/GNURadio + COMPONENT "core_python" +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/GNURadio/Booter/__init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport/GNURadio/Booter + COMPONENT "core_python" +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/GNURadio/Frontend/__init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport/GNURadio/Frontend + COMPONENT "core_python" +) + +install( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/icon.png + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport + COMPONENT "core_python" +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/GrDataPlotter.py + ${CMAKE_CURRENT_SOURCE_DIR}/monitor.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/ctrlport/ + COMPONENT "core_python" +) + +GR_PYTHON_INSTALL( + FILES + ${CMAKE_CURRENT_SOURCE_DIR}/gr-ctrlport-monitor + ${CMAKE_CURRENT_SOURCE_DIR}/gr-ctrlport-curses + DESTINATION ${GR_RUNTIME_DIR} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + COMPONENT "core_python" +) + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_GR_CTRLPORT) + if(ENABLE_TESTING) + include(GrTest) + file(GLOB py_qa_test_files "qa_*.py") + foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + set(GR_TEST_TARGET_DEPS gruel gnuradio-core) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file}) + endforeach(py_qa_test_file) + endif(ENABLE_TESTING) +endif(ENABLE_GR_CTRLPORT) diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/GrDataPlotter.py b/gnuradio-core/src/python/gnuradio/ctrlport/GrDataPlotter.py new file mode 100644 index 0000000000..f33160aca2 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/GrDataPlotter.py @@ -0,0 +1,423 @@ +#!/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 +import sys, time + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +class GrDataPlotterC(gr.top_block): + def __init__(self, name, rate, pmin=None, pmax=None): + gr.top_block.__init__(self) + + self._name = name + self._npts = 500 + samp_rate = 1.0 + + self._last_data = self._npts*[0,] + self._data_len = 0 + + self.src = gr.vector_source_c([]) + self.thr = gr.throttle(gr.sizeof_gr_complex, rate) + self.snk = qtgui.time_sink_c(self._npts, samp_rate, + self._name, 1) + + if(pmin is not None or not pmax is None): + self.snk.set_y_axis(pmin, pmax) + + self.connect(self.src, self.thr, (self.snk, 0)) + + self.snk.set_line_label(0, "Real") + self.snk.set_line_label(1, "Imag") + + self.py_window = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) + + def __del__(self): + pass + + def qwidget(self): + return self.py_window + + def name(self): + return self._name + + def update(self, data): + # Ask GUI if there has been a change in nsamps + npts = self.snk.nsamps() + if(self._npts != npts): + + # Adjust buffers to accomodate new settings + if(npts < self._npts): + if(self._data_len < npts): + self._last_data = self._last_data[0:npts] + else: + self._last_data = self._last_data[self._data_len-npts:self._data_len] + self._data_len = npts + else: + self._last_data += (npts - self._npts)*[0,] + self._npts = npts + self.snk.reset() + + # Update the plot data depending on type + if(type(data) == list): + data_r = data[0::2] + data_i = data[1::2] + data = [complex(r,i) for r,i in zip(data_r, data_i)] + if(len(data) > self._npts): + self.src.set_data(data) + self._last_data = data[-self._npts:] + else: + newdata = self._last_data[-(self._npts-len(data)):] + newdata += data + self.src.set_data(newdata) + self._last_data = newdata + + else: # single value update + if(self._data_len < self._npts): + self._last_data[self._data_len] = data + self._data_len += 1 + else: + self._last_data = self._last_data[1:] + self._last_data.append(data) + self.src.set_data(self._last_data) + +class GrDataPlotterF(gr.top_block): + def __init__(self, name, rate, pmin=None, pmax=None): + gr.top_block.__init__(self) + + self._name = name + self._npts = 500 + samp_rate = 1.0 + + self._last_data = self._npts*[0,] + self._data_len = 0 + + self.src = gr.vector_source_f([]) + self.thr = gr.throttle(gr.sizeof_float, rate) + self.snk = qtgui.time_sink_f(self._npts, samp_rate, + self._name, 1) + + if(pmin is not None or not pmax is None): + self.snk.set_y_axis(pmin, pmax) + + self.connect(self.src, self.thr, (self.snk, 0)) + + self.py_window = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) + + def __del__(self): + pass + + def qwidget(self): + return self.py_window + + def name(self): + return self._name + + def update(self, data): + # Ask GUI if there has been a change in nsamps + npts = self.snk.nsamps() + if(self._npts != npts): + + # Adjust buffers to accomodate new settings + if(npts < self._npts): + if(self._data_len < npts): + self._last_data = self._last_data[0:npts] + else: + self._last_data = self._last_data[self._data_len-npts:self._data_len] + self._data_len = npts + else: + self._last_data += (npts - self._npts)*[0,] + self._npts = npts + self.snk.reset() + + # Update the plot data depending on type + if(type(data) == list): + if(len(data) > self._npts): + self.src.set_data(data) + self._last_data = data[-self._npts:] + else: + newdata = self._last_data[-(self._npts-len(data)):] + newdata += data + self.src.set_data(newdata) + self._last_data = newdata + + else: # single value update + if(self._data_len < self._npts): + self._last_data[self._data_len] = data + self._data_len += 1 + else: + self._last_data = self._last_data[1:] + self._last_data.append(data) + self.src.set_data(self._last_data) + + +class GrDataPlotterConst(gr.top_block): + def __init__(self, name, rate, pmin=None, pmax=None): + gr.top_block.__init__(self) + + self._name = name + self._npts = 500 + samp_rate = 1.0 + + self._last_data = self._npts*[0,] + self._data_len = 0 + + self.src = gr.vector_source_c([]) + self.thr = gr.throttle(gr.sizeof_gr_complex, rate) + self.snk = qtgui.const_sink_c(self._npts, + self._name, 1) + + if(pmin is not None or not pmax is None): + self.snk.set_x_axis(pmin, pmax) + self.snk.set_y_axis(pmin, pmax) + + self.connect(self.src, self.thr, (self.snk, 0)) + + self.py_window = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) + + def __del__(self): + pass + + def qwidget(self): + return self.py_window + + def name(self): + return self._name + + def update(self, data): + # Ask GUI if there has been a change in nsamps + npts = self.snk.nsamps() + if(self._npts != npts): + + # Adjust buffers to accomodate new settings + if(npts < self._npts): + if(self._data_len < npts): + self._last_data = self._last_data[0:npts] + else: + self._last_data = self._last_data[self._data_len-npts:self._data_len] + self._data_len = npts + else: + self._last_data += (npts - self._npts)*[0,] + self._npts = npts + self.snk.reset() + + # Update the plot data depending on type + if(type(data) == list): + data_r = data[0::2] + data_i = data[1::2] + data = [complex(r,i) for r,i in zip(data_r, data_i)] + if(len(data) > self._npts): + self.src.set_data(data) + self._last_data = data[-self._npts:] + else: + newdata = self._last_data[-(self._npts-len(data)):] + newdata += data + self.src.set_data(newdata) + self._last_data = newdata + + else: # single value update + if(self._data_len < self._npts): + self._last_data[self._data_len] = data + self._data_len += 1 + else: + self._last_data = self._last_data[1:] + self._last_data.append(data) + self.src.set_data(self._last_data) + + +class GrDataPlotterPsdC(gr.top_block): + def __init__(self, name, rate, pmin=None, pmax=None): + gr.top_block.__init__(self) + + self._name = name + self._samp_rate = 1.0 + self._fftsize = 2048 + self._wintype = gr.firdes.WIN_BLACKMAN_hARRIS + self._fc = 0 + + self._last_data = self._fftsize*[0,] + self._data_len = 0 + + self.src = gr.vector_source_c([]) + self.thr = gr.throttle(gr.sizeof_gr_complex, rate) + self.snk = qtgui.freq_sink_c(self._fftsize, self._wintype, + self._fc, self._samp_rate, + self._name, 1) + + if(pmin is not None or not pmax is None): + self.snk.set_y_axis(pmin, pmax) + + self.connect(self.src, self.thr, (self.snk, 0)) + + self.py_window = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) + + def __del__(self): + pass + + def qwidget(self): + return self.py_window + + def name(self): + return self._name + + def update(self, data): + # Ask GUI if there has been a change in nsamps + fftsize = self.snk.fft_size() + if(self._fftsize != fftsize): + + # Adjust buffers to accomodate new settings + if(fftsize < self._fftsize): + if(self._data_len < fftsize): + self._last_data = self._last_data[0:fftsize] + else: + self._last_data = self._last_data[self._data_len-fftsize:self._data_len] + self._data_len = fftsize + else: + self._last_data += (fftsize - self._fftsize)*[0,] + self._fftsize = fftsize + self.snk.reset() + + # Update the plot data depending on type + if(type(data) == list): + data_r = data[0::2] + data_i = data[1::2] + data = [complex(r,i) for r,i in zip(data_r, data_i)] + if(len(data) > self._fftsize): + self.src.set_data(data) + self._last_data = data[-self._fftsize:] + else: + newdata = self._last_data[-(self._fftsize-len(data)):] + newdata += data + self.src.set_data(newdata) + self._last_data = newdata + + else: # single value update + if(self._data_len < self._fftsize): + self._last_data[self._data_len] = data + self._data_len += 1 + else: + self._last_data = self._last_data[1:] + self._last_data.append(data) + self.src.set_data(self._last_data) + +class GrDataPlotterPsdF(gr.top_block): + def __init__(self, name, rate, pmin=None, pmax=None): + gr.top_block.__init__(self) + + self._name = name + self._samp_rate = 1.0 + self._fftsize = 2048 + self._wintype = gr.firdes.WIN_BLACKMAN_hARRIS + self._fc = 0 + + self._last_data = self._fftsize*[0,] + self._data_len = 0 + + self.src = gr.vector_source_f([]) + self.thr = gr.throttle(gr.sizeof_float, rate) + self.snk = qtgui.freq_sink_f(self._fftsize, self._wintype, + self._fc, self._samp_rate, + self._name, 1) + + if(pmin is not None or not pmax is None): + self.snk.set_y_axis(pmin, pmax) + + self.connect(self.src, self.thr, (self.snk, 0)) + + self.py_window = sip.wrapinstance(self.snk.pyqwidget(), QtGui.QWidget) + + def __del__(self): + pass + + def qwidget(self): + return self.py_window + + def name(self): + return self._name + + def update(self, data): + # Ask GUI if there has been a change in nsamps + fftsize = self.snk.fft_size() + if(self._fftsize != fftsize): + + # Adjust buffers to accomodate new settings + if(fftsize < self._fftsize): + if(self._data_len < fftsize): + self._last_data = self._last_data[0:fftsize] + else: + self._last_data = self._last_data[self._data_len-fftsize:self._data_len] + self._data_len = fftsize + else: + self._last_data += (fftsize - self._fftsize)*[0,] + self._fftsize = fftsize + self.snk.reset() + + # Update the plot data depending on type + if(type(data) == list): + data_r = data[0::2] + data_i = data[1::2] + data = [complex(r,i) for r,i in zip(data_r, data_i)] + if(len(data) > self._fftsize): + self.src.set_data(data) + self._last_data = data[-self._fftsize:] + else: + newdata = self._last_data[-(self._fftsize-len(data)):] + newdata += data + self.src.set_data(newdata) + self._last_data = newdata + + else: # single value update + if(self._data_len < self._fftsize): + self._last_data[self._data_len] = data + self._data_len += 1 + else: + self._last_data = self._last_data[1:] + self._last_data.append(data) + self.src.set_data(self._last_data) + + +class GrDataPlotterValueTable: + def __init__(self, uid, parent, x, y, xsize, ysize, + headers=['Statistic Key ( Source Block :: Stat Name ) ', + 'Curent Value', 'Units', 'Description']): + # must encapsulate, cuz Qt's bases are not classes + self.uid = uid + self.treeWidget = QtGui.QTreeWidget(parent) + self.treeWidget.setColumnCount(len(headers)) + self.treeWidget.setGeometry(x,y,xsize,ysize) + self.treeWidget.setHeaderLabels(headers) + self.treeWidget.resizeColumnToContents(0) + + def updateItems(self, knobs, knobprops): + items = []; + self.treeWidget.clear() + for k, v in knobs.iteritems(): + items.append(QtGui.QTreeWidgetItem([str(k), str(v.value), + knobprops[k].units, + knobprops[k].description])) + self.treeWidget.insertTopLevelItems(0, items) diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/IceRadioClient.py b/gnuradio-core/src/python/gnuradio/ctrlport/IceRadioClient.py new file mode 100644 index 0000000000..0964b5a4ba --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/IceRadioClient.py @@ -0,0 +1,102 @@ +#!/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 Ice, Glacier2 +from PyQt4 import QtGui, QtCore +import sys, time, Ice +from gnuradio import gr +from gnuradio.ctrlport import GNURadio + +class IceRadioClient(Ice.Application): + def __init__(self, parentClass): + self.parentClass = parentClass + + def getRadio(self, host, port): + radiostr = "gnuradio -t:tcp -h " + host + " -p " + port + " -t 3000" + base = self.communicator().stringToProxy(radiostr).ice_twoway() + radio = GNURadio.ControlPortPrx.checkedCast(base) + + if not radio: + sys.stderr.write("{0} : invalid proxy.\n".format(args[0])) + return None + + return radio + + def run(self,args): + if len(args) < 2: + print "useage: [glacierinstance glacierhost glacierport] host port" + return + if len(args) == 8: + self.useglacier = True + guser = args[1] + gpass = args[2] + ginst = args[3] + ghost = args[4] + gport = args[5] + host = args[6] + port = args[7] + else: + self.useglacier = False + host = args[1] + port = args[2] + + if self.useglacier: + gstring = ginst + "/router -t:tcp -h " + ghost + " -p " + gport + print "GLACIER: {0}".format(gstring) + + setrouter = Glacier2.RouterPrx.checkedCast(self.communicator().stringToProxy(gstring)) + self.communicator().setDefaultRouter(setrouter) + defaultRouter = self.communicator().getDefaultRouter() + #defaultRouter = self.communicator().stringToProxy(gstring) + if not defaultRouter: + print self.appName() + ": no default router set" + return 1 + else: + print str(defaultRouter) + router = Glacier2.RouterPrx.checkedCast(defaultRouter) + if not router: + print self.appName() + ": configured router is not a Glacier2 router" + return 1 + + while True: + print "This demo accepts any user-id / password combination." + if not guser == '' and not gpass == '': + id = guser + pw = gpass + else: + id = raw_input("user id: ") + pw = raw_input("password: ") + + try: + router.createSession(id, pw) + break + except Glacier2.PermissionDeniedException, ex: + print "permission denied:\n" + ex.reason + + radio = self.getRadio(host, port) + if(radio is None): + return 1 + + app = QtGui.QApplication(sys.argv) + ex = self.parentClass(radio, port, self) + ex.show(); + app.exec_() diff --git a/gnuradio-core/src/python/gnuradio/blks2/CMakeLists.txt b/gnuradio-core/src/python/gnuradio/ctrlport/__init__.py index 83d11dd831..031c3b424e 100644 --- a/gnuradio-core/src/python/gnuradio/blks2/CMakeLists.txt +++ b/gnuradio-core/src/python/gnuradio/ctrlport/__init__.py @@ -1,26 +1,30 @@ -# Copyright 2010-2011 Free Software Foundation, Inc. # +# 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# 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) +# The presence of this file turns this directory into a Python package + +import Ice, IcePy + +# import swig generated symbols into the ctrlport namespace +#from ctrlport_swig import * +from monitor import * -GR_PYTHON_INSTALL( - FILES __init__.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/blks2 - COMPONENT "core_python" -) +# import any pure python here +#import GNURadio diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-curses b/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-curses new file mode 100755 index 0000000000..1bee3b1a1e --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-curses @@ -0,0 +1,268 @@ +#!/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 threading +import curses +import os, sys, time +from optparse import OptionParser + +import Ice +from gnuradio.ctrlport import GNURadio + +ENTER = chr(10) +UP_ARROW = chr(65) +DOWN_ARROW = chr(66) + +class modem_monitor(threading.Thread): + def __init__(self, cb_live, cb_exit, interface): + threading.Thread.__init__(self) + self.cb_live = cb_live + self.cb_exit = cb_exit + + self.running = True + + def __del__(self): + rx.close() + + def run(self): + while self.running: + time.sleep(0.5) + + def shutdown(self): + self.running = False + self.rx.close() + + def cb(self,contents): + (op, sep, payload) = contents.partition(":") + if(op == "live"): + print "live" + self.cb_live(payload) + elif(op == "exit"): + self.cb_exit(payload) + else: + print "unknown op arrived! garbage on multicast adx?" + +class modem_window(threading.Thread): + def __init__(self, locator): + threading.Thread.__init__(self) + self.locator = locator + + # curses init + self.win = curses.newwin(30,100,4,4) + + # Ice/GRCP init + self.comm = Ice.initialize() + proxy = self.comm.stringToProxy(locator) + self.radio = GNURadio.ControlPortPrx.checkedCast(proxy) + self.updateKnobs() + + # GUI init + self.running = True + self.ssel = 0 + self.start() + #self.updateGUI() + + # input loop + while(self.running): + self.getInput() + + # wait for update thread exit + self.join() + + def updateKnobs(self): + self.knobs = self.radio.get([]) + + def getInput(self): + a = self.win.getch() + if(a <= 256): + a = chr(a) + if(a == 'q'): + self.running = False + elif(a == UP_ARROW): + self.ssel = max(self.ssel-1, 0) + self.updateGUI() + elif(a == DOWN_ARROW): + self.ssel = max(min(self.ssel+1, len(self.knobs.keys())-1),0) + self.updateGUI() + self.updateGUI() + + def updateGUI(self): + self.win.clear() + self.win.border(0) + self.win.addstr(1, 2, "Modem Statistics :: %s"%(self.locator)) + self.win.addstr(2, 2, "---------------------------------------------------") + + maxnb = 0 + maxk = 0 + for k in self.knobs.keys(): + (nb,k) = k.split("::", 2) + maxnb = max(maxnb,len(nb)) + maxk = max(maxk,len(k)) + + offset = 3 + keys = self.knobs.keys() + keys.sort() + for k in keys: + (nb,sk) = k.split("::", 2) + v = self.knobs[k].value + sv = str(v) + if(len(sv) > 20): + sv = sv[0:20] + props = 0 + if(self.ssel == offset-3): + props = props | curses.A_REVERSE + self.win.addstr(offset, 2, "%s %s %s" % \ + (nb.rjust(maxnb," "), sk.ljust(maxk," "), sv),props) + offset = offset + 1 + self.win.refresh() + + def run(self): + while(self.running): + self.updateKnobs() + self.updateGUI() + time.sleep(1) + +class monitor_gui: + def __init__(self, interfaces, options): + + locator = None + + # Extract options into a locator + if(options.host and options.port): + locator = "{0} -t:{1} -h {2} -p {3}".format( + options.app, options.protocol, + options.host, options.port) + + # Set up GUI + self.locators = {} + + self.mode = 0 # modem index screen (modal keyboard input) + self.lsel = 0 # selected locator + self.scr = curses.initscr() + self.updateGUI() + + # Kick off initial monitors + self.monitors = [] + for i in interfaces: + self.monitors.append( modem_monitor(self.addModem, self.delModem, i) ) + self.monitors[-1].start() + + if not ((locator == None) or (locator == "")): + self.addModem(locator) + + # wait for user input + while(True): + self.getInput() + + def addModem(self, locator): + if(not self.locators.has_key(locator)): + self.locators[locator] = {} + self.locators[locator]["update_time"] = time.time() + self.locators[locator]["status"] = "live" + + self.updateGUI(); + + def delModem(self, locator): + #if(self.locators.has_key(locator)): + if(not self.locators.has_key(locator)): + self.locators[locator] = {} + self.locators[locator]["update_time"] = time.time() + self.locators[locator]["status"] = "exit" + + self.updateGUI() + + def updateGUI(self): + if(self.mode == 0): #redraw locators + self.scr.clear() + self.scr.border(0) + self.scr.addstr(1, 2, " GRCP-Curses Modem Monitor :: (A)dd (R)efresh, (Q)uit, ...") + for i in range(len(self.locators.keys())): + locator = self.locators.keys()[i] + lhash = self.locators[locator] + #self.scr.addstr(3+i, 5, locator + str(lhash)) + props = 0 + if(self.lsel == i): + props = props | curses.A_REVERSE + self.scr.addstr(3+i, 5, locator + str(lhash), props) + self.scr.refresh() + + def connectGUI(self): + self.scr.clear() + self.scr.addstr(1, 1, "Connect to radio:") + locator = self.scr.getstr(200) + self.addModem(locator) + self.updateGUI() + + def getInput(self): + a = self.scr.getch() + self.scr.addstr(20, 2, "got key (%d) " % (int(a))) + if(a <= 256): + a = chr(a) + if(a =='r'): + self.updateGUI() + elif(a == 'q'): + self.shutdown() + elif(a == 'a'): + self.connectGUI() + elif(a == UP_ARROW): + self.lsel = max(self.lsel-1, 0) + self.updateGUI() + elif(a == DOWN_ARROW): + self.lsel = max(min(self.lsel+1, len(self.locators.keys())-1),0) + self.updateGUI() + elif(a == ENTER): + try: + locator = self.locators.keys()[self.lsel] + self.mode = 1 + mwin = modem_window(locator) + self.mode = 0 + # pop up a new modem display ... + self.updateGUI() + except: + pass + + def shutdown(self): + curses.endwin() + os._exit(0) + +if __name__ == "__main__": + parser = OptionParser() + parser.add_option("-H", "--host", type="string", + help="Hostname of ControlPort server.") + parser.add_option("-p", "--port", type="int", + help="Port number of host's ControlPort endpoint.") + parser.add_option("-i", "--interfaces", type="string", + action="append", default=["lo"], + help="Interfaces to use. [default=%default]") + parser.add_option("-P", "--protocol", type="string", default="tcp", + help="Type of protocol to use (usually tcp). [default=%default]") + parser.add_option("-a", "--app", type="string", default="gnuradio", + help="Name of application [default=%default]") + (options, args) = parser.parse_args() + + if((options.host == None) ^ (options.port == None)): + print "Please set both a hostname and a port number.\n" + parser.print_help() + sys.exit(1) + + mg = monitor_gui(options.interfaces, options) + diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-monitor b/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-monitor new file mode 100755 index 0000000000..241b8a2043 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/gr-ctrlport-monitor @@ -0,0 +1,581 @@ +#!/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, ctrlport + +from PyQt4 import QtCore,Qt +import PyQt4.QtGui as QtGui +import sys, time + +import Ice +from gnuradio.ctrlport.IceRadioClient import * +from gnuradio.ctrlport.GrDataPlotter import * +from gnuradio.ctrlport import GNURadio + +class MAINWindow(QtGui.QMainWindow): + def minimumSizeHint(self): + return Qtgui.QSize(800,600) + + def __init__(self, radio, port, interface): + + super(MAINWindow, self).__init__() + self.conns = [] + self.plots = [] + self.knobprops = [] + self.interface = interface + + self.mdiArea = QtGui.QMdiArea() + self.mdiArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) + self.mdiArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) + self.setCentralWidget(self.mdiArea) + + self.mdiArea.subWindowActivated.connect(self.updateMenus) + self.windowMapper = QtCore.QSignalMapper(self) + self.windowMapper.mapped[QtGui.QWidget].connect(self.setActiveSubWindow) + + self.createActions() + self.createMenus() + self.createToolBars() + self.createStatusBar() + self.updateMenus() + + self.setWindowTitle("GNU Radio Control Port Monitor") + self.setUnifiedTitleAndToolBarOnMac(True) + + self.newCon(radio, port) + icon = QtGui.QIcon(ctrlport.__path__[0] + "/icon.png" ) + self.setWindowIcon(icon) + + def newCon(self, radio=None, port=None): + child = MForm(radio, port, len(self.conns), self) + if(child.radio is not None): + child.setWindowTitle(str(child.radio)) + self.mdiArea.addSubWindow(child) + child.showMaximized() + self.conns.append(child) + self.plots.append([]) + + def propertiesMenu(self, key, radio, uid): + r = str(radio).split(" ") + title = "{0}:{1}".format(r[3], r[5]) + + props = radio.properties([key]) + pmin = props[key].min.value + pmax = props[key].max.value + if pmin == []: + pmin = None + else: + pmin = 1.1*pmin + if pmax == []: + pmax = None + else: + pmax = 1.1*pmax + + def newUpdaterProxy(): + self.newUpdater(key, radio) + + def newPlotterFProxy(): + self.newPlotF(key, uid, title, pmin, pmax) + + def newPlotterCProxy(): + self.newPlotC(key, uid, title, pmin, pmax) + + def newPlotterConstProxy(): + self.newPlotConst(key, uid, title, pmin, pmax) + + def newPlotterPsdFProxy(): + self.newPlotPsdF(key, uid, title) + + def newPlotterPsdCProxy(): + self.newPlotPsdC(key, uid, title) + + menu = QtGui.QMenu(self) + menu.setTitle("Item Actions") + menu.setTearOffEnabled(False) + + # object properties + menu.addAction("Properties", newUpdaterProxy) + + # displays available if not complex + menu.addAction("Plot Time", newPlotterFProxy) + menu.addAction("Plot PSD", newPlotterPsdFProxy) + + # displays available if complex + menu.addAction("Plot Time (cpx)", newPlotterCProxy) + menu.addAction("Plot Constellation", newPlotterConstProxy) + menu.addAction("Plot PSD cpx", newPlotterPsdCProxy) + + menu.popup(QtGui.QCursor.pos()) + + def newUpdater(self, key, radio): + updater = UpdaterWindow(key, radio, None) + updater.setWindowTitle("Updater: " + key) + updater.setModal(False) + updater.exec_() + + def newSub(self, e): + tag = str(e.text(0)) + tree = e.treeWidget().parent() + uid = tree.uid + knobprop = self.knobprops[uid][tag] + + r = str(tree.radio).split(" ") + title = "{0}:{1}".format(r[3], r[5]) + pmin = knobprop.min.value + pmax = knobprop.max.value + if pmin == []: + pmin = None + else: + pmin = 1.1*pmin + if pmax == []: + pmax = None + else: + pmax = 1.1*pmax + + if(knobprop.display == GNURadio.DisplayType.DISPXYSCATTER): + self.newPlotConst(tag, uid, title, pmin, pmax) + elif(knobprop.display == GNURadio.DisplayType.DISPTIMESERIESF): + self.newPlotF(tag, uid, title, pmin, pmax) + elif(knobprop.display == GNURadio.DisplayType.DISPTIMESERIESC): + self.newPlotC(tag, uid, title, pmin, pmax) + + def createPlot(self, plot, uid, title): + plot.start() + self.plots[uid].append(plot) + + self.mdiArea.addSubWindow(plot.qwidget()) + plot.qwidget().setWindowTitle("{0}: {1}".format(title, plot.name())) + self.connect(plot.qwidget(), + QtCore.SIGNAL('destroyed(QObject*)'), + self.destroyPlot) + plot.qwidget().show() + + + def destroyPlot(self, obj): + for plots in self.plots: + for p in plots: + if p.qwidget() == obj: + plots.remove(p) + break + + def newPlotConst(self, tag, uid, title="", pmin=None, pmax=None): + plot = GrDataPlotterConst(tag, 32e6, pmin, pmax) + self.createPlot(plot, uid, title) + + def newPlotF(self, tag, uid, title="", pmin=None, pmax=None): + plot = GrDataPlotterF(tag, 32e6, pmin, pmax) + self.createPlot(plot, uid, title) + + def newPlotC(self, tag, uid, title="", pmin=None, pmax=None): + plot = GrDataPlotterC(tag, 32e6, pmin, pmax) + self.createPlot(plot, uid, title) + + def newPlotPsdF(self, tag, uid, title="", pmin=None, pmax=None): + plot = GrDataPlotterPsdF(tag, 32e6, pmin, pmax) + self.createPlot(plot, uid, title) + + def newPlotPsdC(self, tag, uid, title="", pmin=None, pmax=None): + plot = GrDataPlotterPsdC(tag, 32e6, pmin, pmax) + self.createPlot(plot, uid, title) + + def update(self, knobs, uid): + #sys.stderr.write("KNOB KEYS: {0}\n".format(knobs.keys())) + for plot in self.plots[uid]: + data = knobs[plot.name()].value + plot.update(data) + plot.stop() + plot.wait() + plot.start() + + def setActiveSubWindow(self, window): + if window: + self.mdiArea.setActiveSubWindow(window) + + + def createActions(self): + self.newConAct = QtGui.QAction("&New Connection", + self, shortcut=QtGui.QKeySequence.New, + statusTip="Create a new file", triggered=self.newCon) + #self.newAct = QtGui.QAction(QtGui.QIcon(':/images/new.png'), "&New Plot", + self.newPlotAct = QtGui.QAction("&New Plot", + self, + statusTip="Create a new file", triggered=self.newPlotF) + + self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q", + statusTip="Exit the application", + triggered=QtGui.qApp.closeAllWindows) + + self.closeAct = QtGui.QAction("Cl&ose", self, shortcut="Ctrl+F4", + statusTip="Close the active window", + triggered=self.mdiArea.closeActiveSubWindow) + + self.closeAllAct = QtGui.QAction("Close &All", self, + statusTip="Close all the windows", + triggered=self.mdiArea.closeAllSubWindows) + + + qks = QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_T); + self.tileAct = QtGui.QAction("&Tile", self, + statusTip="Tile the windows", + triggered=self.mdiArea.tileSubWindows, + shortcut=qks) + + qks = QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_C); + self.cascadeAct = QtGui.QAction("&Cascade", self, + statusTip="Cascade the windows", shortcut=qks, + triggered=self.mdiArea.cascadeSubWindows) + + self.nextAct = QtGui.QAction("Ne&xt", self, + shortcut=QtGui.QKeySequence.NextChild, + statusTip="Move the focus to the next window", + triggered=self.mdiArea.activateNextSubWindow) + + self.previousAct = QtGui.QAction("Pre&vious", self, + shortcut=QtGui.QKeySequence.PreviousChild, + statusTip="Move the focus to the previous window", + triggered=self.mdiArea.activatePreviousSubWindow) + + self.separatorAct = QtGui.QAction(self) + self.separatorAct.setSeparator(True) + + self.aboutAct = QtGui.QAction("&About", self, + statusTip="Show the application's About box", + triggered=self.about) + + self.aboutQtAct = QtGui.QAction("About &Qt", self, + statusTip="Show the Qt library's About box", + triggered=QtGui.qApp.aboutQt) + + def createMenus(self): + self.fileMenu = self.menuBar().addMenu("&File") + self.fileMenu.addAction(self.newConAct) + self.fileMenu.addAction(self.newPlotAct) + self.fileMenu.addSeparator() + self.fileMenu.addAction(self.exitAct) + + self.windowMenu = self.menuBar().addMenu("&Window") + self.updateWindowMenu() + self.windowMenu.aboutToShow.connect(self.updateWindowMenu) + + self.menuBar().addSeparator() + + self.helpMenu = self.menuBar().addMenu("&Help") + self.helpMenu.addAction(self.aboutAct) + self.helpMenu.addAction(self.aboutQtAct) + + def createToolBars(self): + self.fileToolBar = self.addToolBar("File") + self.fileToolBar.addAction(self.newConAct) + self.fileToolBar.addAction(self.newPlotAct) + + self.fileToolBar = self.addToolBar("Window") + self.fileToolBar.addAction(self.tileAct) + self.fileToolBar.addAction(self.cascadeAct) + + def createStatusBar(self): + self.statusBar().showMessage("Ready") + + + def activeMdiChild(self): + activeSubWindow = self.mdiArea.activeSubWindow() + if activeSubWindow: + return activeSubWindow.widget() + return None + + def updateMenus(self): + hasMdiChild = (self.activeMdiChild() is not None) + self.closeAct.setEnabled(hasMdiChild) + self.closeAllAct.setEnabled(hasMdiChild) + self.tileAct.setEnabled(hasMdiChild) + self.cascadeAct.setEnabled(hasMdiChild) + self.nextAct.setEnabled(hasMdiChild) + self.previousAct.setEnabled(hasMdiChild) + self.separatorAct.setVisible(hasMdiChild) + + def updateWindowMenu(self): + self.windowMenu.clear() + self.windowMenu.addAction(self.closeAct) + self.windowMenu.addAction(self.closeAllAct) + self.windowMenu.addSeparator() + self.windowMenu.addAction(self.tileAct) + self.windowMenu.addAction(self.cascadeAct) + self.windowMenu.addSeparator() + self.windowMenu.addAction(self.nextAct) + self.windowMenu.addAction(self.previousAct) + self.windowMenu.addAction(self.separatorAct) + + def about(self): + about_info = \ +'''Copyright 2012 Free Software Foundation, Inc.\n +This program is part of GNU Radio.\n +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.\n +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.\n +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.''' + + QtGui.QMessageBox.about(None, "gr-ctrlport-monitor", about_info) + + +class ConInfoDialog(QtGui.QDialog): + def __init__(self, parent=None): + super(ConInfoDialog, self).__init__(parent) + + self.gridLayout = QtGui.QGridLayout(self) + + + self.host = QtGui.QLineEdit(self); + self.port = QtGui.QLineEdit(self); + self.host.setText("localhost"); + self.port.setText("43243"); + + self.buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) + + self.gridLayout.addWidget(self.host); + self.gridLayout.addWidget(self.port); + self.gridLayout.addWidget(self.buttonBox); + + self.buttonBox.accepted.connect(self.accept) + self.buttonBox.rejected.connect(self.reject) + + + def accept(self): + self.done(1); + + def reject(self): + self.done(0); + + +class UpdaterWindow(QtGui.QDialog): + def __init__(self, key, radio, parent): + QtGui.QDialog.__init__(self, parent) + + self.key = key; + self.radio = radio + + self.resize(300,200) + self.layout = QtGui.QVBoxLayout() + + self.props = radio.properties([key])[key] + info = str(self.props) + + self.infoLabel = QtGui.QLabel(info) + self.layout.addWidget(self.infoLabel) + + # Test here to make sure that a 'set' function + try: + a = radio.set(radio.get([key])) + has_set = True + except Ice.UnknownException: + has_set = False + + if(has_set is False): + self.cancelButton = QtGui.QPushButton("Ok") + self.cancelButton.connect(self.cancelButton, QtCore.SIGNAL('clicked()'), self.reject) + + self.buttonlayout = QtGui.QHBoxLayout() + self.buttonlayout.addWidget(self.cancelButton) + self.layout.addLayout(self.buttonlayout) + + else: # we have a set function + self.textInput = QtGui.QLineEdit() + self.layout.addWidget(self.textInput) + + self.applyButton = QtGui.QPushButton("Apply") + self.setButton = QtGui.QPushButton("OK") + self.cancelButton = QtGui.QPushButton("Cancel") + + rv = radio.get([key]) + self.textInput.setText(str(rv[key].value)) + self.sv = rv[key] + + self.applyButton.connect(self.applyButton, QtCore.SIGNAL('clicked()'), self._apply) + self.setButton.connect(self.setButton, QtCore.SIGNAL('clicked()'), self._set) + self.cancelButton.connect(self.cancelButton, QtCore.SIGNAL('clicked()'), self.reject) + + self.is_num = ((type(self.sv.value)==float) or (type(self.sv.value)==int)) + if(self.is_num): + self.sliderlayout = QtGui.QHBoxLayout() + + self.slider = QtGui.QSlider(QtCore.Qt.Horizontal) + + self.sliderlayout.addWidget(QtGui.QLabel(str(self.props.min.value))) + self.sliderlayout.addWidget(self.slider) + self.sliderlayout.addWidget(QtGui.QLabel(str(self.props.max.value))) + + self.steps = 10000 + self.valspan = self.props.max.value - self.props.min.value + + self.slider.setRange(0, 10000) + self._set_slider_value(self.sv.value) + + self.connect(self.slider, QtCore.SIGNAL("sliderReleased()"), self._slide) + + self.layout.addLayout(self.sliderlayout) + + self.buttonlayout = QtGui.QHBoxLayout() + self.buttonlayout.addWidget(self.applyButton) + self.buttonlayout.addWidget(self.setButton) + self.buttonlayout.addWidget(self.cancelButton) + self.layout.addLayout(self.buttonlayout) + + # set layout and go... + self.setLayout(self.layout) + + def _set_slider_value(self, val): + self.slider.setValue(self.steps*(val-self.props.min.value)/self.valspan) + + def _slide(self): + val = (self.slider.value()*self.valspan + self.props.min.value)/float(self.steps) + self.textInput.setText(str(val)) + + def _apply(self): + if(type(self.sv.value) == str): + val = str(self.textInput.text()) + elif(type(self.sv.value) == int): + val = int(round(float(self.textInput.text()))) + elif(type(self.sv.value) == float): + val = float(self.textInput.text()) + else: + sys.stderr.write("set type not supported! ({0})\n".format(type(self.sv.value))) + sys.exit(-1) + + self.sv.value = val + km = {} + km[self.key] = self.sv + self.radio.set(km) + self._set_slider_value(self.sv.value) + + def _set(self): + self._apply() + self.done(0) + + +class MForm(QtGui.QWidget): + def update(self): + try: + st = time.time(); + knobs = self.radio.get([]); + ft = time.time(); + latency = ft-st; + self.parent.statusBar().showMessage("Current GNU Radio Control Port Query Latency: %f ms"%(latency*1000)) + + except Exception, e: + sys.stderr.write("ctrlport-monitor: radio.get threw exception ({0}).\n".format(e)) + if(type(self.parent) is MAINWindow): + # Find window of connection + remove = [] + for p in self.parent.mdiArea.subWindowList(): + if self.parent.conns[self.uid] == p.widget(): + remove.append(p) + + # Find any subplot windows of connection + for p in self.parent.mdiArea.subWindowList(): + for plot in self.parent.plots[self.uid]: + if plot.qwidget() == p.widget(): + remove.append(p) + + # Clean up local references to these + self.parent.conns.remove(self.parent.conns[self.uid]) + self.parent.plots.remove(self.parent.plots[self.uid]) + + # Remove subwindows for connection and plots + for r in remove: + self.parent.mdiArea.removeSubWindow(r) + + # Clean up self + self.close() + else: + sys.exit(1) + return + + tableitems = knobs.keys() + + #UPDATE TABLE: + self.table.updateItems(knobs, self.knobprops) + + #UPDATE PLOTS + self.parent.update(knobs, self.uid) + + + def __init__(self, radio=None, port=None, uid=0, parent=None): + + super(MForm, self).__init__() + + if(radio == None or port == None): + askinfo = ConInfoDialog(self); + if askinfo.exec_(): + host = str(askinfo.host.text()); + port = str(askinfo.port.text()); + radio = parent.interface.getRadio(host, port) + else: + self.radio = None + return + + self.uid = uid + self.parent = parent + self.horizontalLayout = QtGui.QVBoxLayout(self) + self.gridLayout = QtGui.QGridLayout() + + self.radio = radio + self.knobprops = self.radio.properties([]) + self.parent.knobprops.append(self.knobprops) + self.resize(775,500) + self.timer = QtCore.QTimer() + self.constupdatediv = 0 + self.tableupdatediv = 0 + plotsize=250 + + # make table + self.table = GrDataPlotterValueTable(uid, self, 0, 0, 400, 200) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) + self.table.treeWidget.setSizePolicy(sizePolicy) + self.table.treeWidget.setEditTriggers(QtGui.QAbstractItemView.EditKeyPressed) + self.table.treeWidget.setSortingEnabled(True) + self.table.treeWidget.setDragEnabled(True) + + # add things to layouts + self.horizontalLayout.addWidget(self.table.treeWidget) + + # set up timer + self.connect(self.timer, QtCore.SIGNAL('timeout()'), self.update) + self.timer.start(1000) + + # set up context menu .. + self.table.treeWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + self.table.treeWidget.customContextMenuRequested.connect(self.openMenu) + + # Set up double-click to launch default plotter + self.connect(self.table.treeWidget, + QtCore.SIGNAL('itemDoubleClicked(QTreeWidgetItem*, int)'), + self.parent.newSub); + + def openMenu(self, pos): + index = self.table.treeWidget.selectedIndexes() + item = self.table.treeWidget.itemFromIndex(index[0]) + itemname = str(item.text(0)) + self.parent.propertiesMenu(itemname, self.radio, self.uid) + + +class MyClient(IceRadioClient): + def __init__(self): + IceRadioClient.__init__(self, MAINWindow) + +sys.exit(MyClient().main(sys.argv)) diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/icon.png b/gnuradio-core/src/python/gnuradio/ctrlport/icon.png Binary files differnew file mode 100644 index 0000000000..4beb204428 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/icon.png diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/monitor.py b/gnuradio-core/src/python/gnuradio/ctrlport/monitor.py new file mode 100644 index 0000000000..53a571a698 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/monitor.py @@ -0,0 +1,59 @@ +#!/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 sys, subprocess, re, signal, time, atexit, os +from gnuradio import gr + +class monitor: + def __init__(self): + print "ControlPort Monitor running." + self.started = False + atexit.register(self.shutdown) + + def __del__(self): + if(self.started): + self.stop() + + def start(self): + print "monitor::endpoints() = %s" % (gr.rpcmanager_get().endpoints()) + try: + self.proc = subprocess.Popen(map(lambda a: ["gr-ctrlport-monitor", + re.search("\d+\.\d+\.\d+\.\d+",a).group(0), + re.search("-p (\d+)",a).group(1)], + gr.rpcmanager_get().endpoints())[0]) + self.started = True + except: + self.proc = None + print "failed to to start ControlPort Monitor on specified port" + + def stop(self): + if(self.proc): + if(self.proc.returncode == None): + print "\tcalling stop on shutdown" + self.proc.terminate() + else: + print "\tno proc to shut down, exiting" + + def shutdown(self): + print "ctrlport.monitor received shutdown signal" + if(self.started): + self.stop() diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding.py b/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding.py new file mode 100755 index 0000000000..34c7d0f5df --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding.py @@ -0,0 +1,170 @@ +#!/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. +# + +# +# This program tests mixed python and c++ ctrlport exports in a single app +# + +import Ice +import sys, time, random, numpy +from gnuradio import gr, gr_unittest + +from gnuradio.ctrlport import GNURadio +from gnuradio import ctrlport + +def get1(): + return "success" + +def get2(): + return "failure" + +class inc_class: + def __init__(self): + self.val = 1 + def pp(self): + self.val = self.val+1 + return self.val + +get3 = inc_class() + +def get4(): + random.seed(0) + rv = random.random() + return rv + +def get5(): + numpy.random.seed(0) + samp_t = numpy.random.randn(24)+1j*numpy.random.randn(24); + samp_f = numpy.fft.fft(samp_t); + log_pow_f = 20*numpy.log10(numpy.abs(samp_f)) + rv = list(log_pow_f) + return rv; + +def get6(): + numpy.random.seed(0) + samp_t = numpy.random.randn(1024)+1j*numpy.random.randn(1024); + rv = list(samp_t) + return rv; + +class test_cpp_py_binding(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + v1 = gr.RPC_get_string("pyland", "v1", "unit_1_string", + "Python Exported String", "", "", "", + gr.DISPNULL) + v1.activate(get1) + + v2 = gr.RPC_get_string("pyland", "v2", "unit_2_string", + "Python Exported String", "", "", "", + gr.DISPNULL) + v2.activate(get2) + + v3 = gr.RPC_get_int("pyland", "v3", "unit_3_int", + "Python Exported Int", 0, 100, 1, + gr.DISPNULL) + v3.activate(get3.pp) + + v4 = gr.RPC_get_double("pyland", "time", "unit_4_time_double", + "Python Exported Double", 0, 1000, 1, + gr.DISPNULL) + v4.activate(get4) + + v5 = gr.RPC_get_vector_float("pyland", "fvec", "unit_5_float_vector", + "Python Exported Float Vector", [], [], [], + gr.DISPTIMESERIESC) + v5.activate(get5) + + v6 = gr.RPC_get_vector_gr_complex("pyland", "cvec", "unit_6_gr_complex_vector", + "Python Exported Complex Vector", [], [], [], + gr.DISPXYSCATTER) + v6.activate(get6) + + # print some variables locally + val = get1() + rval = v1.get() + self.assertEqual(val, rval) + + val = get2() + rval = v2.get() + self.assertEqual(val, rval) + + val = get3.pp() + rval = v3.get() + self.assertEqual(val+1, rval) + + val = get4() + rval = v4.get() + self.assertEqual(val, rval) + + val = get5() + rval = v5.get() + self.assertComplexTuplesAlmostEqual(val, rval, 5) + + val = get6() + rval = v6.get() + self.assertComplexTuplesAlmostEqual(val, rval, 5) + + def test_002(self): + data = range(1,9) + + self.src = gr.vector_source_c(data) + self.p1 = gr.ctrlport_probe_c("aaa","C++ exported variable") + self.p2 = gr.ctrlport_probe_c("bbb","C++ exported variable") + probe_name = self.p2.alias() + + self.tb.connect(self.src, self.p1) + self.tb.connect(self.src, self.p2) + self.tb.start() + + # Probes return complex values as list of floats with re, im + # Imaginary parts of this data set are 0. + expected_result = [1, 0, 2, 0, 3, 0, 4, 0, + 5, 0, 6, 0, 7, 0, 8, 0] + + # Make sure we have time for flowgraph to run + time.sleep(0.1) + + # Get available endpoint + ep = gr.rpcmanager_get().endpoints()[0] + + # Initialize a simple Ice client from endpoint + ic = Ice.initialize(sys.argv) + base = ic.stringToProxy(ep) + radio = GNURadio.ControlPortPrx.checkedCast(base) + + # Get all exported knobs + ret = radio.get([probe_name + "::bbb"]) + for name in ret.keys(): + result = ret[name].value + self.assertEqual(result, expected_result) + + self.tb.stop() + +if __name__ == '__main__': + gr_unittest.run(test_cpp_py_binding, "test_cpp_py_binding.xml") + diff --git a/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding_set.py b/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding_set.py new file mode 100755 index 0000000000..8b1b15022c --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/ctrlport/qa_cpp_py_binding_set.py @@ -0,0 +1,148 @@ +#!/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. +# + +# +# This program tests mixed python and c++ GRCP sets in a single app +# + +import Ice +import sys, time, random, numpy +from gnuradio import gr, gr_unittest + +from gnuradio.ctrlport import GNURadio +from gnuradio import ctrlport + +class inc_class: + def __init__(self,val): + self.val = val; + + def _get(self): + #print "returning get (val = %s)"%(str(self.val)); + return self.val; + + def _set(self,val): + #print "updating val to %s"%(str(val)); + self.val = val; + return; + +getset1 = inc_class(10); +getset2 = inc_class(100.0); +getset3 = inc_class("test"); + +class test_cpp_py_binding_set(gr_unittest.TestCase): + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + + g1 = gr.RPC_get_int("pyland", "v1", "unit_1_int", + "Python Exported Int", 0, 100, 10, + gr.DISPNULL) + g1.activate(getset1._get) + s1 = gr.RPC_get_int("pyland", "v1", "unit_1_int", + "Python Exported Int", 0, 100, 10, + gr.DISPNULL) + s1.activate(getset1._set) + time.sleep(0.01) + + # test int variables + getset1._set(21) + val = getset1._get() + rval = g1.get() + self.assertEqual(val, rval) + + g2 = gr.RPC_get_float("pyland", "v2", "unit_2_float", + "Python Exported Float", -100, 1000.0, 100.0, + gr.DISPNULL) + g2.activate(getset2._get) + s2 = gr.RPC_get_float("pyland", "v2", "unit_2_float", + "Python Exported Float", -100, 1000.0, 100.0, + gr.DISPNULL) + s2.activate(getset2._set) + time.sleep(0.01) + + # test float variables + getset2._set(123.456) + val = getset2._get() + rval = g2.get() + self.assertAlmostEqual(val, rval, 4) + + g3 = gr.RPC_get_string("pyland", "v3", "unit_3_string", + "Python Exported String", "", "", "", + gr.DISPNULL) + g3.activate(getset3._get) + s3 = gr.RPC_get_string("pyland", "v3", "unit_3_string", + "Python Exported String", "", "", "", + gr.DISPNULL) + s3.activate(getset3._set) + time.sleep(0.01) + + # test string variables + getset3._set("third test") + val = getset3._get() + rval = g3.get() + self.assertEqual(val, rval) + + + def test_002(self): + data = range(1, 10) + + self.src = gr.vector_source_c(data, True) + self.p = gr.nop(gr.sizeof_gr_complex) + self.p.set_ctrlport_test(0); + probe_info = self.p.alias() + + self.tb.connect(self.src, self.p) + + # Get available endpoint + ep = gr.rpcmanager_get().endpoints()[0] + + # Initialize a simple Ice client from endpoint + ic = Ice.initialize(sys.argv) + base = ic.stringToProxy(ep) + radio = GNURadio.ControlPortPrx.checkedCast(base) + + self.tb.start() + + # Make sure we have time for flowgraph to run + time.sleep(0.1) + + # Get all exported knobs + key_name_test = probe_info+"::test" + ret = radio.get([key_name_test,]) + + ret[key_name_test].value = 10 + radio.set({key_name_test: ret[key_name_test]}) + + ret = radio.get([]) + result_test = ret[key_name_test].value + self.assertEqual(result_test, 10) + + self.tb.stop() + self.tb.wait() + +if __name__ == '__main__': + gr_unittest.run(test_cpp_py_binding_set, "test_cpp_py_binding_set.xml") + diff --git a/gnuradio-core/src/python/gnuradio/eng_notation.py b/gnuradio-core/src/python/gnuradio/eng_notation.py index c552a45f55..d23f9005f0 100644 --- a/gnuradio-core/src/python/gnuradio/eng_notation.py +++ b/gnuradio-core/src/python/gnuradio/eng_notation.py @@ -18,6 +18,9 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # +""" +Display numbers as strings using engineering notation. +""" scale_factor = {} scale_factor['E'] = 1e18 diff --git a/gnuradio-core/src/python/gnuradio/eng_option.py b/gnuradio-core/src/python/gnuradio/eng_option.py index 02e9b0b6df..5d8660f0f2 100644 --- a/gnuradio-core/src/python/gnuradio/eng_option.py +++ b/gnuradio-core/src/python/gnuradio/eng_option.py @@ -43,7 +43,8 @@ def check_subdev (option, opt, value): """ Value has the form: (A|B)(:0|1)? - @returns a 2-tuple (0|1, 0|1) + Returns: + a 2-tuple (0|1, 0|1) """ d = { 'A' : (0, 0), 'A:0' : (0, 0), 'A:1' : (0, 1), 'A:2' : (0, 2), 'B' : (1, 0), 'B:0' : (1, 0), 'B:1' : (1, 1), 'B:2' : (1, 2) } diff --git a/gnuradio-core/src/python/gnuradio/gr/__init__.py b/gnuradio-core/src/python/gnuradio/gr/__init__.py index f1b971e62d..e4dca5d98f 100644 --- a/gnuradio-core/src/python/gnuradio/gr/__init__.py +++ b/gnuradio-core/src/python/gnuradio/gr/__init__.py @@ -21,6 +21,10 @@ # The presence of this file turns this directory into a Python package +""" +Core contents. +""" + # This is the main GNU Radio python module. # We pull the swig output and the other modules into the gnuradio.gr namespace @@ -31,19 +35,5 @@ from top_block import * from gateway import basic_block, sync_block, decim_block, interp_block from tag_utils import tag_to_python, tag_to_pmt -# 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/hier_block2.py b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py index b957822381..ff39b3e709 100644 --- a/gnuradio-core/src/python/gnuradio/gr/hier_block2.py +++ b/gnuradio-core/src/python/gnuradio/gr/hier_block2.py @@ -20,6 +20,7 @@ # from gnuradio_core import hier_block2_swig + try: import pmt except ImportError: @@ -35,7 +36,9 @@ except ImportError: # class hier_block2(object): """ - Python wrapper around the C++ hierarchical block implementation. + Subclass this to create a python hierarchical block. + + This is a python wrapper around the C++ hierarchical block implementation. Provides convenience functions and allows proper Python subclassing. """ @@ -122,8 +125,8 @@ class hier_block2(object): self.primitive_msg_disconnect(src.to_basic_block(), srcport, dst.to_basic_block(), dstport); def message_port_register_hier_in(self, portname): - self.primitive_message_port_register_hier_in(pmt.pmt_intern(portname)); + self.primitive_message_port_register_hier_in(pmt.intern(portname)); def message_port_register_hier_out(self, portname): - self.primitive_message_port_register_hier_out(pmt.pmt_intern(portname)); + self.primitive_message_port_register_hier_out(pmt.intern(portname)); 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_agc.py b/gnuradio-core/src/python/gnuradio/gr/qa_agc.py deleted file mode 100755 index 9fd633576e..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_agc.py +++ /dev/null @@ -1,433 +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 - -test_output = False - -class test_agc (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - - def test_001(self): - ''' Test the complex AGC loop (single rate input) ''' - tb = self.tb - - expected_result = ( - (100.000244140625+7.2191943445432116e-07j), - (72.892257690429688+52.959323883056641j), - (25.089065551757812+77.216217041015625j), - (-22.611061096191406+69.589706420898438j), - (-53.357715606689453+38.766635894775391j), - (-59.458671569824219+3.4792964243024471e-07j), - (-43.373462677001953-31.512666702270508j), - (-14.94139289855957-45.984889984130859j), - (13.478158950805664-41.48150634765625j), - (31.838506698608398-23.132022857666016j), - (35.519271850585938-3.1176801940091536e-07j), - (25.942903518676758+18.848621368408203j), - (8.9492912292480469+27.5430908203125j), - (-8.0852642059326172+24.883890151977539j), - (-19.131628036499023+13.899936676025391j), - (-21.383295059204102+3.1281737733479531e-07j), - (-15.650330543518066-11.370632171630859j), - (-5.4110145568847656-16.65339469909668j), - (4.9008159637451172-15.083160400390625j), - (11.628337860107422-8.4484796524047852j), - (13.036135673522949-2.288476110834381e-07j), - (9.5726661682128906+6.954948902130127j), - (3.3216962814331055+10.223132133483887j), - (-3.0204284191131592+9.2959251403808594j), - (-7.1977195739746094+5.2294478416442871j), - (-8.1072216033935547+1.8976157889483147e-07j), - (-5.9838657379150391-4.3475332260131836j), - (-2.0879747867584229-6.4261269569396973j), - (1.9100792407989502-5.8786196708679199j), - (4.5814824104309082-3.3286411762237549j), - (5.1967458724975586-1.3684227440080576e-07j), - (3.8647139072418213+2.8078789710998535j), - (1.3594740629196167+4.1840314865112305j), - (-1.2544282674789429+3.8607344627380371j), - (-3.0366206169128418+2.2062335014343262j), - (-3.4781389236450195+1.1194014604143376e-07j), - (-2.6133756637573242-1.8987287282943726j), - (-0.9293016791343689-2.8600969314575195j), - (0.86727333068847656-2.6691930294036865j), - (2.1243946552276611-1.5434627532958984j), - (2.4633183479309082-8.6486437567145913e-08j), - (1.8744727373123169+1.3618841171264648j), - (0.67528903484344482+2.0783262252807617j), - (-0.63866174221038818+1.965599536895752j), - (-1.5857341289520264+1.152103066444397j), - (-1.8640764951705933+7.6355092915036948e-08j), - (-1.4381576776504517-1.0448826551437378j), - (-0.52529704570770264-1.6166983842849731j), - (0.50366902351379395-1.5501341819763184j), - (1.26766037940979-0.92100900411605835j)) - - sampling_freq = 100 - src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 100.0) - dst1 = gr.vector_sink_c () - head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) - - agc = gr.agc_cc(1e-3, 1, 1, 1000) - - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) - - if test_output == True: - tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc_cc.dat")) - - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4) - - def test_002(self): - ''' Test the floating point AGC loop (single rate input) ''' - tb = self.tb - - expected_result = ( - 7.2191943445432116e-07, - 58.837181091308594, - 89.700050354003906, - 81.264183044433594, - 45.506141662597656, - 4.269894304798072e-07, - -42.948936462402344, - -65.50335693359375, - -59.368724822998047, - -33.261005401611328, - -4.683740257860336e-07, - 31.423542022705078, - 47.950984954833984, - 43.485683441162109, - 24.378345489501953, - 5.7254135299444897e-07, - -23.062990188598633, - -35.218441009521484, - -31.964075088500977, - -17.934831619262695, - -5.0591745548445033e-07, - 16.998210906982422, - 25.982204437255859, - 23.606258392333984, - 13.260685920715332, - 4.9936483037527069e-07, - -12.59880542755127, - -19.28221321105957, - -17.54347038269043, - -9.8700437545776367, - -4.188150626305287e-07, - 9.4074573516845703, - 14.422011375427246, - 13.145503044128418, - 7.41046142578125, - 3.8512698097292741e-07, - -7.0924453735351562, - -10.896408081054688, - -9.9552040100097656, - -5.6262712478637695, - -3.1982864356905338e-07, - 5.4131259918212891, - 8.3389215469360352, - 7.6409502029418945, - 4.3320145606994629, - 2.882407841298118e-07, - -4.194943904876709, - -6.4837145805358887, - -5.9621825218200684, - -3.3931560516357422) - - sampling_freq = 100 - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 100.0) - dst1 = gr.vector_sink_f () - head = gr.head (gr.sizeof_float, int (5*sampling_freq * 0.10)) - - agc = gr.agc_ff(1e-3, 1, 1, 1000) - - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) - - if test_output == True: - tb.connect (agc, gr.file_sink(gr.sizeof_float, "test_agc_ff.dat")) - - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4) - - def test_003(self): - ''' Test the complex AGC loop (attack and decay rate inputs) ''' - tb = self.tb - - expected_result = \ - ((100.000244140625+7.2191943445432116e-07j), - (0.80881959199905396+0.58764183521270752j), - (0.30894950032234192+0.95084899663925171j), - (-0.30895623564720154+0.95086973905563354j), - (-0.80887287855148315+0.58768033981323242j), - (-0.99984413385391235+5.850709250410091e-09j), - (-0.80889981985092163-0.58770018815994263j), - (-0.30897706747055054-0.95093393325805664j), - (0.30898112058639526-0.95094609260559082j), - (0.80893135070800781-0.58772283792495728j), - (0.99990922212600708-8.7766354184282136e-09j), - (0.80894720554351807+0.58773452043533325j), - (0.30899339914321899+0.95098406076431274j), - (-0.30899572372436523+0.95099133253097534j), - (-0.80896598100662231+0.58774799108505249j), - (-0.99994778633117676+1.4628290578855285e-08j), - (-0.80897533893585205-0.58775502443313599j), - (-0.30900305509567261-0.95101380348205566j), - (0.30900448560714722-0.95101797580718994j), - (0.80898630619049072-0.58776277303695679j), - (0.99997037649154663-1.7554345532744264e-08j), - (0.80899184942245483+0.58776694536209106j), - (0.30900871753692627+0.95103120803833008j), - (-0.30900952219963074+0.95103377103805542j), - (-0.8089984655380249+0.58777159452438354j), - (-0.99998390674591064+2.3406109050938539e-08j), - (-0.809001624584198-0.58777409791946411j), - (-0.30901208519935608-0.95104163885116577j), - (0.30901262164115906-0.95104306936264038j), - (0.80900543928146362-0.587776780128479j), - (0.99999171495437622-2.6332081404234486e-08j), - (0.80900734663009644+0.58777821063995361j), - (0.30901408195495605+0.95104765892028809j), - (-0.30901429057121277+0.95104855298995972j), - (-0.80900967121124268+0.58777981996536255j), - (-0.99999648332595825+3.2183805842578295e-08j), - (-0.80901080369949341-0.58778077363967896j), - (-0.30901527404785156-0.95105135440826416j), - (0.30901545286178589-0.95105189085006714j), - (0.80901217460632324-0.58778166770935059j), - (0.99999916553497314-3.5109700036173308e-08j), - (0.809012770652771+0.58778214454650879j), - (0.30901595950126648+0.9510534405708313j), - (-0.30901598930358887+0.95105385780334473j), - (-0.80901366472244263+0.58778274059295654j), - (-1.0000008344650269+4.0961388947380328e-08j), - (-0.8090139627456665-0.58778303861618042j), - (-0.30901634693145752-0.95105475187301636j), - (0.30901640653610229-0.95105493068695068j), - (0.80901449918746948-0.5877833366394043j)) - - sampling_freq = 100 - src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 100) - dst1 = gr.vector_sink_c () - head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) - - agc = gr.agc2_cc(1e-2, 1e-3, 1, 1, 1000) - - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) - - if test_output == True: - tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc2_cc.dat")) - - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4) - - def test_004(self): - ''' Test the floating point AGC loop (attack and decay rate inputs) ''' - tb = self.tb - - expected_result = \ - (7.2191943445432116e-07, - 58.837181091308594, - 40.194305419921875, - 2.9183335304260254, - 0.67606079578399658, - 8.6260438791896377e-09, - -1.4542514085769653, - -1.9210131168365479, - -1.0450780391693115, - -0.61939650774002075, - -1.2590258613442984e-08, - 1.4308931827545166, - 1.9054338932037354, - 1.0443156957626343, - 0.61937344074249268, - 2.0983527804219193e-08, - -1.4308838844299316, - -1.9054274559020996, - -1.0443152189254761, - -0.61937344074249268, - -2.5180233009791664e-08, - 1.4308837652206421, - 1.9054274559020996, - 1.0443154573440552, - 0.61937344074249268, - 3.3573645197293445e-08, - -1.4308838844299316, - -1.9054274559020996, - -1.0443152189254761, - -0.61937350034713745, - -3.7770352179222755e-08, - 1.4308837652206421, - 1.9054274559020996, - 1.0443154573440552, - 0.61937350034713745, - 4.6163762590367696e-08, - -1.4308838844299316, - -1.9054274559020996, - -1.0443153381347656, - -0.61937344074249268, - -5.0360466019583328e-08, - 1.4308837652206421, - 1.9054274559020996, - 1.0443155765533447, - 0.61937344074249268, - 5.8753879983441948e-08, - -1.4308837652206421, - -1.9054274559020996, - -1.0443153381347656, - -0.61937344074249268) - - sampling_freq = 100 - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 100) - dst1 = gr.vector_sink_f () - head = gr.head (gr.sizeof_float, int (5*sampling_freq * 0.10)) - - agc = gr.agc2_ff(1e-2, 1e-3, 1, 1, 1000) - - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) - - if test_output == True: - tb.connect (agc, gr.file_sink(gr.sizeof_float, "test_agc2_ff.dat")) - - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4) - - - def test_005(self): - ''' Test the complex AGC loop (attack and decay rate inputs) ''' - tb = self.tb - - expected_result = \ - ((100.000244140625+7.2191943445432116e-07j), - (0.80881959199905396+0.58764183521270752j), - (0.30894950032234192+0.95084899663925171j), - (-0.30895623564720154+0.95086973905563354j), - (-0.80887287855148315+0.58768033981323242j), - (-0.99984413385391235+5.850709250410091e-09j), - (-0.80889981985092163-0.58770018815994263j), - (-0.30897706747055054-0.95093393325805664j), - (0.30898112058639526-0.95094609260559082j), - (0.80893135070800781-0.58772283792495728j), - (0.99990922212600708-8.7766354184282136e-09j), - (0.80894720554351807+0.58773452043533325j), - (0.30899339914321899+0.95098406076431274j), - (-0.30899572372436523+0.95099133253097534j), - (-0.80896598100662231+0.58774799108505249j), - (-0.99994778633117676+1.4628290578855285e-08j), - (-0.80897533893585205-0.58775502443313599j), - (-0.30900305509567261-0.95101380348205566j), - (0.30900448560714722-0.95101797580718994j), - (0.80898630619049072-0.58776277303695679j), - (0.99997037649154663-1.7554345532744264e-08j), - (0.80899184942245483+0.58776694536209106j), - (0.30900871753692627+0.95103120803833008j), - (-0.30900952219963074+0.95103377103805542j), - (-0.8089984655380249+0.58777159452438354j), - (-0.99998390674591064+2.3406109050938539e-08j), - (-0.809001624584198-0.58777409791946411j), - (-0.30901208519935608-0.95104163885116577j), - (0.30901262164115906-0.95104306936264038j), - (0.80900543928146362-0.587776780128479j), - (0.99999171495437622-2.6332081404234486e-08j), - (0.80900734663009644+0.58777821063995361j), - (0.30901408195495605+0.95104765892028809j), - (-0.30901429057121277+0.95104855298995972j), - (-0.80900967121124268+0.58777981996536255j), - (-0.99999648332595825+3.2183805842578295e-08j), - (-0.80901080369949341-0.58778077363967896j), - (-0.30901527404785156-0.95105135440826416j), - (0.30901545286178589-0.95105189085006714j), - (0.80901217460632324-0.58778166770935059j), - (0.99999916553497314-3.5109700036173308e-08j), - (0.809012770652771+0.58778214454650879j), - (0.30901595950126648+0.9510534405708313j), - (-0.30901598930358887+0.95105385780334473j), - (-0.80901366472244263+0.58778274059295654j), - (-1.0000008344650269+4.0961388947380328e-08j), - (-0.8090139627456665-0.58778303861618042j), - (-0.30901634693145752-0.95105475187301636j), - (0.30901640653610229-0.95105493068695068j), - (0.80901449918746948-0.5877833366394043j)) - - sampling_freq = 100 - src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 100) - dst1 = gr.vector_sink_c () - head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) - - agc = gr.agc2_cc(1e-2, 1e-3, 1, 1, 1000) - - tb.connect (src1, head) - tb.connect (head, agc) - tb.connect (agc, dst1) - - if test_output == True: - tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc2_cc.dat")) - - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4) - - - def test_100(self): # FIXME needs work - ''' Test complex feedforward agc with constant input ''' - input_data = 16*(0.0,) + 64*(1.0,) + 64*(0.0,) - expected_result = () - - src = gr.vector_source_c(input_data) - agc = gr.feedforward_agc_cc(16, 2.0) - dst = gr.vector_sink_c () - self.tb.connect (src, agc, dst) - - if test_output == True: - self.tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_feedforward_cc.dat")) - - self.tb.run () - dst_data = dst.data () - #self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4) - - -if __name__ == '__main__': - gr_unittest.run(test_agc, "test_agc.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..2c8cba5439 100644 --- a/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_block_gateway.py @@ -112,8 +112,8 @@ class tag_source(gr.sync_block): #make a new tag on the middle element every time work is called count = self.nitems_written(0) + num_output_items/2 - key = pmt.pmt_string_to_symbol("example_key") - value = pmt.pmt_string_to_symbol("example_value") + key = pmt.string_to_symbol("example_key") + value = pmt.string_to_symbol("example_value") self.add_item_tag(0, count, key, value) return num_output_items @@ -138,9 +138,9 @@ class tag_sink(gr.sync_block): tags = self.get_tags_in_range(0, nread, nread+num_input_items) for tag in tags: #print tag.offset - #print pmt.pmt_symbol_to_string(tag.key) - #print pmt.pmt_symbol_to_string(tag.value) - self.key = pmt.pmt_symbol_to_string(tag.key) + #print pmt.symbol_to_string(tag.key) + #print pmt.symbol_to_string(tag.value) + self.key = pmt.symbol_to_string(tag.key) return num_input_items @@ -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_dc_blocker.py b/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py deleted file mode 100755 index 1757358676..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py +++ /dev/null @@ -1,108 +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_dc_blocker(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - ''' Test impulse response - long form, cc ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.02072429656982422+0j), (-0.02081298828125+0j), - (0.979156494140625+0j), (-0.02081298828125+0j), - (-0.02072429656982422+0j)) - - src = gr.vector_source_c(src_data) - op = gr.dc_blocker_cc(32, True) - dst = gr.vector_sink_c() - - self.tb.connect (src, op, dst) - self.tb.run() - - # only test samples around 2D-2 - result_data = dst.data()[60:65] - self.assertComplexTuplesAlmostEqual (expected_result, result_data) - - def test_002(self): - ''' Test impulse response - short form, cc ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.029296875+0j), (-0.0302734375+0j), - (0.96875+0j), (-0.0302734375+0j), - (-0.029296875+0j)) - - src = gr.vector_source_c(src_data) - op = gr.dc_blocker_cc(32, False) - dst = gr.vector_sink_c() - - self.tb.connect (src, op, dst) - self.tb.run() - - # only test samples around D-1 - result_data = dst.data()[29:34] - self.assertComplexTuplesAlmostEqual (expected_result, result_data) - - - def test_003(self): - ''' Test impulse response - long form, ff ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.02072429656982422), (-0.02081298828125), - (0.979156494140625), (-0.02081298828125), - (-0.02072429656982422)) - - src = gr.vector_source_f(src_data) - op = gr.dc_blocker_ff(32, True) - dst = gr.vector_sink_f() - - self.tb.connect (src, op, dst) - self.tb.run() - - # only test samples around 2D-2 - result_data = dst.data()[60:65] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_004(self): - ''' Test impulse response - short form, ff ''' - src_data = [1,] + 100*[0,] - expected_result = ((-0.029296875), (-0.0302734375), - (0.96875), (-0.0302734375), - (-0.029296875)) - - src = gr.vector_source_f(src_data) - op = gr.dc_blocker_ff(32, False) - dst = gr.vector_sink_f() - - self.tb.connect (src, op, dst) - self.tb.run() - - # only test samples around D-1 - result_data = dst.data()[29:34] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_dc_blocker, "test_dc_blocker.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_diff_encoder.py b/gnuradio-core/src/python/gnuradio/gr/qa_diff_encoder.py deleted file mode 100755 index c1fe2a7000..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_diff_encoder.py +++ /dev/null @@ -1,86 +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 math -import random - -def make_random_int_tuple(L, min, max): - result = [] - for x in range(L): - result.append(random.randint(min, max)) - return tuple(result) - - -class test_diff_encoder (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_diff_encdec_000(self): - random.seed(0) - modulus = 2 - src_data = make_random_int_tuple(1000, 0, modulus-1) - expected_result = src_data - src = gr.vector_source_b(src_data) - enc = gr.diff_encoder_bb(modulus) - dec = gr.diff_decoder_bb(modulus) - dst = gr.vector_sink_b() - self.tb.connect(src, enc, dec, dst) - self.tb.run() # run the graph and wait for it to finish - actual_result = dst.data() # fetch the contents of the sink - self.assertEqual(expected_result, actual_result) - - def test_diff_encdec_001(self): - random.seed(0) - modulus = 4 - src_data = make_random_int_tuple(1000, 0, modulus-1) - expected_result = src_data - src = gr.vector_source_b(src_data) - enc = gr.diff_encoder_bb(modulus) - dec = gr.diff_decoder_bb(modulus) - dst = gr.vector_sink_b() - self.tb.connect(src, enc, dec, dst) - self.tb.run() # run the graph and wait for it to finish - actual_result = dst.data() # fetch the contents of the sink - self.assertEqual(expected_result, actual_result) - - def test_diff_encdec_002(self): - random.seed(0) - modulus = 8 - src_data = make_random_int_tuple(40000, 0, modulus-1) - expected_result = src_data - src = gr.vector_source_b(src_data) - enc = gr.diff_encoder_bb(modulus) - dec = gr.diff_decoder_bb(modulus) - dst = gr.vector_sink_b() - self.tb.connect(src, enc, dec, dst) - self.tb.run() # run the graph and wait for it to finish - actual_result = dst.data() # fetch the contents of the sink - self.assertEqual(expected_result, actual_result) - -if __name__ == '__main__': - gr_unittest.run(test_diff_encoder, "test_diff_encoder.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_diff_phasor_cc.py b/gnuradio-core/src/python/gnuradio/gr/qa_diff_phasor_cc.py deleted file mode 100755 index 41f96aa616..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_diff_phasor_cc.py +++ /dev/null @@ -1,50 +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_diff_phasor (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_diff_phasor_cc (self): - src_data = (0+0j, 1+0j, -1+0j, 3+4j, -3-4j, -3+4j) - expected_result = (0+0j, 0+0j, -1+0j, -3-4j, -25+0j, -7-24j) - src = gr.vector_source_c (src_data) - op = gr.diff_phasor_cc () - dst = gr.vector_sink_c () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () # run the graph and wait for it to finish - actual_result = dst.data () # fetch the contents of the sink - self.assertComplexTuplesAlmostEqual (expected_result, actual_result) - - - -if __name__ == '__main__': - gr_unittest.run(test_diff_phasor, "test_diff_phasor.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_ecc_ccsds_27.py b/gnuradio-core/src/python/gnuradio/gr/qa_ecc_ccsds_27.py deleted file mode 100755 index 29122ff3ed..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_ecc_ccsds_27.py +++ /dev/null @@ -1,50 +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_ccsds_27 (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def xtest_ccsds_27 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) - expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) - src = gr.vector_source_b(src_data) - enc = gr.encode_ccsds_27_bb() - b2f = gr.char_to_float() - add = gr.add_const_ff(-0.5) - mul = gr.multiply_const_ff(2.0) - dec = gr.decode_ccsds_27_fb() - dst = gr.vector_sink_b() - self.tb.connect(src, enc, b2f, add, mul, dec, dst) - self.tb.run() - dst_data = dst.data() - self.assertEqual(expected, dst_data) - - -if __name__ == '__main__': - gr_unittest.run(test_ccsds_27, "test_ccsds_27.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_fft.py b/gnuradio-core/src/python/gnuradio/gr/qa_fft.py deleted file mode 100755 index 693d0e67c5..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_fft.py +++ /dev/null @@ -1,212 +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 - -primes = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53, - 59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131, - 137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223, - 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311) - - -class test_fft(gr_unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def assert_fft_ok2(self, expected_result, result_data): - expected_result = expected_result[:len(result_data)] - self.assertComplexTuplesAlmostEqual2 (expected_result, result_data, - abs_eps=1e-9, rel_eps=4e-4) - - def assert_fft_float_ok2(self, expected_result, result_data, abs_eps=1e-9, rel_eps=4e-4): - expected_result = expected_result[:len(result_data)] - self.assertFloatTuplesAlmostEqual2 (expected_result, result_data, - abs_eps, rel_eps) - - def test_001(self): - tb = gr.top_block() - fft_size = 32 - src_data = tuple([complex(primes[2*i], primes[2*i+1]) for i in range(fft_size)]) - - expected_result = ((4377+4516j), - (-1706.1268310546875+1638.4256591796875j), - (-915.2083740234375+660.69427490234375j), - (-660.370361328125+381.59600830078125j), - (-499.96044921875+238.41630554199219j), - (-462.26748657226562+152.88948059082031j), - (-377.98440551757812+77.5928955078125j), - (-346.85821533203125+47.152004241943359j), - (-295+20j), - (-286.33609008789062-22.257017135620117j), - (-271.52999877929688-33.081821441650391j), - (-224.6358642578125-67.019538879394531j), - (-244.24473571777344-91.524826049804688j), - (-203.09068298339844-108.54627227783203j), - (-198.45195007324219-115.90768432617188j), - (-182.97744750976562-128.12318420410156j), - (-167-180j), - (-130.33688354492188-173.83778381347656j), - (-141.19784545898438-190.28807067871094j), - (-111.09677124023438-214.48896789550781j), - (-70.039543151855469-242.41630554199219j), - (-68.960540771484375-228.30015563964844j), - (-53.049201965332031-291.47097778320312j), - (-28.695289611816406-317.64553833007812j), - (57-300j), - (45.301143646240234-335.69509887695312j), - (91.936195373535156-373.32437133789062j), - (172.09465026855469-439.275146484375j), - (242.24473571777344-504.47515869140625j), - (387.81732177734375-666.6788330078125j), - (689.48553466796875-918.2142333984375j), - (1646.539306640625-1694.1956787109375j)) - - src = gr.vector_source_c(src_data) - s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) - fft = gr.fft_vcc(fft_size, True, [], False) - v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_size) - dst = gr.vector_sink_c() - tb.connect(src, s2v, fft, v2s, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - #self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - self.assert_fft_ok2(expected_result, result_data) - - def test_002(self): - tb = gr.top_block() - fft_size = 32 - - tmp_data = ((4377+4516j), - (-1706.1268310546875+1638.4256591796875j), - (-915.2083740234375+660.69427490234375j), - (-660.370361328125+381.59600830078125j), - (-499.96044921875+238.41630554199219j), - (-462.26748657226562+152.88948059082031j), - (-377.98440551757812+77.5928955078125j), - (-346.85821533203125+47.152004241943359j), - (-295+20j), - (-286.33609008789062-22.257017135620117j), - (-271.52999877929688-33.081821441650391j), - (-224.6358642578125-67.019538879394531j), - (-244.24473571777344-91.524826049804688j), - (-203.09068298339844-108.54627227783203j), - (-198.45195007324219-115.90768432617188j), - (-182.97744750976562-128.12318420410156j), - (-167-180j), - (-130.33688354492188-173.83778381347656j), - (-141.19784545898438-190.28807067871094j), - (-111.09677124023438-214.48896789550781j), - (-70.039543151855469-242.41630554199219j), - (-68.960540771484375-228.30015563964844j), - (-53.049201965332031-291.47097778320312j), - (-28.695289611816406-317.64553833007812j), - (57-300j), - (45.301143646240234-335.69509887695312j), - (91.936195373535156-373.32437133789062j), - (172.09465026855469-439.275146484375j), - (242.24473571777344-504.47515869140625j), - (387.81732177734375-666.6788330078125j), - (689.48553466796875-918.2142333984375j), - (1646.539306640625-1694.1956787109375j)) - - src_data = tuple([x/fft_size for x in tmp_data]) - - expected_result = tuple([complex(primes[2*i], primes[2*i+1]) for i in range(fft_size)]) - - src = gr.vector_source_c(src_data) - s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) - fft = gr.fft_vcc(fft_size, False, [], False) - v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_size) - dst = gr.vector_sink_c() - tb.connect(src, s2v, fft, v2s, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - #self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - self.assert_fft_ok2(expected_result, result_data) - - def test_003(self): - # Same test as above, only use 2 threads - - tb = gr.top_block() - fft_size = 32 - - tmp_data = ((4377+4516j), - (-1706.1268310546875+1638.4256591796875j), - (-915.2083740234375+660.69427490234375j), - (-660.370361328125+381.59600830078125j), - (-499.96044921875+238.41630554199219j), - (-462.26748657226562+152.88948059082031j), - (-377.98440551757812+77.5928955078125j), - (-346.85821533203125+47.152004241943359j), - (-295+20j), - (-286.33609008789062-22.257017135620117j), - (-271.52999877929688-33.081821441650391j), - (-224.6358642578125-67.019538879394531j), - (-244.24473571777344-91.524826049804688j), - (-203.09068298339844-108.54627227783203j), - (-198.45195007324219-115.90768432617188j), - (-182.97744750976562-128.12318420410156j), - (-167-180j), - (-130.33688354492188-173.83778381347656j), - (-141.19784545898438-190.28807067871094j), - (-111.09677124023438-214.48896789550781j), - (-70.039543151855469-242.41630554199219j), - (-68.960540771484375-228.30015563964844j), - (-53.049201965332031-291.47097778320312j), - (-28.695289611816406-317.64553833007812j), - (57-300j), - (45.301143646240234-335.69509887695312j), - (91.936195373535156-373.32437133789062j), - (172.09465026855469-439.275146484375j), - (242.24473571777344-504.47515869140625j), - (387.81732177734375-666.6788330078125j), - (689.48553466796875-918.2142333984375j), - (1646.539306640625-1694.1956787109375j)) - - src_data = tuple([x/fft_size for x in tmp_data]) - - expected_result = tuple([complex(primes[2*i], primes[2*i+1]) for i in range(fft_size)]) - - nthreads = 2 - - src = gr.vector_source_c(src_data) - s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size) - fft = gr.fft_vcc(fft_size, False, [], False, nthreads) - v2s = gr.vector_to_stream(gr.sizeof_gr_complex, fft_size) - dst = gr.vector_sink_c() - tb.connect(src, s2v, fft, v2s, dst) - tb.run() - result_data = dst.data() - self.assert_fft_ok2(expected_result, result_data) - -if __name__ == '__main__': - gr_unittest.run(test_fft, "test_fft.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_fft_filter.py b/gnuradio-core/src/python/gnuradio/gr/qa_fft_filter.py deleted file mode 100755 index c0aadc306f..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_fft_filter.py +++ /dev/null @@ -1,383 +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 -import sys -import random - -def make_random_complex_tuple(L): - result = [] - for x in range(L): - result.append(complex(random.uniform(-1000,1000), - random.uniform(-1000,1000))) - return tuple(result) - -def make_random_float_tuple(L): - result = [] - for x in range(L): - result.append(float(int(random.uniform(-1000,1000)))) - return tuple(result) - - -def reference_filter_ccc(dec, taps, input): - """ - compute result using conventional fir filter - """ - tb = gr.top_block() - #src = gr.vector_source_c(((0,) * (len(taps) - 1)) + input) - src = gr.vector_source_c(input) - op = gr.fir_filter_ccc(dec, taps) - dst = gr.vector_sink_c() - tb.connect(src, op, dst) - tb.run() - return dst.data() - -def reference_filter_fff(dec, taps, input): - """ - compute result using conventional fir filter - """ - tb = gr.top_block() - #src = gr.vector_source_f(((0,) * (len(taps) - 1)) + input) - src = gr.vector_source_f(input) - op = gr.fir_filter_fff(dec, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - return dst.data() - - -def print_complex(x): - for i in x: - i = complex(i) - sys.stdout.write("(%6.3f,%6.3fj), " % (i.real, i.imag)) - sys.stdout.write('\n') - - -class test_fft_filter(gr_unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def assert_fft_ok2(self, expected_result, result_data): - expected_result = expected_result[:len(result_data)] - self.assertComplexTuplesAlmostEqual2 (expected_result, result_data, - abs_eps=1e-9, rel_eps=4e-4) - - def assert_fft_float_ok2(self, expected_result, result_data, abs_eps=1e-9, rel_eps=4e-4): - expected_result = expected_result[:len(result_data)] - self.assertFloatTuplesAlmostEqual2 (expected_result, result_data, - abs_eps, rel_eps) - - #def test_ccc_000(self): - # self.assertRaises (RuntimeError, gr.fft_filter_ccc, 2, (1,)) - - def test_ccc_001(self): - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (1,) - expected_result = tuple([complex(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(1, taps) - dst = gr.vector_sink_c() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - - def test_ccc_002(self): - # Test nthreads - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (2,) - nthreads = 2 - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(1, taps, nthreads) - dst = gr.vector_sink_c() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - def test_ccc_003(self): - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (2,) - expected_result = tuple([2 * complex(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(1, taps) - dst = gr.vector_sink_c() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - - def test_ccc_004(self): - random.seed(0) - for i in xrange(25): - # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4*1024 - src_data = make_random_complex_tuple(src_len) - ntaps = int(random.uniform(2, 1000)) - taps = make_random_complex_tuple(ntaps) - expected_result = reference_filter_ccc(1, taps, src_data) - - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(1, taps) - dst = gr.vector_sink_c() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - del tb - - self.assert_fft_ok2(expected_result, result_data) - - def test_ccc_005(self): - random.seed(0) - for i in xrange(25): - # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - dec = i + 1 - src_len = 4*1024 - src_data = make_random_complex_tuple(src_len) - ntaps = int(random.uniform(2, 100)) - taps = make_random_complex_tuple(ntaps) - expected_result = reference_filter_ccc(dec, taps, src_data) - - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(dec, taps) - dst = gr.vector_sink_c() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - del tb - result_data = dst.data() - - self.assert_fft_ok2(expected_result, result_data) - - def test_ccc_006(self): - # Test decimating with nthreads=2 - random.seed(0) - nthreads = 2 - for i in xrange(25): - # sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - dec = i + 1 - src_len = 4*1024 - src_data = make_random_complex_tuple(src_len) - ntaps = int(random.uniform(2, 100)) - taps = make_random_complex_tuple(ntaps) - expected_result = reference_filter_ccc(dec, taps, src_data) - - src = gr.vector_source_c(src_data) - op = gr.fft_filter_ccc(dec, taps, nthreads) - dst = gr.vector_sink_c() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - del tb - result_data = dst.data() - - self.assert_fft_ok2(expected_result, result_data) - - # ---------------------------------------------------------------- - # test _fff version - # ---------------------------------------------------------------- - - def test_fff_001(self): - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (1,) - expected_result = tuple([float(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) - - - def test_fff_002(self): - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (2,) - expected_result = tuple([2 * float(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(1, taps) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - #print 'expected:', expected_result - #print 'results: ', result_data - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) - - def test_fff_003(self): - # Test 02 with nthreads - tb = gr.top_block() - src_data = (0,1,2,3,4,5,6,7) - taps = (2,) - nthreads = 2 - expected_result = tuple([2 * float(x) for x in (0,1,2,3,4,5,6,7)]) - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(1, taps, nthreads) - dst = gr.vector_sink_f() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 5) - - def xtest_fff_004(self): - random.seed(0) - for i in xrange(25): - sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4096 - src_data = make_random_float_tuple(src_len) - ntaps = int(random.uniform(2, 1000)) - taps = make_random_float_tuple(ntaps) - expected_result = reference_filter_fff(1, taps, src_data) - - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(1, taps) - dst = gr.vector_sink_f() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - - #print "src_len =", src_len, " ntaps =", ntaps - try: - self.assert_fft_float_ok2(expected_result, result_data, abs_eps=1.0) - except: - expected = open('expected', 'w') - for x in expected_result: - expected.write(`x` + '\n') - actual = open('actual', 'w') - for x in result_data: - actual.write(`x` + '\n') - raise - - def xtest_fff_005(self): - random.seed(0) - for i in xrange(25): - sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - src_len = 4*1024 - src_data = make_random_float_tuple(src_len) - ntaps = int(random.uniform(2, 1000)) - taps = make_random_float_tuple(ntaps) - expected_result = reference_filter_fff(1, taps, src_data) - - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(1, taps) - dst = gr.vector_sink_f() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - - self.assert_fft_float_ok2(expected_result, result_data, abs_eps=2.0) - - def xtest_fff_006(self): - random.seed(0) - for i in xrange(25): - sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - dec = i + 1 - src_len = 4*1024 - src_data = make_random_float_tuple(src_len) - ntaps = int(random.uniform(2, 100)) - taps = make_random_float_tuple(ntaps) - expected_result = reference_filter_fff(dec, taps, src_data) - - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(dec, taps) - dst = gr.vector_sink_f() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - - self.assert_fft_float_ok2(expected_result, result_data) - - def xtest_fff_007(self): - # test decimation with nthreads - random.seed(0) - nthreads = 2 - for i in xrange(25): - sys.stderr.write("\n>>> Loop = %d\n" % (i,)) - dec = i + 1 - src_len = 4*1024 - src_data = make_random_float_tuple(src_len) - ntaps = int(random.uniform(2, 100)) - taps = make_random_float_tuple(ntaps) - expected_result = reference_filter_fff(dec, taps, src_data) - - src = gr.vector_source_f(src_data) - op = gr.fft_filter_fff(dec, taps, nthreads) - dst = gr.vector_sink_f() - tb = gr.top_block() - tb.connect(src, op, dst) - tb.run() - result_data = dst.data() - - self.assert_fft_float_ok2(expected_result, result_data) - - def test_fff_get0(self): - random.seed(0) - for i in xrange(25): - ntaps = int(random.uniform(2, 100)) - taps = make_random_float_tuple(ntaps) - - op = gr.fft_filter_fff(1, taps) - result_data = op.taps() - #print result_data - - self.assertEqual(taps, result_data) - - def test_ccc_get0(self): - random.seed(0) - for i in xrange(25): - ntaps = int(random.uniform(2, 100)) - taps = make_random_complex_tuple(ntaps) - - op = gr.fft_filter_ccc(1, taps) - result_data = op.taps() - #print result_data - - self.assertComplexTuplesAlmostEqual(taps, result_data, 4) - - -if __name__ == '__main__': - gr_unittest.run(test_fft_filter, "test_fft_filter.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_filter_delay_fc.py b/gnuradio-core/src/python/gnuradio/gr/qa_filter_delay_fc.py deleted file mode 100755 index 8d325fc3e6..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_filter_delay_fc.py +++ /dev/null @@ -1,317 +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_filter_delay_fc (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001_filter_delay_one_input (self): - - # expected result - expected_result = ( -1.4678005338941702e-11j, - -0.0011950774351134896j, - -0.0019336787518113852j, - -0.0034673355985432863j, - -0.0036765895783901215j, - -0.004916108213365078j, - -0.0042778430506587029j, - -0.006028641015291214j, - -0.005476709920912981j, - -0.0092810001224279404j, - -0.0095402700826525688j, - -0.016060983762145042j, - -0.016446959227323532j, - -0.02523401565849781j, - -0.024382550269365311j, - -0.035477779805660248j, - -0.033021725714206696j, - -0.048487484455108643j, - -0.04543270543217659j, - -0.069477587938308716j, - -0.066984444856643677j, - -0.10703597217798233j, - -0.10620346665382385j, - -0.1852707713842392j, - -0.19357112050056458j, - (7.2191945754696007e-09 -0.50004088878631592j), - (0.58778399229049683 -0.6155126690864563j), - (0.95105588436126709 -0.12377222627401352j), - (0.95105588436126709 +0.41524654626846313j), - (0.5877838134765625 +0.91611981391906738j), - (5.8516356205018383e-09 +1.0670661926269531j), - (-0.5877840518951416 +0.87856143712997437j), - (-0.95105588436126709 +0.35447561740875244j), - (-0.95105588436126709 -0.26055556535720825j), - (-0.5877838134765625 -0.77606213092803955j), - (-8.7774534307527574e-09 -0.96460390090942383j), - (0.58778399229049683 -0.78470128774642944j), - (0.95105588436126709 -0.28380891680717468j), - (0.95105588436126709 +0.32548999786376953j), - (0.5877838134765625 +0.82514488697052002j), - (1.4629089051254596e-08 +1.0096219778060913j), - (-0.5877840518951416 +0.81836479902267456j), - (-0.95105588436126709 +0.31451958417892456j), - (-0.95105588436126709 -0.3030143678188324j), - (-0.5877838134765625 -0.80480599403381348j), - (-1.7554906861505515e-08 -0.99516552686691284j), - (0.58778399229049683 -0.80540722608566284j), - (0.95105582475662231 -0.30557557940483093j), - (0.95105588436126709 +0.31097668409347534j), - (0.5877838134765625 +0.81027895212173462j), - (2.3406542482007353e-08 +1.0000816583633423j), - (-0.5877840518951416 +0.80908381938934326j), - (-0.95105588436126709 +0.30904293060302734j), - (-0.95105588436126709 -0.30904296040534973j), - (-0.5877838134765625 -0.80908387899398804j), - (-2.6332360292258272e-08 -1.0000815391540527j), - (0.58778399229049683 -0.80908381938934326j), - (0.95105582475662231 -0.30904299020767212j), - (0.95105588436126709 +0.30904293060302734j), - (0.5877838134765625 +0.80908381938934326j), - (3.218399768911695e-08 +1.0000815391540527j)) - - tb = self.tb - - sampling_freq = 100 - - ntaps = 51 - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 1.0) - head = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10)) - dst2 = gr.vector_sink_c () - - # calculate taps - taps = gr.firdes_hilbert (ntaps) - hd = gr.filter_delay_fc (taps) - - tb.connect (src1, head) - tb.connect (head, hd) - tb.connect (hd,dst2) - - tb.run () - - # get output - result_data = dst2.data () - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - def test_002_filter_delay_two_inputs (self): - - # giving the same signal to both the inputs should fetch the same results - # as above - - # expected result - expected_result = ( -1.4678005338941702e-11j, - -0.0011950774351134896j, - -0.0019336787518113852j, - -0.0034673355985432863j, - -0.0036765895783901215j, - -0.004916108213365078j, - -0.0042778430506587029j, - -0.006028641015291214j, - -0.005476709920912981j, - -0.0092810001224279404j, - -0.0095402700826525688j, - -0.016060983762145042j, - -0.016446959227323532j, - -0.02523401565849781j, - -0.024382550269365311j, - -0.035477779805660248j, - -0.033021725714206696j, - -0.048487484455108643j, - -0.04543270543217659j, - -0.069477587938308716j, - -0.066984444856643677j, - -0.10703597217798233j, - -0.10620346665382385j, - -0.1852707713842392j, - -0.19357112050056458j, - (7.2191945754696007e-09 -0.50004088878631592j), - (0.58778399229049683 -0.6155126690864563j), - (0.95105588436126709 -0.12377222627401352j), - (0.95105588436126709 +0.41524654626846313j), - (0.5877838134765625 +0.91611981391906738j), - (5.8516356205018383e-09 +1.0670661926269531j), - (-0.5877840518951416 +0.87856143712997437j), - (-0.95105588436126709 +0.35447561740875244j), - (-0.95105588436126709 -0.26055556535720825j), - (-0.5877838134765625 -0.77606213092803955j), - (-8.7774534307527574e-09 -0.96460390090942383j), - (0.58778399229049683 -0.78470128774642944j), - (0.95105588436126709 -0.28380891680717468j), - (0.95105588436126709 +0.32548999786376953j), - (0.5877838134765625 +0.82514488697052002j), - (1.4629089051254596e-08 +1.0096219778060913j), - (-0.5877840518951416 +0.81836479902267456j), - (-0.95105588436126709 +0.31451958417892456j), - (-0.95105588436126709 -0.3030143678188324j), - (-0.5877838134765625 -0.80480599403381348j), - (-1.7554906861505515e-08 -0.99516552686691284j), - (0.58778399229049683 -0.80540722608566284j), - (0.95105582475662231 -0.30557557940483093j), - (0.95105588436126709 +0.31097668409347534j), - (0.5877838134765625 +0.81027895212173462j), - (2.3406542482007353e-08 +1.0000816583633423j), - (-0.5877840518951416 +0.80908381938934326j), - (-0.95105588436126709 +0.30904293060302734j), - (-0.95105588436126709 -0.30904296040534973j), - (-0.5877838134765625 -0.80908387899398804j), - (-2.6332360292258272e-08 -1.0000815391540527j), - (0.58778399229049683 -0.80908381938934326j), - (0.95105582475662231 -0.30904299020767212j), - (0.95105588436126709 +0.30904293060302734j), - (0.5877838134765625 +0.80908381938934326j), - (3.218399768911695e-08 +1.0000815391540527j)) - - - tb = self.tb - - sampling_freq = 100 - ntaps = 51 - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 1.0) - head = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10)) - dst2 = gr.vector_sink_c () - - - # calculate taps - taps = gr.firdes_hilbert (ntaps) - hd = gr.filter_delay_fc (taps) - - tb.connect (src1, head) - tb.connect (head, (hd,0)) - tb.connect (head, (hd,1)) - tb.connect (hd,dst2) - tb.run () - - # get output - result_data = dst2.data () - - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - - def test_003_filter_delay_two_inputs (self): - - # give two different inputs - - # expected result - expected_result = ( -0.0020331963896751404j, - -0.0016448829555884004j, - -0.0032375147566199303j, - -0.0014826074475422502j, - -0.0033034090884029865j, - -0.00051144487224519253j, - -0.0043686260469257832j, - -0.0010198024101555347j, - -0.0082517862319946289j, - -0.003456643782556057j, - -0.014193611219525337j, - -0.005875137634575367j, - -0.020293503999710083j, - -0.0067503536120057106j, - -0.026798896491527557j, - -0.0073488112539052963j, - -0.037041611969470978j, - -0.010557252913713455j, - -0.055669989436864853j, - -0.018332764506340027j, - -0.089904911816120148j, - -0.033361352980136871j, - -0.16902604699134827j, - -0.074318811297416687j, - -0.58429563045501709j, - (7.2191945754696007e-09 -0.35892376303672791j), - (0.58778399229049683 +0.63660913705825806j), - (0.95105588436126709 +0.87681591510772705j), - (0.95105588436126709 +0.98705857992172241j), - (0.5877838134765625 +0.55447429418563843j), - (5.8516356205018383e-09 +0.026006083935499191j), - (-0.5877840518951416 -0.60616838932037354j), - (-0.95105588436126709 -0.9311758279800415j), - (-0.95105588436126709 -0.96169203519821167j), - (-0.5877838134765625 -0.57292771339416504j), - (-8.7774534307527574e-09 -0.0073488391935825348j), - (0.58778399229049683 +0.59720659255981445j), - (0.95105588436126709 +0.94438445568084717j), - (0.95105588436126709 +0.95582199096679688j), - (0.5877838134765625 +0.58196049928665161j), - (1.4629089051254596e-08 +0.0026587247848510742j), - (-0.5877840518951416 -0.59129220247268677j), - (-0.95105588436126709 -0.94841635227203369j), - (-0.95105588436126709 -0.95215457677841187j), - (-0.5877838134765625 -0.58535969257354736j), - (-1.7554906861505515e-08 -0.00051158666610717773j), - (0.58778399229049683 +0.58867418766021729j), - (0.95105582475662231 +0.94965213537216187j), - (0.95105588436126709 +0.95050644874572754j), - (0.5877838134765625 +0.58619076013565063j), - (2.3406542482007353e-08 +1.1920928955078125e-07j), - (-0.5877840518951416 -0.58783555030822754j), - (-0.95105588436126709 -0.95113480091094971j), - (-0.95105588436126709 -0.95113474130630493j), - (-0.5877838134765625 -0.58783555030822754j), - (-2.6332360292258272e-08 -8.1956386566162109e-08j), - (0.58778399229049683 +0.58783555030822754j), - (0.95105582475662231 +0.95113474130630493j), - (0.95105588436126709 +0.95113474130630493j), - (0.5877838134765625 +0.58783560991287231j), - (3.218399768911695e-08 +1.1920928955078125e-07j)) - - tb = self.tb - - sampling_freq = 100 - ntaps = 51 - - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,sampling_freq * 0.10, 1.0) - src2 = gr.sig_source_f (sampling_freq, gr.GR_COS_WAVE,sampling_freq * 0.10, 1.0) - - head1 = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10)) - head2 = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10)) - - taps = gr.firdes_hilbert (ntaps) - hd = gr.filter_delay_fc (taps) - - dst2 = gr.vector_sink_c () - - tb.connect (src1, head1) - tb.connect (src2, head2) - - tb.connect (head1, (hd,0)) - tb.connect (head2, (hd,1)) - tb.connect (hd, dst2) - - tb.run () - - # get output - result_data = dst2.data () - - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - -if __name__ == '__main__': - gr_unittest.run(test_filter_delay_fc, "test_filter_delay_fc.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_fractional_interpolator.py b/gnuradio-core/src/python/gnuradio/gr/qa_fractional_interpolator.py deleted file mode 100755 index e19bb28f31..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_fractional_interpolator.py +++ /dev/null @@ -1,38 +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 - -class test_fractional_resampler (gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def test_000_make(self): - op = gr.fractional_interpolator_ff(0.0, 1.0) - op2 = gr.fractional_interpolator_cc(0.0, 1.0) - -if __name__ == '__main__': - gr_unittest.run(test_fractional_resampler, "test_fractional_resampler.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_frequency_modulator.py b/gnuradio-core/src/python/gnuradio/gr/qa_frequency_modulator.py deleted file mode 100755 index 23459fff3f..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_frequency_modulator.py +++ /dev/null @@ -1,56 +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 - -def sincos(x): - return math.cos(x) + math.sin(x) * 1j - - -class test_frequency_modulator (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_fm_001 (self): - pi = math.pi - sensitivity = pi/4 - src_data = (1.0/4, 1.0/2, 1.0/4, -1.0/4, -1.0/2, -1/4.0) - running_sum = (pi/16, 3*pi/16, pi/4, 3*pi/16, pi/16, 0) - expected_result = tuple ([sincos (x) for x in running_sum]) - src = gr.vector_source_f (src_data) - op = gr.frequency_modulator_fc (sensitivity) - dst = gr.vector_sink_c () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5) - - -if __name__ == '__main__': - gr_unittest.run(test_frequency_modulator, "test_frequency_modulator.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_fsk_stuff.py b/gnuradio-core/src/python/gnuradio/gr/qa_fsk_stuff.py deleted file mode 100755 index 95b8c06641..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_fsk_stuff.py +++ /dev/null @@ -1,75 +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 - -def sincos(x): - return math.cos(x) + math.sin(x) * 1j - -class test_bytes_to_syms (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_bytes_to_syms_001 (self): - src_data = (0x01, 0x80, 0x03) - expected_result = (-1, -1, -1, -1, -1, -1, -1, +1, - +1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, +1, +1) - src = gr.vector_source_b (src_data) - op = gr.bytes_to_syms () - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (expected_result, result_data) - - def test_simple_framer (self): - src_data = (0x00, 0x11, 0x22, 0x33, - 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, - 0xcc, 0xdd, 0xee, 0xff) - - expected_result = ( - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x00, 0x00, 0x11, 0x22, 0x33, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x01, 0x44, 0x55, 0x66, 0x77, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x02, 0x88, 0x99, 0xaa, 0xbb, 0x55, - 0xac, 0xdd, 0xa4, 0xe2, 0xf2, 0x8c, 0x20, 0xfc, 0x03, 0xcc, 0xdd, 0xee, 0xff, 0x55) - - src = gr.vector_source_b (src_data) - op = gr.simple_framer (4) - dst = gr.vector_sink_b () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertEqual (expected_result, result_data) - - -if __name__ == '__main__': - gr_unittest.run(test_bytes_to_syms, "test_bytes_to_syms.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py b/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py deleted file mode 100755 index 161e4a5cc1..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_glfsr_source.py +++ /dev/null @@ -1,94 +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 - -class test_glfsr_source(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_000_make_b(self): - src = gr.glfsr_source_b(16) - self.assertEquals(src.mask(), 0x8016) - self.assertEquals(src.period(), 2**16-1) - - def test_001_degree_b(self): - self.assertRaises(RuntimeError, - lambda: gr.glfsr_source_b(0)) - self.assertRaises(RuntimeError, - lambda: gr.glfsr_source_b(33)) - - def test_002_correlation_b(self): - for degree in range(1,11): # Higher degrees take too long to correlate - src = gr.glfsr_source_b(degree, False) - b2f = gr.chunks_to_symbols_bf((-1.0,1.0), 1) - dst = gr.vector_sink_f() - del self.tb # Discard existing top block - self.tb = gr.top_block() - self.tb.connect(src, b2f, dst) - self.tb.run() - self.tb.disconnect_all() - actual_result = dst.data() - R = auto_correlate(actual_result) - self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin - for i in range(len(R)-1): - self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else - - def test_003_make_f(self): - src = gr.glfsr_source_f(16) - self.assertEquals(src.mask(), 0x8016) - self.assertEquals(src.period(), 2**16-1) - - def test_004_degree_f(self): - self.assertRaises(RuntimeError, - lambda: gr.glfsr_source_f(0)) - self.assertRaises(RuntimeError, - lambda: gr.glfsr_source_f(33)) - def test_005_correlation_f(self): - for degree in range(1,11): # Higher degrees take too long to correlate - src = gr.glfsr_source_f(degree, False) - dst = gr.vector_sink_f() - del self.tb # Discard existing top block - self.tb = gr.top_block() - self.tb.connect(src, dst) - self.tb.run() - - actual_result = dst.data() - R = auto_correlate(actual_result) - self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin - for i in range(len(R)-1): - self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else - -def auto_correlate(data): - l = len(data) - R = [0,]*l - for lag in range(l): - for i in range(l): - R[lag] += data[i]*data[i-lag] - return R - -if __name__ == '__main__': - gr_unittest.run(test_glfsr_source, "test_glfsr_source.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_goertzel.py b/gnuradio-core/src/python/gnuradio/gr/qa_goertzel.py deleted file mode 100755 index 77f1b5f897..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_goertzel.py +++ /dev/null @@ -1,64 +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 -from math import pi, cos - -class test_goertzel(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def make_tone_data(self, rate, freq): - return [cos(2*pi*x*freq/rate) for x in range(rate)] - - def transform(self, src_data, rate, freq): - src = gr.vector_source_f(src_data, False) - dft = gr.goertzel_fc(rate, rate, freq) - dst = gr.vector_sink_c() - self.tb.connect(src, dft, dst) - self.tb.run() - return dst.data() - - def test_001(self): # Measure single tone magnitude - rate = 8000 - freq = 100 - bin = freq - src_data = self.make_tone_data(rate, freq) - expected_result = 0.5 - actual_result = abs(self.transform(src_data, rate, bin)[0]) - self.assertAlmostEqual(expected_result, actual_result, places=4) - - def test_002(self): # Measure off frequency magnitude - rate = 8000 - freq = 100 - bin = freq/2 - src_data = self.make_tone_data(rate, freq) - expected_result = 0.0 - actual_result = abs(self.transform(src_data, rate, bin)[0]) - self.assertAlmostEqual(expected_result, actual_result, places=4) - -if __name__ == '__main__': - gr_unittest.run(test_goertzel, "test_goertzel.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_hilbert.py b/gnuradio-core/src/python/gnuradio/gr/qa_hilbert.py deleted file mode 100755 index 27d01092bb..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_hilbert.py +++ /dev/null @@ -1,116 +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_hilbert (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_hilbert (self): - tb = self.tb - ntaps = 51 - sampling_freq = 100 - - expected_result = ( -1.4678005338941702e-11j, - -0.0011950774351134896j, - -0.0019336787518113852j, - -0.0034673355985432863j, - -0.0036765895783901215j, - -0.004916108213365078j, - -0.0042778430506587029j, - -0.006028641015291214j, - -0.005476709920912981j, - -0.0092810001224279404j, - -0.0095402700826525688j, - -0.016060983762145042j, - -0.016446959227323532j, - -0.02523401565849781j, - -0.024382550269365311j, - -0.035477779805660248j, - -0.033021725714206696j, - -0.048487484455108643j, - -0.04543270543217659j, - -0.069477587938308716j, - -0.066984444856643677j, - -0.10703597217798233j, - -0.10620346665382385j, - -0.1852707713842392j, - -0.19357112050056458j, - (7.2191945754696007e-09 -0.50004088878631592j), - (0.58778399229049683 -0.6155126690864563j), - (0.95105588436126709 -0.12377222627401352j), - (0.95105588436126709 +0.41524654626846313j), - (0.5877838134765625 +0.91611981391906738j), - (5.8516356205018383e-09 +1.0670661926269531j), - (-0.5877840518951416 +0.87856143712997437j), - (-0.95105588436126709 +0.35447561740875244j), - (-0.95105588436126709 -0.26055556535720825j), - (-0.5877838134765625 -0.77606213092803955j), - (-8.7774534307527574e-09 -0.96460390090942383j), - (0.58778399229049683 -0.78470128774642944j), - (0.95105588436126709 -0.28380891680717468j), - (0.95105588436126709 +0.32548999786376953j), - (0.5877838134765625 +0.82514488697052002j), - (1.4629089051254596e-08 +1.0096219778060913j), - (-0.5877840518951416 +0.81836479902267456j), - (-0.95105588436126709 +0.31451958417892456j), - (-0.95105588436126709 -0.3030143678188324j), - (-0.5877838134765625 -0.80480599403381348j), - (-1.7554906861505515e-08 -0.99516552686691284j), - (0.58778399229049683 -0.80540722608566284j), - (0.95105582475662231 -0.30557557940483093j), - (0.95105588436126709 +0.31097668409347534j), - (0.5877838134765625 +0.81027895212173462j), - (2.3406542482007353e-08 +1.0000816583633423j), - (-0.5877840518951416 +0.80908381938934326j), - (-0.95105588436126709 +0.30904293060302734j), - (-0.95105588436126709 -0.30904296040534973j), - (-0.5877838134765625 -0.80908387899398804j), - (-2.6332360292258272e-08 -1.0000815391540527j), - (0.58778399229049683 -0.80908381938934326j), - (0.95105582475662231 -0.30904299020767212j), - (0.95105588436126709 +0.30904293060302734j), - (0.5877838134765625 +0.80908381938934326j), - (3.218399768911695e-08 +1.0000815391540527j)) - - - src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE, - sampling_freq * 0.10, 1.0) - - head = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10)) - hilb = gr.hilbert_fc (ntaps) - dst1 = gr.vector_sink_c () - tb.connect (src1, head) - tb.connect (head, hilb) - tb.connect (hilb, dst1) - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5) - -if __name__ == '__main__': - gr_unittest.run(test_hilbert, "test_hilbert.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_iir.py b/gnuradio-core/src/python/gnuradio/gr/qa_iir.py deleted file mode 100755 index 06b8d767ed..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_iir.py +++ /dev/null @@ -1,159 +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_iir (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_iir_direct_001 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = () - fbtaps = () - expected_result = (0, 0, 0, 0, 0, 0, 0, 0) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_002 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = (2,) - fbtaps = (0,) - expected_result = (2, 4, 6, 8, 10, 12, 14, 16) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_003 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = (2, 11) - fbtaps = (0, 0) - expected_result = (2, 15, 28, 41, 54, 67, 80, 93) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_004 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = (2, 11) - fbtaps = (0, -1) - expected_result = (2, 13, 15, 26, 28, 39, 41, 52) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_005 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - fftaps = (2, 11, 0) - fbtaps = (0, -1, 3) - expected_result = (2, 13, 21, 59, 58, 186, 68, 583) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_006 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - expected_result = (2, 13, 21, 59, 58, 186, 68, 583) - fftaps = (2, 1) - fbtaps = (0, -1) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - fftaps = (2, 11, 0) - fbtaps = (0, -1, 3) - op.set_taps (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_007 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - expected_result = (2,2,5,5,8,8,11,11) - fftaps = (2, 1) - fbtaps = (0, -1) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - fftaps = (2,0,1) - fbtaps = (0, -1) - op.set_taps (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - def test_iir_direct_008 (self): - src_data = (1, 2, 3, 4, 5, 6, 7, 8) - expected_result = (2,4,4,10,18,14,26,56) - fftaps = (2,) - fbtaps = (0, 1) - src = gr.vector_source_f (src_data) - op = gr.iir_filter_ffd (fftaps, fbtaps) - fftaps_data = (1) - fbtaps = (0,0, -1,3) - op.set_taps (fftaps, fbtaps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - self.assertFloatTuplesAlmostEqual (expected_result, result_data) - - - - -if __name__ == '__main__': - gr_unittest.run(test_iir, "test_iir.xml") - 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_interp_fir_filter.py b/gnuradio-core/src/python/gnuradio/gr/qa_interp_fir_filter.py deleted file mode 100755 index 9bd9977c75..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_interp_fir_filter.py +++ /dev/null @@ -1,54 +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_interp_fir_filter (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_fff (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) - expected_result = tuple ([float (x) for x in xr]) - - src = gr.vector_source_f (src_data) - op = gr.interp_fir_filter_fff (interpolation, taps) - dst = gr.vector_sink_f () - self.tb.connect (src, op) - self.tb.connect (op, dst) - self.tb.run () - result_data = dst.data () - L = min(len(result_data), len(expected_result)) - self.assertEqual (expected_result[0:L], result_data[0:L]) - - -if __name__ == '__main__': - gr_unittest.run(test_interp_fir_filter, "test_interp_fir_filter.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_kludged_imports.py b/gnuradio-core/src/python/gnuradio/gr/qa_kludged_imports.py index 39b5d781e2..f80188c9fc 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_kludged_imports.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_kludged_imports.py @@ -30,10 +30,6 @@ class test_kludged_imports (gr_unittest.TestCase): def tearDown(self): pass - def test_blks_import(self): - # make sure that this somewhat magic import works - from gnuradio import blks2 - def test_gru_import(self): # make sure that this somewhat magic import works from gnuradio import gru 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 a87ed87eef..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_nlog10.py +++ /dev/null @@ -1,47 +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 - -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_noise.py b/gnuradio-core/src/python/gnuradio/gr/qa_noise.py deleted file mode 100755 index e875191507..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_noise.py +++ /dev/null @@ -1,51 +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 - -class test_noise_source(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - # Just confirm that we can instantiate a noise source - op = gr.noise_source_f(gr.GR_GAUSSIAN, 10, 10) - - def test_002(self): - # Test get methods - set_type = gr.GR_GAUSSIAN - set_ampl = 10 - op = gr.noise_source_f(set_type, set_ampl, 10) - get_type = op.type() - get_ampl = op.amplitude() - - self.assertEqual(get_type, set_type) - self.assertEqual(get_ampl, set_ampl) - - -if __name__ == '__main__': - gr_unittest.run(test_noise_source, "test_noise_source.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py b/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py index 572d8b1861..59f927fa19 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_pdu.py @@ -46,23 +46,23 @@ class test_pdu(gr_unittest.TestCase): # Test that the right number of ports exist. pi = dbg.message_ports_in() po = dbg.message_ports_out() - self.assertEqual(pmt.pmt_length(pi), 2) - self.assertEqual(pmt.pmt_length(po), 0) + self.assertEqual(pmt.length(pi), 2) + self.assertEqual(pmt.length(po), 0) pi = snk3.message_ports_in() po = snk3.message_ports_out() - self.assertEqual(pmt.pmt_length(pi), 0) - self.assertEqual(pmt.pmt_length(po), 1) + self.assertEqual(pmt.length(pi), 0) + self.assertEqual(pmt.length(po), 1) #print "Message Debug input ports: " - #pmt.pmt_print(pi) + #pmt.print(pi) #print "Message Debug output ports: " - #pmt.pmt_print(po) + #pmt.print(po) #print "Stream to PDU input ports: " - #pmt.pmt_print(pi) + #pmt.print(pi) #print "Stream to PDU output ports: " - #pmt.pmt_print(po) + #pmt.print(po) time.sleep(0.1) self.tb.connect(src, snk) @@ -73,12 +73,12 @@ class test_pdu(gr_unittest.TestCase): self.tb.start() # make our reference and message pmts - port = pmt.pmt_intern("pdus") - msg = pmt.pmt_cons( pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF) ) + port = pmt.intern("pdus") + msg = pmt.cons( pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF) ) #print "printing port & msg" - #pmt.pmt_print(port) - #pmt.pmt_print(msg) + #print(port) + #print(msg) # post the message src.to_basic_block()._post( port, msg ) @@ -94,13 +94,13 @@ class test_pdu(gr_unittest.TestCase): # Get the vector of data from the message sink # Convert the message PMT as a pair into its vector result_msg = dbg.get_message(0) - msg_vec = pmt.pmt_cdr(result_msg) - pmt.pmt_print(msg_vec) + msg_vec = pmt.cdr(result_msg) + print(msg_vec) # Convert the PMT vector into a Python list msg_data = [] for i in xrange(16): - msg_data.append(pmt.pmt_u8vector_ref(msg_vec, i)) + msg_data.append(pmt.u8vector_ref(msg_vec, i)) actual_data = 16*[0xFF,] self.assertEqual(actual_data, list(result_data)) 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_pll_carriertracking.py b/gnuradio-core/src/python/gnuradio/gr/qa_pll_carriertracking.py deleted file mode 100755 index 8964db53db..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pll_carriertracking.py +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,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. -# - -from gnuradio import gr, gr_unittest -import math - -class test_pll_carriertracking (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block() - - def tearDown (self): - self.tb = None - - def test_pll_carriertracking (self): - expected_result = ((1.00000238419+7.21919457547e-09j), - (0.998025715351+0.062790453434j), - (0.992777824402+0.119947694242j), - (0.985192835331+0.171441286802j), - (0.976061582565+0.217501848936j), - (0.966034710407+0.258409559727j), - (0.95565611124+0.294477283955j), - (0.945357382298+0.326030552387j), - (0.935475051403+0.353395611048j), - (0.926258146763+0.376889169216j), - (0.917895197868+0.39681750536j), - (0.910515546799+0.413470208645j), - (0.904196679592+0.427117019892j), - (0.898972511292+0.438006043434j), - (0.894769787788+0.446523308754j), - (0.891652584076+0.452715367079j), - (0.8895829916+0.456773489714j), - (0.888502895832+0.458873122931j), - (0.888343691826+0.459175437689j), - (0.889035582542+0.457833081484j), - (0.890497922897+0.454985737801j), - (0.892645597458+0.450762689114j), - (0.895388305187+0.445282936096j), - (0.898648142815+0.438664674759j), - (0.902342617512+0.431016951799j), - (0.906392872334+0.422441422939j), - (0.910642921925+0.413191765547j), - (0.915039420128+0.403358519077j), - (0.919594764709+0.392864197493j), - (0.92425006628+0.381792247295j), - (0.928944349289+0.370217680931j), - (0.933634519577+0.358220815659j), - (0.938279032707+0.345874190331j), - (0.942840516567+0.333247303963j), - (0.947280526161+0.32040438056j), - (0.951574921608+0.307409763336j), - (0.955703914165+0.294323593378j), - (0.959648966789+0.281201630831j), - (0.963392794132+0.268095195293j), - (0.966880619526+0.255221515894j), - (0.970162451267+0.242447137833j), - (0.973235487938+0.229809194803j), - (0.97609680891+0.217341512442j), - (0.978744983673+0.20507311821j), - (0.981189727783+0.193033605814j), - (0.983436584473+0.181248426437j), - (0.985490739346+0.169738590717j), - (0.987353682518+0.158523857594j), - (0.989041447639+0.147622272372j), - (0.990563035011+0.137049794197j), - (0.991928339005+0.126818582416j), - (0.993117690086+0.117111675441j), - (0.994156062603+0.107930034399j), - (0.995076179504+0.0990980416536j), - (0.995887458324+0.0906178802252j), - (0.996591091156+0.0824909061193j), - (0.997202515602+0.0747182965279j), - (0.997730851173+0.0672992765903j), - (0.998185396194+0.0602316558361j), - (0.99856698513+0.0535135567188j), - (0.998885989189+0.0471420884132j), - (0.99915266037+0.0411129891872j), - (0.999372899532+0.0354214012623j), - (0.999548316002+0.0300626158714j), - (0.999680638313+0.0252036750317j), - (0.999784469604+0.020652115345j), - (0.999865531921+0.0163950324059j), - (0.999923825264+0.0124222636223j), - (0.999960243702+0.00872156023979j), - (0.999983668327+0.00528120994568j), - (0.999997138977+0.00209015607834j), - (1.00000119209-0.00086285173893j), - (0.999992132187-0.00358882546425j), - (0.999979138374-0.00609711557627j), - (0.999963641167-0.00839691981673j), - (0.999947249889-0.0104993218556j), - (0.999924004078-0.0122378543019j), - (0.999904811382-0.0136305987835j), - (0.999888062477-0.0148707330227j), - (0.9998742342-0.0159679055214j), - (0.999856114388-0.0169314742088j), - (0.999839782715-0.0177700817585j), - (0.999826967716-0.0184917747974j), - (0.999818325043-0.0191045701504j), - (0.999807476997-0.0196143388748j), - (0.999797284603-0.0200265944004j), - (0.999791204929-0.0203481912613j), - (0.99978852272-0.0205836892128j), - (0.99978530407-0.0207380950451j), - (0.999785065651-0.0206423997879j), - (0.999787807465-0.0204866230488j), - (0.999794304371-0.0202808082104j), - (0.999800384045-0.0200312435627j), - (0.999803245068-0.0197458267212j), - (0.9998087883-0.0194311738014j), - (0.999816894531-0.0190933048725j), - (0.999825954437-0.0187371373177j), - (0.999829888344-0.0183679759502j), - (0.999835848808-0.017987690866j), - (0.999844014645-0.0176006518304j)) - - sampling_freq = 10e3 - freq = sampling_freq / 100 - - loop_bw = math.pi/100.0 - maxf = 1 - minf = -1 - - src = gr.sig_source_c (sampling_freq, gr.GR_COS_WAVE, freq, 1.0) - pll = gr.pll_carriertracking_cc(loop_bw, maxf, minf) - head = gr.head (gr.sizeof_gr_complex, int (freq)) - dst = gr.vector_sink_c () - - self.tb.connect (src, pll, head) - self.tb.connect (head, dst) - - self.tb.run () - dst_data = dst.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5) - -if __name__ == '__main__': - gr_unittest.run(test_pll_carriertracking, "test_pll_carriertracking.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pll_freqdet.py b/gnuradio-core/src/python/gnuradio/gr/qa_pll_freqdet.py deleted file mode 100755 index 219e9b84b6..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pll_freqdet.py +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,2007,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. -# - -from gnuradio import gr, gr_unittest -import math - -class test_pll_freqdet (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block() - - def tearDown (self): - self.tb = None - - def test_pll_freqdet (self): - expected_result = (0.0, - 4.33888922882e-08, - 0.367369994515, - 1.08135249597, - 2.10983253908, - 3.42221529438, - 4.98940390402, - 6.78379190842, - 8.77923286024, - 10.9510106794, - 13.2758363182, - 15.7317829127, - 18.2982902299, - 20.9561068599, - 23.6755271122, - 26.452952094, - 29.2731265301, - 32.1219053479, - 34.9862418188, - 37.8540971414, - 40.7144315483, - 43.5571390869, - 46.3730179743, - 49.1537231663, - 51.8917218889, - 54.58026103, - 57.2015358514, - 59.7513664199, - 62.2380533124, - 64.657612252, - 67.006640002, - 69.2822432184, - 71.4820384499, - 73.6041047056, - 75.6469478817, - 77.6094829742, - 79.4909866472, - 81.2911031615, - 83.0097850853, - 84.6355598352, - 86.1820937186, - 87.6504420946, - 89.0418441206, - 90.3577286819, - 91.5996432431, - 92.7692775646, - 93.8684162704, - 94.8989269904, - 95.8627662892, - 96.7619381633, - 97.598505899, - 98.362769679, - 99.0579904444, - 99.6992633875, - 100.288805948, - 100.828805921, - 101.321421457, - 101.76878699, - 102.17300138, - 102.536116055, - 102.860158727, - 103.147085962, - 103.398830608, - 103.617254366, - 103.792467691, - 103.939387906, - 104.060030865, - 104.15631756, - 104.230085975, - 104.283067372, - 104.316933727, - 104.333238432, - 104.333440018, - 104.318914008, - 104.290941063, - 104.250742554, - 104.187634452, - 104.103822339, - 104.013227468, - 103.916810336, - 103.815448432, - 103.709936239, - 103.600997093, - 103.489283183, - 103.375351833, - 103.259712936, - 103.142828952, - 103.025091195, - 102.90686726, - 102.776726069, - 102.648078982, - 102.521459607, - 102.397294831, - 102.275999684, - 102.157882471, - 102.043215927, - 101.93218978, - 101.824958181, - 101.72159228, - 101.622151366) - - sampling_freq = 10e3 - freq = sampling_freq / 100 - - loop_bw = math.pi/100.0 - maxf = 1 - minf = -1 - - src = gr.sig_source_c (sampling_freq, gr.GR_COS_WAVE, freq, 1.0) - pll = gr.pll_freqdet_cf(loop_bw, maxf, minf) - head = gr.head (gr.sizeof_float, int (freq)) - dst = gr.vector_sink_f () - - self.tb.connect (src, pll, head) - self.tb.connect (head, dst) - - self.tb.run () - dst_data = dst.data () - - # convert it from normalized frequency to absolute frequency (Hz) - dst_data = [i*(sampling_freq/(2*math.pi)) for i in dst_data] - - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 3) - -if __name__ == '__main__': - gr_unittest.run(test_pll_freqdet, "test_pll_freqdet.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pll_refout.py b/gnuradio-core/src/python/gnuradio/gr/qa_pll_refout.py deleted file mode 100755 index f319f63814..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pll_refout.py +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2004,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_pll_refout (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block() - - def tearDown (self): - self.tb = None - - def test_pll_refout (self): - expected_result = ((1+0j), - (1+6.4087357643e-10j), - (0.999985277653+0.00542619498447j), - (0.999868750572+0.0162021834403j), - (0.99948567152+0.0320679470897j), - (0.99860727787+0.0527590736747j), - (0.996953129768+0.0780025869608j), - (0.994203746319+0.107512556016j), - (0.990011692047+0.140985429287j), - (0.984013140202+0.178095817566j), - (0.975838363171+0.218493551016j), - (0.965121984482+0.261800557375j), - (0.95151245594+0.307610183954j), - (0.934681296349+0.355486690998j), - (0.914401650429+0.404808044434j), - (0.890356600285+0.455263823271j), - (0.862329125404+0.506348133087j), - (0.830152392387+0.557536482811j), - (0.793714106083+0.608290970325j), - (0.752960026264+0.658066213131j), - (0.707896590233+0.706316053867j), - (0.658591926098+0.752500295639j), - (0.605175673962+0.796091973782j), - (0.547837555408+0.836584687233j), - (0.48682525754+0.873499393463j), - (0.42244040966+0.906390726566j), - (0.355197101831+0.934791445732j), - (0.285494059324+0.958380460739j), - (0.213591173291+0.976923108101j), - (0.139945343137+0.990159213543j), - (0.065038472414+0.997882783413j), - (-0.0106285437942+0.999943494797j), - (-0.0865436866879+0.996248066425j), - (-0.162189796567+0.986759603024j), - (-0.23705175519+0.971496999264j), - (-0.310622543097+0.950533330441j), - (-0.38240903616+0.923993110657j), - (-0.451937526464+0.89204955101j), - (-0.518758952618+0.854920566082j), - (-0.582311093807+0.812966048717j), - (-0.642372369766+0.76639264822j), - (-0.698591887951+0.715520322323j), - (-0.750654160976+0.660695314407j), - (-0.798280358315+0.602286040783j), - (-0.841228663921+0.540679454803j), - (-0.87929558754+0.476276367903j), - (-0.912315964699+0.409486919641j), - (-0.940161883831+0.340728074312j), - (-0.962742805481+0.270418733358j), - (-0.980004072189+0.198977485299j), - (-0.991925954819+0.126818284392j), - (-0.99851256609+0.0545223206282j), - (-0.999846458435-0.0175215266645j), - (-0.996021270752-0.0891158208251j), - (-0.987133920193-0.159895718098j), - (-0.973306238651-0.2295101583j), - (-0.954683184624-0.297624111176j), - (-0.931430280209-0.363919824362j), - (-0.903732538223-0.428097635508j), - (-0.871792256832-0.489875763655j), - (-0.835827112198-0.548992812634j), - (-0.796068251133-0.605206847191j), - (-0.752758979797-0.658296227455j), - (-0.706152498722-0.70805978775j), - (-0.656641483307-0.754202902317j), - (-0.604367733002-0.79670548439j), - (-0.549597978592-0.835429251194j), - (-0.492602348328-0.870254516602j), - (-0.433654457331-0.901079237461j), - (-0.373029649258-0.927819430828j), - (-0.31100410223-0.950408577919j), - (-0.247853919864-0.968797445297j), - (-0.183855071664-0.982953369617j), - (-0.119282215834-0.992860376835j), - (-0.0544078871608-0.998518764973j), - (0.0104992967099-0.999944865704j), - (0.0749994292855-0.997183561325j), - (0.138844624162-0.990314185619j), - (0.201967850327-0.979392170906j), - (0.264124274254-0.964488625526j), - (0.325075358152-0.945688128471j), - (0.3845885396-0.92308807373j), - (0.442438393831-0.89679890871j), - (0.498407125473-0.866943061352j), - (0.552284479141-0.833655714989j), - (0.603869199753-0.797083437443j), - (0.652970373631-0.757383465767j), - (0.69940674305-0.714723825455j), - (0.743007957935-0.66928255558j), - (0.78350687027-0.62138313055j), - (0.820889055729-0.571087777615j), - (0.855021059513-0.51859331131j), - (0.885780930519-0.46410369873j), - (0.913058102131-0.407829582691j), - (0.936754107475-0.349988251925j), - (0.956783294678-0.290801793337j), - (0.973072886467-0.230497643352j), - (0.985563337803-0.169307261705j), - (0.9942086339-0.1074674353j), - (0.9989772439-0.0452152714133j)) - - sampling_freq = 10e3 - freq = sampling_freq / 100 - - loop_bw = math.pi/100.0 - maxf = 1 - minf = -1 - - src = gr.sig_source_c (sampling_freq, gr.GR_COS_WAVE, freq, 1.0) - pll = gr.pll_refout_cc(loop_bw, maxf, minf) - head = gr.head (gr.sizeof_gr_complex, int (freq)) - dst = gr.vector_sink_c () - - self.tb.connect (src, pll, head) - self.tb.connect (head, dst) - - self.tb.run () - dst_data = dst.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4) - -if __name__ == '__main__': - gr_unittest.run(test_pll_refout, "test_pll_refout.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py b/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py deleted file mode 100755 index 6a62a6997b..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_pn_correlator_cc.py +++ /dev/null @@ -1,50 +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 - -class test_pn_correlator_cc(gr_unittest.TestCase): - - def setUp(self): - self.tb = gr.top_block () - - def tearDown(self): - self.tb = None - - def test_000_make(self): - c = gr.pn_correlator_cc(10) - - def test_001_correlate(self): - degree = 10 - length = 2**degree-1 - src = gr.glfsr_source_f(degree) - head = gr.head(gr.sizeof_float, length*length) - f2c = gr.float_to_complex() - corr = gr.pn_correlator_cc(degree) - dst = gr.vector_sink_c() - self.tb.connect(src, head, f2c, corr, dst) - self.tb.run() - data = dst.data() - self.assertEqual(data[-1], (1.0+0j)) - -if __name__ == '__main__': - gr_unittest.run(test_pn_correlator_cc, "test_pn_correlator_cc.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_scrambler.py b/gnuradio-core/src/python/gnuradio/gr/qa_scrambler.py deleted file mode 100755 index 5fe89bdc7f..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_scrambler.py +++ /dev/null @@ -1,64 +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 - -class test_scrambler(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block() - - def tearDown(self): - self.tb = None - - def test_scrambler_descrambler(self): - src_data = (1,)*1000 - src = gr.vector_source_b(src_data, False) - scrambler = gr.scrambler_bb(0x8a, 0x7F, 7) # CCSDS 7-bit scrambler - descrambler = gr.descrambler_bb(0x8a, 0x7F, 7) - dst = gr.vector_sink_b() - self.tb.connect(src, scrambler, descrambler, dst) - self.tb.run() - self.assertEqual(tuple(src_data[:-8]), dst.data()[8:]) # skip garbage during synchronization - - def test_additive_scrambler(self): - src_data = (1,)*1000 - src = gr.vector_source_b(src_data, False) - scrambler = gr.additive_scrambler_bb(0x8a, 0x7f, 7) - descrambler = gr.additive_scrambler_bb(0x8a, 0x7f, 7) - dst = gr.vector_sink_b() - self.tb.connect(src, scrambler, descrambler, dst) - self.tb.run() - self.assertEqual(src_data, dst.data()) - - def test_additive_scrambler_reset(self): - src_data = (1,)*1000 - src = gr.vector_source_b(src_data, False) - scrambler = gr.additive_scrambler_bb(0x8a, 0x7f, 7, 100) - descrambler = gr.additive_scrambler_bb(0x8a, 0x7f, 7, 100) - dst = gr.vector_sink_b() - self.tb.connect(src, scrambler, descrambler, dst) - self.tb.run() - self.assertEqual(src_data, dst.data()) - -if __name__ == '__main__': - gr_unittest.run(test_scrambler, "test_scrambler.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_sig_source.py b/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py deleted file mode 100755 index 122b169b7e..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_sig_source.py +++ /dev/null @@ -1,157 +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_sig_source (gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_const_f (self): - tb = self.tb - expected_result = (1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5) - src1 = gr.sig_source_f (1e6, gr.GR_CONST_WAVE, 0, 1.5) - op = gr.head (gr.sizeof_float, 10) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertEqual (expected_result, dst_data) - - def test_const_i (self): - tb = self.tb - expected_result = (1, 1, 1, 1) - src1 = gr.sig_source_i (1e6, gr.GR_CONST_WAVE, 0, 1) - op = gr.head (gr.sizeof_int, 4) - dst1 = gr.vector_sink_i () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertEqual (expected_result, dst_data) - - def test_sine_f (self): - tb = self.tb - sqrt2 = math.sqrt(2) / 2 - expected_result = (0, sqrt2, 1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0) - src1 = gr.sig_source_f (8, gr.GR_SIN_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_float, 9) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5) - - def test_cosine_f (self): - tb = self.tb - sqrt2 = math.sqrt(2) / 2 - expected_result = (1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0, sqrt2, 1) - src1 = gr.sig_source_f (8, gr.GR_COS_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_float, 9) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5) - - def test_sqr_c (self): - tb = self.tb #arg6 is a bit before -PI/2 - expected_result = (1j, 1j, 0, 0, 1, 1, 1+0j, 1+1j, 1j) - src1 = gr.sig_source_c (8, gr.GR_SQR_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_gr_complex, 9) - dst1 = gr.vector_sink_c () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertEqual (expected_result, dst_data) - - def test_tri_c (self): - tb = self.tb - expected_result = (1+.5j, .75+.75j, .5+1j, .25+.75j, 0+.5j, .25+.25j, .5+0j, .75+.25j, 1+.5j) - src1 = gr.sig_source_c (8, gr.GR_TRI_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_gr_complex, 9) - dst1 = gr.vector_sink_c () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5) - - def test_saw_c (self): - tb = self.tb - expected_result = (.5+.25j, .625+.375j, .75+.5j, .875+.625j, 0+.75j, .125+.875j, .25+1j, .375+.125j, .5+.25j) - src1 = gr.sig_source_c (8, gr.GR_SAW_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_gr_complex, 9) - dst1 = gr.vector_sink_c () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5) - - def test_sqr_f (self): - tb = self.tb - expected_result = (0, 0, 0, 0, 1, 1, 1, 1, 0) - src1 = gr.sig_source_f (8, gr.GR_SQR_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_float, 9) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertEqual (expected_result, dst_data) - - def test_tri_f (self): - tb = self.tb - expected_result = (1, .75, .5, .25, 0, .25, .5, .75, 1) - src1 = gr.sig_source_f (8, gr.GR_TRI_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_float, 9) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5) - - def test_saw_f (self): - tb = self.tb - expected_result = (.5, .625, .75, .875, 0, .125, .25, .375, .5) - src1 = gr.sig_source_f (8, gr.GR_SAW_WAVE, 1.0, 1.0) - op = gr.head (gr.sizeof_float, 9) - dst1 = gr.vector_sink_f () - tb.connect (src1, op) - tb.connect (op, dst1) - tb.run () - dst_data = dst1.data () - self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5) - -if __name__ == '__main__': - gr_unittest.run(test_sig_source, "test_sig_source.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir.py b/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir.py deleted file mode 100755 index bfe2d8fc8c..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir.py +++ /dev/null @@ -1,72 +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 - -class test_single_pole_iir(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - src_data = (0, 1000, 2000, 3000, 4000, 5000) - expected_result = src_data - src = gr.vector_source_f(src_data) - op = gr.single_pole_iir_filter_ff (1.0) - 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): - src_data = (0, 1000, 2000, 3000, 4000, 5000) - expected_result = (0, 125, 359.375, 689.453125, 1103.271484, 1590.36255) - src = gr.vector_source_f(src_data) - op = gr.single_pole_iir_filter_ff (0.125) - dst = gr.vector_sink_f() - self.tb.connect (src, op, dst) - self.tb.run() - result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 3) - - def test_003(self): - block_size = 2 - src_data = (0, 1000, 2000, 3000, 4000, 5000) - expected_result = (0, 125, 250, 484.375, 718.75, 1048.828125) - src = gr.vector_source_f(src_data) - s2p = gr.serial_to_parallel(gr.sizeof_float, block_size) - op = gr.single_pole_iir_filter_ff (0.125, block_size) - p2s = gr.parallel_to_serial(gr.sizeof_float, block_size) - dst = gr.vector_sink_f() - self.tb.connect (src, s2p, op, p2s, dst) - self.tb.run() - result_data = dst.data() - self.assertFloatTuplesAlmostEqual (expected_result, result_data, 3) - - -if __name__ == '__main__': - gr_unittest.run(test_single_pole_iir, "test_single_pole_iir.xml") - diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir_cc.py b/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir_cc.py deleted file mode 100755 index 353df1bc0d..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_single_pole_iir_cc.py +++ /dev/null @@ -1,72 +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 - -class test_single_pole_iir_cc(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001(self): - src_data = (0+0j, 1000+1000j, 2000+2000j, 3000+3000j, 4000+4000j, 5000+5000j) - expected_result = src_data - src = gr.vector_source_c(src_data) - op = gr.single_pole_iir_filter_cc (1.0) - dst = gr.vector_sink_c() - self.tb.connect (src, op, dst) - self.tb.run() - result_data = dst.data() - self.assertComplexTuplesAlmostEqual (expected_result, result_data) - - def test_002(self): - src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), complex(3000,-3000), complex(4000,-4000), complex(5000,-5000)) - expected_result = (complex(0,0), complex(125,-125), complex(359.375,-359.375), complex(689.453125,-689.453125), complex(1103.271484,-1103.271484), complex(1590.36255,-1590.36255)) - src = gr.vector_source_c(src_data) - op = gr.single_pole_iir_filter_cc (0.125) - dst = gr.vector_sink_c() - self.tb.connect (src, op, dst) - self.tb.run() - result_data = dst.data() - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3) - - def test_003(self): - block_size = 2 - src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), complex(3000,-3000), complex(4000,-4000), complex(5000,-5000)) - expected_result = (complex(0,0), complex(125,-125), complex(250,-250), complex(484.375,-484.375), complex(718.75,-718.75), complex(1048.828125,-1048.828125)) - src = gr.vector_source_c(src_data) - s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, block_size) - op = gr.single_pole_iir_filter_cc (0.125, block_size) - p2s = gr.parallel_to_serial(gr.sizeof_gr_complex, block_size) - dst = gr.vector_sink_c() - self.tb.connect (src, s2p, op, p2s, dst) - self.tb.run() - result_data = dst.data() - self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3) - - -if __name__ == '__main__': - gr_unittest.run(test_single_pole_iir_cc, "test_single_pole_iir_cc.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/gr/qa_tag_utils.py b/gnuradio-core/src/python/gnuradio/gr/qa_tag_utils.py index ca1184979b..de1b5aa002 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_tag_utils.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_tag_utils.py @@ -40,9 +40,9 @@ class test_tag_utils (gr_unittest.TestCase): def test_001(self): t = gr.gr_tag_t() t.offset = 10 - t.key = pmt.pmt_string_to_symbol('key') - t.value = pmt.pmt_from_long(23) - t.srcid = pmt.pmt_from_bool(False) + t.key = pmt.string_to_symbol('key') + t.value = pmt.from_long(23) + t.srcid = pmt.from_bool(False) pt = tag_utils.tag_to_python(t) self.assertEqual(pt.key, 'key') self.assertEqual(pt.value, 23) diff --git a/gnuradio-core/src/python/gnuradio/gr/top_block.py b/gnuradio-core/src/python/gnuradio/gr/top_block.py index dc1f443aa9..947e46bc55 100644 --- a/gnuradio-core/src/python/gnuradio/gr/top_block.py +++ b/gnuradio-core/src/python/gnuradio/gr/top_block.py @@ -85,6 +85,12 @@ class _top_block_waiter(_threading.Thread): # method in gr_top_block # class top_block(object): + """ + Top-level hierarchical block representing a flow-graph. + + This is a python wrapper around the C++ implementation to allow + python subclassing. + """ def __init__(self, name="top_block"): self._tb = top_block_swig(name) @@ -93,13 +99,13 @@ class top_block(object): raise RuntimeError("top_block: invalid state--did you forget to call gr.top_block.__init__ in a derived class?") return getattr(self._tb, name) - def start(self, max_noutput_items=100000): + def start(self, max_noutput_items=10000000): self._tb.start(max_noutput_items) def stop(self): self._tb.stop() - def run(self, max_noutput_items=100000): + def run(self, max_noutput_items=10000000): self.start(max_noutput_items) self.wait() diff --git a/gnuradio-core/src/python/gnuradio/gr_unittest.py b/gnuradio-core/src/python/gnuradio/gr_unittest.py index e4510a6eb9..c729566e88 100755 --- a/gnuradio-core/src/python/gnuradio/gr_unittest.py +++ b/gnuradio-core/src/python/gnuradio/gr_unittest.py @@ -19,6 +19,9 @@ # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # +""" +GNU radio specific extension of unittest. +""" import unittest import gr_xmlrunner diff --git a/gnuradio-core/src/python/gnuradio/gruimpl/socket_stuff.py b/gnuradio-core/src/python/gnuradio/gruimpl/socket_stuff.py index 329fd2ed3d..489b6ab255 100644 --- a/gnuradio-core/src/python/gnuradio/gruimpl/socket_stuff.py +++ b/gnuradio-core/src/python/gnuradio/gruimpl/socket_stuff.py @@ -27,9 +27,12 @@ import sys def tcp_connect_or_die(sock_addr): """ - @param sock_addr: (host, port) to connect to - @type sock_addr: tuple - @returns: socket or exits + + Args: + sock_addr: (host, port) to connect to (tuple) + + Returns: + : socket or exits """ s = socket.socket (socket.AF_INET, socket.SOCK_STREAM) try: @@ -42,9 +45,12 @@ def tcp_connect_or_die(sock_addr): def udp_connect_or_die(sock_addr): """ - @param sock_addr: (host, port) to connect to - @type sock_addr: tuple - @returns: socket or exits + + Args: + sock_addr: (host, port) to connect to (tuple) + + Returns: + : socket or exits """ s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) try: diff --git a/gnuradio-core/src/python/gnuradio/optfir.py b/gnuradio-core/src/python/gnuradio/optfir.py deleted file mode 100644 index bbf9ead747..0000000000 --- a/gnuradio-core/src/python/gnuradio/optfir.py +++ /dev/null @@ -1,341 +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 - -# ---------------------------------------------------------------- - -## Builds a low pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq1 End of pass band (in Hz) -# @param freq2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) -def low_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, - nextra_taps=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 - -## Builds a band pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_sb1 End of stop band (in Hz) -# @param freq_pb1 Start of pass band (in Hz) -# @param freq_pb2 End of pass band (in Hz) -# @param freq_sb2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) -def band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=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 - - -## Builds a band pass filter with complex taps by making an LPF and -# spinning it up to the right center frequency -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_sb1 End of stop band (in Hz) -# @param freq_pb1 Start of pass band (in Hz) -# @param freq_pb2 End of pass band (in Hz) -# @param freq_sb2 Start of stop band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) -def complex_band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=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 - - -## Builds a band reject filter -# spinning it up to the right center frequency -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq_pb1 End of pass band (in Hz) -# @param freq_sb1 Start of stop band (in Hz) -# @param freq_sb2 End of stop band (in Hz) -# @param freq_pb2 Start of pass band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) -def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2, - passband_ripple_db, stopband_atten_db, - nextra_taps=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 - - -## Builds a high pass filter. -# @param gain Filter gain in the passband (linear) -# @param Fs Sampling rate (sps) -# @param freq1 End of stop band (in Hz) -# @param freq2 Start of pass band (in Hz) -# @param passband_ripple_db Pass band ripple in dB (should be small, < 1) -# @param stopband_atten_db Stop band attenuation in dB (should be large, >= 60) -# @param nextra_taps Extra taps to use in the filter (default=2) -def high_pass (gain, Fs, freq1, freq2, passband_ripple_db, stopband_atten_db, - nextra_taps=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 |