summaryrefslogtreecommitdiff
path: root/gr-wavelet/lib
diff options
context:
space:
mode:
authorJohnathan Corgan <jcorgan@corganenterprises.com>2012-04-01 13:23:06 -0700
committerJohnathan Corgan <jcorgan@corganenterprises.com>2012-04-01 13:55:45 -0700
commitf9b73b1710f19529b99f8f69c8e3a06839ad68bc (patch)
treec6ec3e97110c75eb187875a9e1a8fd22b7123b2b /gr-wavelet/lib
parenta40ac1d61259dda14e5a6abf328004d3f4b17f02 (diff)
wavelet: move wavelet blocks to new top-level component
Diffstat (limited to 'gr-wavelet/lib')
-rw-r--r--gr-wavelet/lib/CMakeLists.txt53
-rw-r--r--gr-wavelet/lib/wavelet_squash_ff.cc93
-rw-r--r--gr-wavelet/lib/wavelet_wavelet_ff.cc103
-rw-r--r--gr-wavelet/lib/wavelet_wvps_ff.cc98
4 files changed, 347 insertions, 0 deletions
diff --git a/gr-wavelet/lib/CMakeLists.txt b/gr-wavelet/lib/CMakeLists.txt
new file mode 100644
index 0000000000..51a5d39899
--- /dev/null
+++ b/gr-wavelet/lib/CMakeLists.txt
@@ -0,0 +1,53 @@
+# 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_BINARY_DIR}
+)
+
+include_directories(${WAVELET_INCLUDE_DIRS})
+link_directories(${WAVELET_LIBRARY_DIRS})
+
+include_directories(${Boost_INCLUDE_DIRS})
+link_directories(${Boost_LIBRARY_DIRS})
+
+########################################################################
+# Setup library
+########################################################################
+list(APPEND gr_wavelet_sources
+ wavelet_squash_ff.cc
+ wavelet_wavelet_ff.cc
+ wavelet_wvps_ff.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.cc b/gr-wavelet/lib/wavelet_squash_ff.cc
new file mode 100644
index 0000000000..9316d34fee
--- /dev/null
+++ b/gr-wavelet/lib/wavelet_squash_ff.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.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(igrid, ogrid));
+}
+
+wavelet_squash_ff::wavelet_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 (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::~wavelet_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
+wavelet_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 (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_wavelet_ff.cc b/gr-wavelet/lib/wavelet_wavelet_ff.cc
new file mode 100644
index 0000000000..3f4354f313
--- /dev/null
+++ b/gr-wavelet/lib/wavelet_wavelet_ff.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.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(size, order, forward));
+}
+
+wavelet_wavelet_ff::wavelet_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");
+}
+
+wavelet_wavelet_ff::~wavelet_wavelet_ff()
+{
+ gsl_wavelet_free(d_wavelet);
+ gsl_wavelet_workspace_free(d_workspace);
+ free((char *) d_temp);
+}
+
+int
+wavelet_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/gr-wavelet/lib/wavelet_wvps_ff.cc b/gr-wavelet/lib/wavelet_wvps_ff.cc
new file mode 100644
index 0000000000..5edc43496d
--- /dev/null
+++ b/gr-wavelet/lib/wavelet_wvps_ff.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.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(ilen));
+}
+
+wavelet_wvps_ff::wavelet_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
+wavelet_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;
+}