diff options
Diffstat (limited to 'gr-wavelet/lib')
-rw-r--r-- | gr-wavelet/lib/CMakeLists.txt | 57 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_squash_ff_impl.cc | 93 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_squash_ff_impl.h | 58 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_wavelet_ff_impl.cc | 103 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_wavelet_ff_impl.h | 55 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_wvps_ff_impl.cc | 98 | ||||
-rw-r--r-- | gr-wavelet/lib/wavelet_wvps_ff_impl.h | 44 |
7 files changed, 508 insertions, 0 deletions
diff --git a/gr-wavelet/lib/CMakeLists.txt b/gr-wavelet/lib/CMakeLists.txt new file mode 100644 index 000000000..f0d9068b7 --- /dev/null +++ b/gr-wavelet/lib/CMakeLists.txt @@ -0,0 +1,57 @@ +# 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. + +######################################################################## +# Setup the include and linker paths +######################################################################## +include_directories( + ${GNURADIO_CORE_INCLUDE_DIRS} + ${GR_WAVELET_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) + +include_directories(${WAVELET_INCLUDE_DIRS}) +link_directories(${WAVELET_LIBRARY_DIRS}) + +include_directories(${Boost_INCLUDE_DIRS}) +link_directories(${Boost_LIBRARY_DIRS}) + +include_directories(${GSL_INCLUDE_DIRS}) +link_directories(${GSL_LIBRARY_DIRS}) + +######################################################################## +# Setup library +######################################################################## +list(APPEND gr_wavelet_sources + wavelet_squash_ff_impl.cc + wavelet_wavelet_ff_impl.cc + wavelet_wvps_ff_impl.cc +) + +list(APPEND wavelet_libs + gnuradio-core + ${Boost_LIBRARIES} + ${WAVELET_LIBRARIES} + ${GSL_LIBRARIES} +) + +add_library(gnuradio-wavelet SHARED ${gr_wavelet_sources}) +target_link_libraries(gnuradio-wavelet ${wavelet_libs}) +GR_LIBRARY_FOO(gnuradio-wavelet RUNTIME_COMPONENT "wavelet_runtime" DEVEL_COMPONENT "wavelet_devel") diff --git a/gr-wavelet/lib/wavelet_squash_ff_impl.cc b/gr-wavelet/lib/wavelet_squash_ff_impl.cc new file mode 100644 index 000000000..89494a9c3 --- /dev/null +++ b/gr-wavelet/lib/wavelet_squash_ff_impl.cc @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2010,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdexcept> +#include <wavelet_squash_ff_impl.h> +#include <gr_io_signature.h> + +// expect input vector of igrid.size y-values, +// produce output vector of ogrid.size y-values + +wavelet_squash_ff_sptr +wavelet_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid) +{ + return gnuradio::get_initial_sptr(new wavelet_squash_ff_impl(igrid, ogrid)); +} + +wavelet_squash_ff_impl::wavelet_squash_ff_impl(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 (unsigned int i = 0; i < d_inum; i++) + d_igrid[i] = igrid[i]; + for (unsigned 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 +} + +wavelet_squash_ff_impl::~wavelet_squash_ff_impl() +{ + free((char *) d_igrid); + free((char *) d_iwork); + free((char *) d_ogrid); + gsl_interp_accel_free(d_accel); + gsl_spline_free(d_spline); +} + +int +wavelet_squash_ff_impl::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 (unsigned int i = 0; i < d_inum; i++) + d_iwork[i] = in[i]; + + gsl_spline_init(d_spline, d_igrid, d_iwork, d_inum); + + for (unsigned 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/gr-wavelet/lib/wavelet_squash_ff_impl.h b/gr-wavelet/lib/wavelet_squash_ff_impl.h new file mode 100644 index 000000000..dac50ddf2 --- /dev/null +++ b/gr-wavelet/lib/wavelet_squash_ff_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ + +#ifndef INCLUDED_WAVELET_SQUASH_FF_IMPL_H +#define INCLUDED_WAVELET_SQUASH_FF_IMPL_H + +#include <wavelet_api.h> +#include <wavelet_squash_ff.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_interp.h> +#include <gsl/gsl_spline.h> + +class WAVELET_API wavelet_squash_ff_impl : public wavelet_squash_ff +{ + 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; + + wavelet_squash_ff_impl(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + + friend WAVELET_API wavelet_squash_ff_sptr + wavelet_make_squash_ff(const std::vector<float> &igrid, + const std::vector<float> &ogrid); + + public: + ~wavelet_squash_ff_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_WAVELET_WAVELET_FF_IMPL_H */ diff --git a/gr-wavelet/lib/wavelet_wavelet_ff_impl.cc b/gr-wavelet/lib/wavelet_wavelet_ff_impl.cc new file mode 100644 index 000000000..ccc1a6d8f --- /dev/null +++ b/gr-wavelet/lib/wavelet_wavelet_ff_impl.cc @@ -0,0 +1,103 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2010,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the 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 <wavelet_wavelet_ff_impl.h> +#include <gr_io_signature.h> + +#include <stdio.h> + +// NB in this version, only Daubechies wavelets +// order is wavelet length, even, 2...20 + +wavelet_wavelet_ff_sptr +wavelet_make_wavelet_ff(int size, + int order, + bool forward) +{ + return gnuradio::get_initial_sptr(new wavelet_wavelet_ff_impl(size, order, forward)); +} + +wavelet_wavelet_ff_impl::wavelet_wavelet_ff_impl(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"); +} + +wavelet_wavelet_ff_impl::~wavelet_wavelet_ff_impl() +{ + gsl_wavelet_free(d_wavelet); + gsl_wavelet_workspace_free(d_workspace); + free((char *) d_temp); +} + +int +wavelet_wavelet_ff_impl::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/gr-wavelet/lib/wavelet_wavelet_ff_impl.h b/gr-wavelet/lib/wavelet_wavelet_ff_impl.h new file mode 100644 index 000000000..dc33a4184 --- /dev/null +++ b/gr-wavelet/lib/wavelet_wavelet_ff_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ +#ifndef INCLUDED_WAVELET_WAVELET_FF_IMPL_H +#define INCLUDED_WAVELET_WAVELET_FF_IMPL_H + +#include <wavelet_wavelet_ff.h> +#include <gsl/gsl_errno.h> +#include <gsl/gsl_wavelet.h> + +class WAVELET_API wavelet_wavelet_ff_impl : public wavelet_wavelet_ff +{ + int d_size; + int d_order; + bool d_forward; + gsl_wavelet *d_wavelet; + gsl_wavelet_workspace *d_workspace; + double *d_temp; + + friend WAVELET_API wavelet_wavelet_ff_sptr + wavelet_make_wavelet_ff(int size, + int order, + bool forward); + + wavelet_wavelet_ff_impl(int size, + int order, + bool forward); + +public: + ~wavelet_wavelet_ff_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_WAVELET_WAVELET_FF_IMPL_H */ diff --git a/gr-wavelet/lib/wavelet_wvps_ff_impl.cc b/gr-wavelet/lib/wavelet_wvps_ff_impl.cc new file mode 100644 index 000000000..b86859b0a --- /dev/null +++ b/gr-wavelet/lib/wavelet_wvps_ff_impl.cc @@ -0,0 +1,98 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <wavelet_wvps_ff_impl.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; +} + +wavelet_wvps_ff_sptr +wavelet_make_wvps_ff(int ilen) +{ + return gnuradio::get_initial_sptr(new wavelet_wvps_ff_impl(ilen)); +} + +wavelet_wvps_ff_impl::wavelet_wvps_ff_impl(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 +wavelet_wvps_ff_impl::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/gr-wavelet/lib/wavelet_wvps_ff_impl.h b/gr-wavelet/lib/wavelet_wvps_ff_impl.h new file mode 100644 index 000000000..553469fde --- /dev/null +++ b/gr-wavelet/lib/wavelet_wvps_ff_impl.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,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. + */ + +#ifndef INCLUDED_WAVELET_WVPS_FF_IMPL_H +#define INCLUDED_WAVELET_WVPS_FF_IMPL_H + +#include <wavelet_wvps_ff.h> + +class WAVELET_API wavelet_wvps_ff_impl : public wavelet_wvps_ff +{ + int d_ilen; + int d_olen; + + friend WAVELET_API wavelet_wvps_ff_sptr + wavelet_make_wvps_ff(int ilen); + + wavelet_wvps_ff_impl(int ilen); + + public: + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_WAVELET_WVPS_FF_IMPL_H */ |