diff options
author | eb | 2008-10-27 07:05:13 +0000 |
---|---|---|
committer | eb | 2008-10-27 07:05:13 +0000 |
commit | 8b9d8612e3e32a8037782e027690e14b29254335 (patch) | |
tree | d5c604aa316a225112485220d9b539ef1fa3e0eb /gnuradio-core/src | |
parent | 5805bd817fe4c8511297acd64b79457e2585980f (diff) | |
download | gnuradio-8b9d8612e3e32a8037782e027690e14b29254335.tar.gz gnuradio-8b9d8612e3e32a8037782e027690e14b29254335.tar.bz2 gnuradio-8b9d8612e3e32a8037782e027690e14b29254335.zip |
Added basic wavelet classifier blocks. GSL is now a prerequisite for
gnuradio-core. Merged from eb/frank -r9627:9868 to trunk.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9870 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src')
20 files changed, 1092 insertions, 2 deletions
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() + |