diff options
23 files changed, 1331 insertions, 3 deletions
diff --git a/config/Makefile.am b/config/Makefile.am index 0ee6096a7..bdc79a5fa 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -26,6 +26,7 @@ m4datadir = $(datadir)/aclocal # List your m4 macros here m4macros = \ + acx_cblas.m4 \ acx_pthread.m4 \ ax_boost_base.m4 \ ax_boost_date_time.m4 \ diff --git a/config/acx_cblas.m4 b/config/acx_cblas.m4 new file mode 100644 index 000000000..38d859828 --- /dev/null +++ b/config/acx_cblas.m4 @@ -0,0 +1,227 @@ +# =========================================================================== +# http://autoconf-archive.cryp.to/acx_blas.html +# =========================================================================== +# +# SYNOPSIS +# +# ACX_CBLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro looks for a library that implements the CBLAS linear-algebra +# interface (see http://www.netlib.org/blas/). On success, it sets the +# CBLAS_LIBS output variable to hold the requisite library linkages. +# +# To link with BLAS, you should link with: +# +# $CBLAS_LIBS $LIBS +# +# Many libraries are searched for, from ATLAS to CXML to ESSL. The user +# may also use --with-blas=<lib> in order to use some specific CBLAS +# library <lib>. In order to link successfully, however, be aware that you +# will probably need to use the same Fortran compiler (which can be set +# via the F77 env. var.) as was used to compile the BLAS library. +# +# ACTION-IF-FOUND is a list of shell commands to run if a CBLAS library is +# found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is +# not found. If ACTION-IF-FOUND is not specified, the default action will +# define HAVE_CBLAS. +# +# This macro requires autoconf 2.50 or later. +# +# LAST MODIFICATION +# +# 2008-04-12 +# +# COPYLEFT +# +# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> +# Copyright (c) 2008 Free Software Foundation, Inc. +# +# This program 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 of the License, or (at your +# option) any later version. +# +# This program 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, see <http://www.gnu.org/licenses/>. +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Macro Archive. When you make and +# distribute a modified version of the Autoconf Macro, you may extend this +# special exception to the GPL to apply to your modified version as well. + +AC_DEFUN([ACX_CBLAS], [ +AC_PREREQ(2.50) +dnl AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS]) +AC_REQUIRE([AC_CANONICAL_HOST]) +acx_cblas_ok=no + +AC_ARG_WITH(cblas, + [AC_HELP_STRING([--with-cblas=<lib>], [use CBLAS library <lib>])]) +case $with_cblas in + yes | "") ;; + no) acx_cblas_ok=disable ;; + -* | */* | *.a | *.so | *.so.* | *.o) CBLAS_LIBS="$with_cblas" ;; + *) CBLAS_LIBS="-l$with_cblas" ;; +esac + + +acx_cblas_save_LIBS="$LIBS" +LIBS="$LIBS $FLIBS" + +# First, check CBLAS_LIBS environment variable +if test $acx_cblas_ok = no; then +if test "x$CBLAS_LIBS" != x; then + save_LIBS="$LIBS"; LIBS="$CBLAS_LIBS $LIBS" + AC_MSG_CHECKING([for cblas_sgemm in $CBLAS_LIBS]) + AC_TRY_LINK_FUNC(cblas_sgemm, [acx_cblas_ok=yes], [CBLAS_LIBS=""]) + AC_MSG_RESULT($acx_cblas_ok) + LIBS="$save_LIBS" +fi +fi + +# CBLAS linked to by default? (happens on some supercomputers) +if test $acx_cblas_ok = no; then + save_LIBS="$LIBS"; LIBS="$LIBS" + AC_CHECK_FUNC(cblas_sgemm, [acx_cblas_ok=yes]) + LIBS="$save_LIBS" +fi + +# CBLAS in ATLAS library? (http://math-atlas.sourceforge.net/) +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(atlas, ATL_xerbla, + [AC_CHECK_LIB(cblas, cblas_dgemm, + [acx_cblas_ok=yes + CBLAS_LIBS="-lcblas -latlas"], + [], [-latlas])], + [], [-latlas]) +fi + +# CBLAS in ATLAS library in /usr/lib64/atlas (if not cross-compiling) +if test $acx_cblas_ok = no && test "$cross_compiling" = no; then + unset ac_cv_lib_atlas_ATL_xerbla + unset ac_cv_lib_cblas_cblas_dgemm + AC_CHECK_LIB(atlas, ATL_xerbla, + [AC_CHECK_LIB(cblas, cblas_dgemm, + [acx_cblas_ok=yes + CBLAS_LIBS="-L/usr/lib64/atlas -lcblas -latlas"], + [], [-L/usr/lib64/atlas -latlas])], + [], [-L/usr/lib64/atlas -latlas]) +fi + +# CBLAS in ATLAS library in /usr/lib/atlas (if not cross-compiling) +if test $acx_cblas_ok = no && test "$cross_compiling" = no; then + unset ac_cv_lib_atlas_ATL_xerbla + unset ac_cv_lib_cblas_cblas_dgemm + AC_CHECK_LIB(atlas, ATL_xerbla, + [AC_CHECK_LIB(cblas, cblas_dgemm, + [acx_cblas_ok=yes + CBLAS_LIBS="-L/usr/lib/atlas -lcblas -latlas"], + [], [-L/usr/lib/atlas -latlas])], + [], [-L/usr/lib/atlas -latlas]) +fi + + +# CBLAS in PhiPACK libraries? (requires generic BLAS lib, too) +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(cblas, cblas_sgemm, + [AC_CHECK_LIB(dgemm, cblas_dgemm, + [AC_CHECK_LIB(sgemm, cblas_sgemm, + [acx_cblas_ok=yes; CBLAS_LIBS="-lsgemm -ldgemm -lblas"], + [], [-lblas])], + [], [-lblas])]) +fi + +# BLAS in Intel MKL library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(mkl, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-lmkl"]) +fi + +# CBLAS in Apple vecLib library? +if test $acx_cblas_ok = no; then + save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS" + AC_CHECK_FUNC(cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-framework vecLib"]) + LIBS="$save_LIBS" +fi + +# CBLAS in Alpha CXML library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(cxml, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-lcxml"]) +fi + +# CBLAS in Alpha DXML library? (now called CXML, see above) +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(dxml, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-ldxml"]) +fi + +# CBLAS in Sun Performance library? +if test $acx_cblas_ok = no; then + if test "x$GCC" != xyes; then # only works with Sun CC + AC_CHECK_LIB(sunmath, acosp, + [AC_CHECK_LIB(sunperf, cblas_sgemm, + [CBLAS_LIBS="-xlic_lib=sunperf -lsunmath" + acx_cblas_ok=yes],[],[-lsunmath])]) + fi +fi + +# CBLAS in SCSL library? (SGI/Cray Scientific Library) +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(scs, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lscs"]) +fi + +# CBLAS in SGIMATH library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(complib.sgimath, cblas_sgemm, + [acx_cblas_ok=yes; CBLAS_LIBS="-lcomplib.sgimath"]) +fi + +# CBLAS in IBM ESSL library? (requires generic CBLAS lib, too) +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(cblas, cblas_sgemm, + [AC_CHECK_LIB(essl, cblas_sgemm, + [acx_cblas_ok=yes; CBLAS_LIBS="-lessl -lblas"], + [], [-lblas $FLIBS])]) +fi + +# Generic CBLAS library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(cblas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lcblas"]) +fi + +# Generic BLAS library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(blas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lblas"]) +fi + +# GSL generic CBLAS library? +if test $acx_cblas_ok = no; then + AC_CHECK_LIB(gslcblas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lgslcblas"]) +fi + +AC_SUBST(CBLAS_LIBS) + +LIBS="$acx_cblas_save_LIBS" + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_cblas_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_CBLAS,1,[Define if you have a CBLAS library.]),[$1]) + : +else + acx_cblas_ok=no + $2 +fi +])dnl ACX_CBLAS diff --git a/config/grc_gnuradio_core.m4 b/config/grc_gnuradio_core.m4 index df2ec305d..607f36a73 100644 --- a/config/grc_gnuradio_core.m4 +++ b/config/grc_gnuradio_core.m4 @@ -36,6 +36,15 @@ AC_DEFUN([GRC_GNURADIO_CORE],[ dnl with : if the --with code didn't error out dnl yes : if the --enable code passed muster and all dependencies are met dnl no : otherwise + if test $passed = yes; then + dnl look for fast CBLAS for GSL, but don't complain if not found + ACX_CBLAS([],[]) + dnl check for GSL + PKG_CHECK_MODULES(GSL, gsl >= 1.10, + [], dnl FIXME remove -lgslcblas from GSL_LIBS if we found a better CBLAS_LIBS above + [passed=no;AC_MSG_RESULT([gnuradio-core requires package gsl, not found.])]) + fi + if test $passed != with; then dnl how and where to find INCLUDES and LA and such gnuradio_core_INCLUDES="\ @@ -52,7 +61,8 @@ AC_DEFUN([GRC_GNURADIO_CORE],[ -I\${abs_top_srcdir}/gnuradio-core/src/lib/g72x \ -I\${abs_top_srcdir}/gnuradio-core/src/lib/swig \ -I\${abs_top_builddir}/gnuradio-core/src/lib/swig \ -\$(FFTW3F_CFLAGS)" +\$(FFTW3F_CFLAGS) \ +\$(GSL_CFLAGS)" gnuradio_core_LA="\${abs_top_builddir}/gnuradio-core/src/lib/libgnuradio-core.la" gnuradio_core_I="\${abs_top_srcdir}/gnuradio-core/src/lib/swig/gnuradio.i" gnuradio_core_LIBDIRPATH="\${abs_top_builddir}/gnuradio-core/src/lib:\${abs_top_builddir}/gnuradio-core/src/lib/.libs" diff --git a/gnuradio-core/src/lib/Makefile.am b/gnuradio-core/src/lib/Makefile.am index e4646cfcc..dea284067 100644 --- a/gnuradio-core/src/lib/Makefile.am +++ b/gnuradio-core/src/lib/Makefile.am @@ -50,7 +50,9 @@ libgnuradio_core_la_LIBADD = \ runtime/libruntime.la \ $(OMNITHREAD_LA) \ $(GRUEL_LA) \ - $(FFTW3F_LIBS) + $(FFTW3F_LIBS) \ + $(GSL_LIBS) \ + $(CBLAS_LIBS) libgnuradio_core_qa_la_LIBADD = \ filter/libfilter-qa.la \ diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index b46590070..7d486092a 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -125,6 +125,7 @@ libgeneral_la_SOURCES = \ gr_pwr_squelch_cc.cc \ gr_pwr_squelch_ff.cc \ gr_quadrature_demod_cf.cc \ + gr_rail_ff.cc \ gr_random.cc \ gr_regenerate_bb.cc \ gr_remez.cc \ @@ -137,6 +138,7 @@ libgeneral_la_SOURCES = \ gr_simple_framer.cc \ gr_simple_squelch_cc.cc \ gr_skiphead.cc \ + gr_squash_ff.cc \ gr_squelch_base_cc.cc \ gr_squelch_base_ff.cc \ gr_stream_mux.cc \ @@ -144,6 +146,7 @@ libgeneral_la_SOURCES = \ gr_stream_to_vector.cc \ gr_streams_to_stream.cc \ gr_streams_to_vector.cc \ + gr_stretch_ff.cc \ gr_test.cc \ gr_threshold_ff.cc \ gr_throttle.cc \ @@ -151,6 +154,8 @@ libgeneral_la_SOURCES = \ gr_vco_f.cc \ gr_vector_to_stream.cc \ gr_vector_to_streams.cc \ + gr_wavelet_ff.cc \ + gr_wvps_ff.cc \ gri_add_const_ss_generic.cc \ gri_char_to_float.cc \ gri_debugger_hook.cc \ @@ -275,6 +280,7 @@ grinclude_HEADERS = \ gr_pwr_squelch_cc.h \ gr_pwr_squelch_ff.h \ gr_quadrature_demod_cf.h \ + gr_rail_ff.h \ gr_random.h \ gr_regenerate_bb.h \ gr_remez.h \ @@ -287,6 +293,7 @@ grinclude_HEADERS = \ gr_simple_framer.h \ gr_simple_framer_sync.h \ gr_simple_squelch_cc.h \ + gr_squash_ff.h \ gr_skiphead.h \ gr_squelch_base_cc.h \ gr_squelch_base_ff.h \ @@ -295,6 +302,7 @@ grinclude_HEADERS = \ gr_stream_to_vector.h \ gr_streams_to_stream.h \ gr_streams_to_vector.h \ + gr_stretch_ff.h \ gr_test_types.h \ gr_test.h \ gr_threshold_ff.h \ @@ -304,6 +312,8 @@ grinclude_HEADERS = \ gr_vco_f.h \ gr_vector_to_stream.h \ gr_vector_to_streams.h \ + gr_wavelet_ff.h \ + gr_wvps_ff.h \ gri_add_const_ss.h \ gri_agc_cc.h \ gri_agc_ff.h \ @@ -427,6 +437,7 @@ swiginclude_HEADERS = \ gr_pwr_squelch_cc.i \ gr_pwr_squelch_ff.i \ gr_quadrature_demod_cf.i \ + gr_rail_ff.i \ gr_regenerate_bb.i \ gr_remez.i \ gr_rms_cf.i \ @@ -437,6 +448,7 @@ swiginclude_HEADERS = \ gr_simple_framer.i \ gr_simple_squelch_cc.i \ gr_skiphead.i \ + gr_squash_ff.i \ gr_squelch_base_cc.i \ gr_squelch_base_ff.i \ gr_stream_mux.i \ @@ -444,6 +456,7 @@ swiginclude_HEADERS = \ gr_stream_to_vector.i \ gr_streams_to_stream.i \ gr_streams_to_vector.i \ + gr_stretch_ff.i \ gr_test.i \ gr_threshold_ff.i \ gr_throttle.i \ @@ -452,6 +465,8 @@ swiginclude_HEADERS = \ gr_vector_to_stream.i \ gr_vector_to_streams.i \ gr_unpack_k_bits_bb.i \ + gr_wavelet_ff.i \ + gr_wvps_ff.i \ gri_agc_cc.i \ gri_agc_ff.i \ gri_agc2_cc.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 542bf6064..e7d9e978e 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -133,6 +133,12 @@ #include <gr_scrambler_bb.h> #include <gr_probe_mpsk_snr_c.h> #include <gr_probe_density_b.h> +#include <gr_rail_ff.h> +#include <gr_squash_ff.h> +#include <gr_stretch_ff.h> +#include <gr_wavelet_ff.h> +#include <gr_wvps_ff.h> + %} %include "gr_nop.i" @@ -246,3 +252,8 @@ %include "gr_scrambler_bb.i" %include "gr_probe_mpsk_snr_c.i" %include "gr_probe_density_b.i" +%include "gr_rail_ff.i" +%include "gr_squash_ff.i" +%include "gr_stretch_ff.i" +%include "gr_wavelet_ff.i" +%include "gr_wvps_ff.i" diff --git a/gnuradio-core/src/lib/general/gr_rail_ff.cc b/gnuradio-core/src/lib/general/gr_rail_ff.cc new file mode 100644 index 000000000..9fd3af8df --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_rail_ff.cc @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_rail_ff.h> +#include <gr_io_signature.h> + +gr_rail_ff_sptr +gr_make_rail_ff(float lo, float hi) +{ + return gr_rail_ff_sptr(new gr_rail_ff(lo, hi)); +} + +gr_rail_ff::gr_rail_ff(float lo, float hi) + : gr_sync_block("rail_ff", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(float))), + d_lo(lo), d_hi(hi) +{ +} + +int +gr_rail_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int i = 0; i < noutput_items; i++) { + if (in[i] < d_lo) + out[i] = d_lo; + else if (in[i] > d_hi) + out[i] = d_hi; + else + out[i] = in[i]; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_rail_ff.h b/gnuradio-core/src/lib/general/gr_rail_ff.h new file mode 100644 index 000000000..d9e19a964 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_rail_ff.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_RAIL_FF_H_ +# define INCLUDED_GR_RAIL_FF_H_ + +#include <gr_sync_block.h> + +/*! + * \brief clips input values to min, max + * \ingroup misc + */ + +class gr_rail_ff; +typedef boost::shared_ptr<gr_rail_ff> gr_rail_ff_sptr; + +gr_rail_ff_sptr gr_make_rail_ff(float lo, float hi); + +class gr_rail_ff : public gr_sync_block +{ + friend gr_rail_ff_sptr gr_make_rail_ff (float lo, float hi); + + float d_lo, d_hi; // the constant + gr_rail_ff(float lo, float hi); + + public: + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + float hi() const { return d_hi; } + void set_hi(float hi) { d_hi = hi; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_rail_ff.i b/gnuradio-core/src/lib/general/gr_rail_ff.i new file mode 100644 index 000000000..ae39b76de --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_rail_ff.i @@ -0,0 +1,30 @@ +/* -*- c++ -*- */ +/* + * 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,rail_ff); + +gr_rail_ff_sptr gr_make_rail_ff(float lo, float hi); + +class gr_rail_ff : public gr_sync_block +{ +private: + gr_rail_ff(float lo, float hi); +}; diff --git a/gnuradio-core/src/lib/general/gr_squash_ff.cc b/gnuradio-core/src/lib/general/gr_squash_ff.cc new file mode 100644 index 000000000..977376bc5 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_squash_ff.cc @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdexcept> +#include <gr_squash_ff.h> +#include <gr_io_signature.h> + +// expect input vector of igrid.size y-values, +// produce output vector of ogrid.size y-values + +gr_squash_ff_sptr +gr_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid) +{ + return gr_squash_ff_sptr(new gr_squash_ff(igrid, ogrid)); +} + +gr_squash_ff::gr_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid) + : gr_sync_block("squash_ff", + gr_make_io_signature(1, 1, sizeof(float) * igrid.size()), + gr_make_io_signature(1, 1, sizeof(float) * ogrid.size())) +{ + d_inum = igrid.size(); + d_onum = ogrid.size(); + d_igrid = (double *) malloc(d_inum * sizeof(double)); + d_iwork = (double *) malloc(d_inum * sizeof(double)); + d_ogrid = (double *) malloc(d_onum * sizeof(double)); + for (int i = 0; i < d_inum; i++) + d_igrid[i] = igrid[i]; + for (int i = 0; i < d_onum; i++) + d_ogrid[i] = ogrid[i]; + + d_accel = gsl_interp_accel_alloc(); + d_spline = gsl_spline_alloc(gsl_interp_cspline, d_inum); // FIXME check w/ Frank +} + +gr_squash_ff::~gr_squash_ff() +{ + free((char *) d_igrid); + free((char *) d_iwork); + free((char *) d_ogrid); + gsl_interp_accel_free(d_accel); + gsl_spline_free(d_spline); +} + +int +gr_squash_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int count = 0; count < noutput_items; count++) { + + for (int i = 0; i < d_inum; i++) + d_iwork[i] = in[i]; + + gsl_spline_init(d_spline, d_igrid, d_iwork, d_inum); + + for (int i = 0; i < d_onum; i++) + out[i] = gsl_spline_eval(d_spline, d_ogrid[i], d_accel); + + in += d_inum; + out += d_onum; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_squash_ff.h b/gnuradio-core/src/lib/general/gr_squash_ff.h new file mode 100644 index 000000000..43880857e --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_squash_ff.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_SQUASH_FF_H_ +# define INCLUDED_GR_SQUASH_FF_H_ + +#include <gr_sync_block.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_interp.h> +#include <gsl/gsl_spline.h> +/*! + * \brief implements cheap resampling of spectrum directly from + * spectral points, using gsl interpolation + * \ingroup misc + */ + +class gr_squash_ff; +typedef boost::shared_ptr<gr_squash_ff> gr_squash_ff_sptr; + +gr_squash_ff_sptr gr_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + +class gr_squash_ff : public gr_sync_block +{ + friend gr_squash_ff_sptr gr_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + + size_t d_inum; + size_t d_onum; + double *d_igrid; + double *d_iwork; + double *d_ogrid; + + gsl_interp_accel *d_accel; + gsl_spline *d_spline; + + gr_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + + public: + ~gr_squash_ff(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_squash_ff.i b/gnuradio-core/src/lib/general/gr_squash_ff.i new file mode 100644 index 000000000..c89b1c28d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_squash_ff.i @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,squash_ff); + +gr_squash_ff_sptr gr_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + +class gr_squash_ff : public gr_sync_block +{ +private: + gr_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + +}; + diff --git a/gnuradio-core/src/lib/general/gr_stretch_ff.cc b/gnuradio-core/src/lib/general/gr_stretch_ff.cc new file mode 100644 index 000000000..0913d5277 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_stretch_ff.cc @@ -0,0 +1,74 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_stretch_ff.h> +#include <gr_io_signature.h> + +gr_stretch_ff_sptr +gr_make_stretch_ff(float lo, size_t vlen) +{ + return gr_stretch_ff_sptr(new gr_stretch_ff(lo, vlen)); +} + +gr_stretch_ff::gr_stretch_ff(float lo, size_t vlen) + : gr_sync_block("stretch_ff", + gr_make_io_signature(1, 1, vlen * sizeof(float)), + gr_make_io_signature(1, 1, vlen * sizeof(float))), + d_lo(lo), d_vlen(vlen) +{ +} + +int +gr_stretch_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int count = 0; count < noutput_items; count++) { + float vmax = in[0] - d_lo; + + for (int i = 1; i < d_vlen; i++) { + float vtmp = in[i] - d_lo; + if (vtmp > vmax) + vmax = vtmp; + } + + if (vmax != 0.0) + for (int i = 0; i < d_vlen; i++) + out[i] = d_lo * (1.0 - (in[i] - d_lo) / vmax); + else + for (int i = 0; i < d_vlen; i++) + out[i] = in[i]; + + in += d_vlen; + out += d_vlen; + } + + return noutput_items; +} + diff --git a/gnuradio-core/src/lib/general/gr_stretch_ff.h b/gnuradio-core/src/lib/general/gr_stretch_ff.h new file mode 100644 index 000000000..d2164f8f4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_stretch_ff.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifndef INCLUDED_GR_STRETCH_FF_H_ +# define INCLUDED_GR_STRETCH_FF_H_ + +#include <gr_sync_block.h> + +/*! + * \brief adjust y-range of an input vector by mapping to range + * (max-of-input, stipulated-min). Primarily for spectral signature + * matching by normalizing spectrum dynamic ranges. + * \ingroup misc + */ + + +class gr_stretch_ff; +typedef boost::shared_ptr<gr_stretch_ff> gr_stretch_ff_sptr; + +gr_stretch_ff_sptr gr_make_stretch_ff(float lo, size_t vlen); + +class gr_stretch_ff : public gr_sync_block +{ + friend gr_stretch_ff_sptr gr_make_stretch_ff(float lo, size_t vlen); + + float d_lo; // the constant + size_t d_vlen; + gr_stretch_ff(float lo, size_t vlen); + + public: + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + size_t vlen() const { return d_vlen; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_stretch_ff.i b/gnuradio-core/src/lib/general/gr_stretch_ff.i new file mode 100644 index 000000000..74c10fb2f --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_stretch_ff.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,stretch_ff); + +gr_stretch_ff_sptr gr_make_stretch_ff(float lo, size_t vlen); + +class gr_stretch_ff : public gr_sync_block +{ +private: + gr_stretch_ff(float lo, size_t vlen); +}; + diff --git a/gnuradio-core/src/lib/general/gr_wavelet_ff.cc b/gnuradio-core/src/lib/general/gr_wavelet_ff.cc new file mode 100644 index 000000000..6cbfa2381 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wavelet_ff.cc @@ -0,0 +1,107 @@ +/* -*- c++ -*- */ +/* + * 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 tewavelet 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdexcept> +#include <gr_wavelet_ff.h> +#include <gr_io_signature.h> + +#include <stdio.h> + +// NB in this version, only Daubechies wavelets +// order is wavelet length, even, 2...20 + +gr_wavelet_ff_sptr +gr_make_wavelet_ff(int size, + int order, + bool forward) +{ + return gr_wavelet_ff_sptr(new gr_wavelet_ff(size, + order, + forward)); +} + +gr_wavelet_ff::gr_wavelet_ff(int size, + int order, + bool forward) + : gr_sync_block("wavelet_ff", + gr_make_io_signature(1, 1, size * sizeof(float)), + gr_make_io_signature(1, 1, size * sizeof(float))), + d_size(size), + d_order(order), + d_forward(forward) +{ + d_wavelet = gsl_wavelet_alloc(gsl_wavelet_daubechies, d_order); + if (d_wavelet == NULL) + throw std::runtime_error("can't allocate wavelet"); + d_workspace = gsl_wavelet_workspace_alloc(d_size); + if (d_workspace == NULL) + throw std::runtime_error("can't allocate wavelet workspace"); + d_temp = (double *) malloc(d_size*sizeof(double)); + if (d_workspace == NULL) + throw std::runtime_error("can't allocate wavelet double conversion temp"); +} + +gr_wavelet_ff::~gr_wavelet_ff() +{ + gsl_wavelet_free(d_wavelet); + gsl_wavelet_workspace_free(d_workspace); + free((char *) d_temp); +} + +int +gr_wavelet_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int count = 0; count < noutput_items; count++) { + for (int i = 0; i < d_size; i++) + d_temp[i] = in[i]; + + if (d_forward) + gsl_wavelet_transform_forward(d_wavelet, + d_temp, + 1, + d_size, + d_workspace); + else + gsl_wavelet_transform_inverse(d_wavelet, + d_temp, + 1, + d_size, + d_workspace); + + for (int i = 0; i < d_size; i++) + out[i] = d_temp[i]; + + in += d_size; + out += d_size; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_wavelet_ff.h b/gnuradio-core/src/lib/general/gr_wavelet_ff.h new file mode 100644 index 000000000..1e98d2e49 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wavelet_ff.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * 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. + */ +#ifndef INCLUDED_GR_WAVELET_FF_H +#define INCLUDED_GR_WAVELET_FF_H + +#include <iostream> +#include <gr_sync_block.h> + +#include <gsl/gsl_errno.h> +#include <gsl/gsl_wavelet.h> + +class gr_wavelet_ff; +typedef boost::shared_ptr<gr_wavelet_ff> gr_wavelet_ff_sptr; + +gr_wavelet_ff_sptr +gr_make_wavelet_ff(int size = 1024, + int order = 20, + bool forward = true); + +/*! + * \brief compute wavelet transform using gsl routines + * \ingroup math + */ + +class gr_wavelet_ff : public gr_sync_block +{ + int d_size; + int d_order; + bool d_forward; + gsl_wavelet *d_wavelet; + gsl_wavelet_workspace *d_workspace; + double *d_temp; + + friend gr_wavelet_ff_sptr + gr_make_wavelet_ff(int size, + int order, + bool forward); + + gr_wavelet_ff(int size, + int order, + bool forward); + +public: + ~gr_wavelet_ff(); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_WAVELET_FF_H */ diff --git a/gnuradio-core/src/lib/general/gr_wavelet_ff.i b/gnuradio-core/src/lib/general/gr_wavelet_ff.i new file mode 100644 index 000000000..9d4264170 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wavelet_ff.i @@ -0,0 +1,31 @@ +/* -*- c++ -*- */ +/* + * 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,wavelet_ff); + +gr_wavelet_ff_sptr gr_make_wavelet_ff(int size, int order, bool forward); + +class gr_wavelet_ff : public gr_sync_block +{ +private: + gr_wavelet_ff(int size, int order, bool forward); +}; + diff --git a/gnuradio-core/src/lib/general/gr_wvps_ff.cc b/gnuradio-core/src/lib/general/gr_wvps_ff.cc new file mode 100644 index 000000000..f814ba8fc --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wvps_ff.cc @@ -0,0 +1,98 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_wvps_ff.h> +#include <gr_io_signature.h> +#include <string.h> + +static int +ceil_log2(int k) +{ + int m = 0; + for (int n = k-1; n > 0; n >>= 1) m++; + return m; +} + +gr_wvps_ff_sptr +gr_make_wvps_ff(int ilen) +{ + return gr_wvps_ff_sptr(new gr_wvps_ff(ilen)); +} + +gr_wvps_ff::gr_wvps_ff(int ilen) + : gr_sync_block("wvps_ff", + gr_make_io_signature(1, 1, sizeof(float) * ilen), + gr_make_io_signature(1, 1, sizeof(float) * ceil_log2(ilen))), + d_ilen(ilen), d_olen(ceil_log2(ilen)) +{ +} + +// input vector assumed to be output from gsl wavelet computation + +int +gr_wvps_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float *) input_items[0]; + float *out = (float *) output_items[0]; + + for (int count = 0; count < noutput_items; count++) { + + // any power? + + if (in[0] == 0.0) { + for (int i = 0; i < d_olen; i++) + out[i] = 0.0; + + } else { + + // get power normalization from 0-th wavelet coefficient + + float scl = 1.0/(in[0]*in[0]); + int k = 1; + + // sum powers over sequences of bins, + // sequence lengths in increasing powers of 2 + + for (int e = 0; e < d_olen; e++) { + int m = 01<<e; + float sum = 0.0; + + for (int l = 0; l < m; l++) + sum += (in[k+l]*in[k+l]); + + out[e] = scl*sum; + k += m; + } + } + + in += d_ilen; + out += d_olen; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_wvps_ff.h b/gnuradio-core/src/lib/general/gr_wvps_ff.h new file mode 100644 index 000000000..ced9646bb --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wvps_ff.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * 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. + */ + +#ifndef INCLUDED_GR_WVPS_FF_H +#define INCLUDED_GR_WVPS_FF_H + +#include <gr_sync_decimator.h> + +class gr_wvps_ff; +typedef boost::shared_ptr<gr_wvps_ff> gr_wvps_ff_sptr; + +gr_wvps_ff_sptr +gr_make_wvps_ff(int ilen); + + +/*! + * \brief computes the Wavelet Power Spectrum from a set of wavelet coefficients + * \ingroup misc + */ +class gr_wvps_ff : public gr_sync_block +{ + friend gr_wvps_ff_sptr + gr_make_wvps_ff(int ilen); + + int d_ilen; + int d_olen; + + protected: + gr_wvps_ff(int ilen); + + public: + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +}; + +#endif /* INCLUDED_GR_WVPS_FF_H */ diff --git a/gnuradio-core/src/lib/general/gr_wvps_ff.i b/gnuradio-core/src/lib/general/gr_wvps_ff.i new file mode 100644 index 000000000..877126fb2 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_wvps_ff.i @@ -0,0 +1,29 @@ +/* -*- c++ -*- */ +/* + * 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +GR_SWIG_BLOCK_MAGIC(gr,wvps_ff); + +gr_wvps_ff_sptr gr_make_wvps_ff(int ilen); + +class gr_wvps_ff : public gr_sync_block +{ +private: + gr_wvps_ff(int ilen); +}; diff --git a/gnuradio-core/src/python/gnuradio/gr/Makefile.am b/gnuradio-core/src/python/gnuradio/gr/Makefile.am index 8b07e4ae1..31d8831fa 100644 --- a/gnuradio-core/src/python/gnuradio/gr/Makefile.am +++ b/gnuradio-core/src/python/gnuradio/gr/Makefile.am @@ -49,6 +49,7 @@ noinst_PYTHON = \ qa_agc.py \ qa_argmax.py \ qa_bin_statistics.py \ + qa_classify.py \ qa_cma_equalizer.py \ qa_complex_to_xxx.py \ qa_constellation_decoder_cb.py \ @@ -93,4 +94,5 @@ noinst_PYTHON = \ qa_skiphead.py \ qa_unpack_k_bits.py \ qa_repeat.py \ - qa_scrambler.py + qa_scrambler.py \ + qa_vector_sink_source.py diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_classify.py b/gnuradio-core/src/python/gnuradio/gr/qa_classify.py new file mode 100755 index 000000000..20ce084dc --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_classify.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python + +import numpy +from gnuradio import gr, gr_unittest +import copy +import pygsl.wavelet as wavelet +import math + + +def sqr(x): + return x*x + +def np2(k): + m = 0 + n = k - 1 + while n > 0: + m += 1 + return m + + +class qa_classify(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + +# def test_000_(self): +# src_data = numpy.zeros(10) +# trg_data = numpy.zeros(10) +# src = gr.vector_source_f(src_data) +# dst = gr.vector_sink_f() +# self.tb.connect(src, dst) +# self.tb.run() +# rsl_data = dst.data() +# sum = 0 +# for (u,v) in zip(trg_data, rsl_data): +# w = u - v +# sum += w * w +# sum /= float(len(trg_data)) +# assert sum < 1e-6 + + def test_001_(self): + src_data = numpy.array([-1.0, 1.0, -1.0, 1.0]) + trg_data = src_data * 0.5 + src = gr.vector_source_f(src_data) + dst = gr.vector_sink_f() + rail = gr.rail_ff(-0.5, 0.5) + self.tb.connect(src, rail) + self.tb.connect(rail, dst) + self.tb.run() + rsl_data = dst.data() + sum = 0 + for (u, v) in zip(trg_data, rsl_data): + w = u - v + sum += w * w + sum /= float(len(trg_data)) + assert sum < 1e-6 + + def test_002_(self): + src_data = numpy.array([-1.0, + -1.0/2.0, + -1.0/3.0, + -1.0/4.0, + -1.0/5.0]) + trg_data = copy.deepcopy(src_data) + + src = gr.vector_source_f(src_data, False, len(src_data)) + st = gr.stretch_ff(-1.0/5.0, len(src_data)) + dst = gr.vector_sink_f(len(src_data)) + self.tb.connect(src, st) + self.tb.connect(st, dst) + self.tb.run() + rsl_data = dst.data() + sum = 0 + for (u, v) in zip(trg_data, rsl_data): + w = u - v + sum += w * w + sum /= float(len(trg_data)) + assert sum < 1e-6 + + def test_003_(self): + src_grid = (0.0, 1.0, 2.0, 3.0, 4.0) + trg_grid = copy.deepcopy(src_grid) + src_data = (0.0, 1.0, 0.0, 1.0, 0.0) + + src = gr.vector_source_f(src_data, False, len(src_grid)) + sq = gr.squash_ff(src_grid, trg_grid) + dst = gr.vector_sink_f(len(trg_grid)) + self.tb.connect(src, sq) + self.tb.connect(sq, dst) + self.tb.run() + rsl_data = dst.data() + sum = 0 + for (u, v) in zip(src_data, rsl_data): + w = u - v + sum += w * w + sum /= float(len(src_data)) + assert sum < 1e-6 + + def test_004_(self): + + n = 256 + o = 4 + ws = wavelet.workspace(n) + w = wavelet.daubechies(o) + + a = numpy.arange(n) + b = numpy.sin(a*numpy.pi/16.0) + c = w.transform_forward(b, ws) + d = w.transform_inverse(c, ws) + + src = gr.vector_source_f(b, False, n) + wv = gr.wavelet_ff(n, o, True) + + dst = gr.vector_sink_f(n) + self.tb.connect(src, wv) + self.tb.connect(wv, dst) + self.tb.run() + e = dst.data() + + sum = 0 + for (u, v) in zip(c, e): + w = u - v + sum += w * w + sum /= float(len(c)) + assert sum < 1e-6 + + def test_005_(self): + + src_data = (1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0) + + dwav = numpy.array(src_data) + wvps = numpy.zeros(3) + # wavelet power spectrum + scl = 1.0/sqr(dwav[0]) + k = 1 + for e in range(len(wvps)): + wvps[e] = scl*sqr(dwav[k:k+(01<<e)]).sum() + k += 01<<e + + src = gr.vector_source_f(src_data, False, len(src_data)) + kon = gr.wvps_ff(len(src_data)) + dst = gr.vector_sink_f(int(math.ceil(math.log(len(src_data), 2)))) + + self.tb.connect(src, kon) + self.tb.connect(kon, dst) + + self.tb.run() + snk_data = dst.data() + + sum = 0 + for (u,v) in zip(snk_data, wvps): + w = u - v + sum += w * w + sum /= float(len(snk_data)) + assert sum < 1e-6 + +if __name__ == '__main__': + gr_unittest.main() + |