[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9880 - in gnuradio/branches/developers/brickle/neww/g
From: |
brickle |
Subject: |
[Commit-gnuradio] r9880 - in gnuradio/branches/developers/brickle/neww/gnuradio-core/src: lib/general python/gnuradio python/gnuradio/gr |
Date: |
Mon, 27 Oct 2008 23:44:15 -0600 (MDT) |
Author: brickle
Date: 2008-10-27 23:44:14 -0600 (Mon, 27 Oct 2008)
New Revision: 9880
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.cc
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.h
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.cc
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.h
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/compandfun.py
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/gr/qa_waveshape.py
Log:
In gnuradio-core/src/liub/general/gr_waveshape blocks
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.cc
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.cc
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.cc
2008-10-28 05:44:14 UTC (rev 9880)
@@ -0,0 +1,104 @@
+/* -*- 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_waveshape_cc.h>
+#include <gr_io_signature.h>
+
+gr_waveshape_cc_sptr
+gr_make_waveshape_cc(const std::vector<float> &waveshape_real,
+ const std::vector<float> &waveshape_imag)
+{
+ return
+ gr_waveshape_cc_sptr(new gr_waveshape_cc(const std::vector<float>
&waveshape_real,
+ const std::vector<float>
&waveshape_imag));
+}
+
+gr_waveshape_cc::gr_waveshape_cc(const std::vector<float> &waveshape_real,
+ const std::vector<float> &waveshape_imag)
+ : gr_sync_block("waveshape_cc",
+ gr_make_io_signature(1, 1, sizeof(complex)),
+ gr_make_io_signature(1, 1, sizeof(complex)))
+{
+ d_size_real = waveshape_real.size();
+ if (!(d_size_real & 01))
+ throw std::out_of_range("waveshape: (real) table must have odd length");
+ d_half_real = d_size_real / 2;
+ d_wshp_real = (float *) malloc((d_size_real + 1) * sizeof(float));
+ for (int i = 0; i < d_size_real; i++)
+ d_wshp_real[i] = waveshape_real[i];
+ d_wshp_real[d_size_real] = d_wshp_real[d_size_real - 1];
+
+ d_size_imag = waveshape_imag.size();
+ if (!(d_size_imag & 01))
+ throw std::out_of_range("waveshape: (imag) table must have odd length");
+ d_half_imag = d_size_imag / 2;
+ d_wshp_imag = (float *) malloc((d_size_imag + 1) * sizeof(float));
+ for (int i = 0; i < d_size_imag; i++)
+ d_wshp_imag[i] = waveshape_imag[i];
+ d_wshp_imag[d_size_imag] = d_wshp_imag[d_size_imag - 1];
+}
+
+gr_waveshape_cc::~gr_waveshape_cc()
+{
+ free((char *) d_wshp_real);
+ free((char *) d_wshp_imag);
+}
+
+int
+gr_waveshape_cc::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const float *in = (const complex *) input_items[0];
+ float *out = (complex *) output_items[0];
+
+ for (int i = 0; i < noutput_items; i++) {
+ int j;
+ float d, x, xn, yr, yi;
+
+ x = in[i].real();
+ if (x < -1.0) x = -1.0;
+ if (x > +1.0) x = +1.0;
+
+ xn = d_half_real * (x + 1.0),
+ j = xn,
+ d = xn - j,
+ yr = d_wshp_real[j] + d * (d_wshp_real[j + 1] - d_wshp_real[j]);
+
+ x = in[i].imag();
+ if (x < -1.0) x = -1.0;
+ if (x > +1.0) x = +1.0;
+
+ xn = d_half_imag * (x + 1.0),
+ j = xn,
+ d = xn - j,
+ yi = d_wshp_imag[j] + d * (d_wshp_imag[j + 1] - d_wshp_imag[j]);
+
+ out[i] = complex(yr, yi);
+ }
+
+ return noutput_items;
+}
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.h
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.h
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_cc.h
2008-10-28 05:44:14 UTC (rev 9880)
@@ -0,0 +1,67 @@
+/* -*- 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_WAVESHAPE_FF_H_
+#define INCLUDED_GR_WAVESHAPE_FF_H_
+
+#include <gr_sync_block.h>
+#include <gr_complex.h>
+
+/*!
+ * \brief Applies bipolar waveshaping to +/-1 input, complex
+ * \param waveshape_real is table representing I part waveshape function,
sampled
+ * by linear interpolation
+ * \param waveshape_imag is table representing Q part waveshape function,
sampled
+ * by linear interpolation
+ * \ingroup misc
+ */
+
+class gr_waveshape_ff;
+typedef boost::shared_ptr<gr_waveshape_ff> gr_waveshape_ff_sptr;
+
+gr_waveshape_ff_sptr gr_make_waveshape_ff(const std::vector<float>
&waveshape_real,
+ const std::vector<float>
&waveshape_imag);
+
+class gr_waveshape_ff : public gr_sync_block
+{
+ friend gr_waveshape_ff_sptr
+ gr_make_waveshape_ff(const std::vector<float> &waveshape_real,
+ const std::vector<float> &waveshape_imag);
+
+ float *d_wshp_real;
+ size_t d_size_real;
+ size_t d_half_real;
+
+ float *d_wshp_imag;
+ size_t d_size_imag;
+ size_t d_half_imag;
+
+ gr_waveshape_ff(const std::vector<float> &waveshape_real,
+ const std::vector<float> &waveshape_imag);
+
+ public:
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.cc
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.cc
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.cc
2008-10-28 05:44:14 UTC (rev 9880)
@@ -0,0 +1,82 @@
+/* -*- 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_waveshape_ff.h>
+#include <gr_io_signature.h>
+
+gr_waveshape_ff_sptr
+gr_make_waveshape_ff(const std::vector<float> &waveshape)
+{
+ return
+ gr_waveshape_ff_sptr(new gr_waveshape_ff(const std::vector<float>
&waveshape));
+}
+
+gr_waveshape_ff::gr_waveshape_ff(const std::vector<float> &waveshape)
+ : gr_sync_block("waveshape_ff",
+ gr_make_io_signature(1, 1, sizeof(float)),
+ gr_make_io_signature(1, 1, sizeof(float)))
+{
+ d_size = waveshape.size();
+ if (!(d_size & 01))
+ throw std::out_of_range("waveshape: table must have odd length");
+ d_half = d_size / 2;
+ d_wshp = (float *) malloc((d_size + 1) * sizeof(float));
+ for (int i = 0; i < d_size; i++)
+ d_wshp[i] = waveshape[i];
+ d_wshp[d_size] = d_wshp[d_size - 1];
+}
+
+gr_waveshape_ff::~gr_waveshape_ff()
+{
+ free((char *) d_wshp);
+}
+
+int
+gr_waveshape_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++) {
+ int j;
+ float d, x, xn, y;
+
+ x = in[i];
+ if (x < -1.0) x = -1.0;
+ if (x > +1.0) x = +1.0;
+
+ xn = d_half * (x + 1.0),
+ j = xn,
+ d = xn - j,
+ y = d_wshp[j] + d * (d_wshp[j + 1] - d_wshp[j]);
+
+ out[i] = y;
+ }
+
+ return noutput_items;
+}
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.h
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.h
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/lib/general/gr_waveshape_ff.h
2008-10-28 05:44:14 UTC (rev 9880)
@@ -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_WAVESHAPE_FF_H_
+#define INCLUDED_GR_WAVESHAPE_FF_H_
+
+#include <gr_sync_block.h>
+
+/*!
+ * \brief Applies bipolar waveshaping to +/-1 input, real
+ * \param waveshape is table representing waveshape function, sampled
+ * by linear interpolation
+ * \ingroup misc
+ */
+
+class gr_waveshape_ff;
+typedef boost::shared_ptr<gr_waveshape_ff> gr_waveshape_ff_sptr;
+
+gr_waveshape_ff_sptr gr_make_waveshape_ff(const std::vector<float> &waveshape);
+
+class gr_waveshape_ff : public gr_sync_block
+{
+ friend gr_waveshape_ff_sptr
+ gr_make_waveshape_ff(const std::vector<float> &waveshape);
+
+ float *d_wshp;
+ size_t d_size;
+ size_t d_half;
+
+ gr_waveshape_ff(const std::vector<float> &waveshape);
+
+ public:
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/compandfun.py
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/compandfun.py
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/compandfun.py
2008-10-28 05:44:14 UTC (rev 9880)
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import math
+import numpy
+
+"""
+Create exponential function specifically for signal companding
+length must be odd, >=3; central point always 0
+fac<0 -> compression
+fac==0 -> linear (default)
+fac>0 -> expansion
+"""
+
+class compandfun():
+
+ def __init__(self,
+ lng = 3,
+ fac = 0):
+ if not ((lng & 01) and (lng >= 3)):
+ raise RuntimeError, 'compand_fun: lng must be odd, >=3'
+ self.lng = lng
+ self.hlf = lng/2
+ self.fac = fac
+ self.tbl = numpy.zeros(self.lng)
+ self._gen()
+
+
+ def _gen(self):
+ if self.fac == 0:
+ for i in range(self.hlf+1):
+ self.tbl[self.hlf+i] = i/float(self.hlf)
+ else:
+ inc = self.fac/float(self.hlf)
+ scl = 1.0-math.exp(self.fac)
+ for i in range(self.hlf+1):
+ self.tbl[self.hlf+i] = (1.0-math.exp(i*inc))/scl
+ for i in range(self.hlf):
+ self.tbl[self.hlf-i-1] = -self.tbl[self.hlf+i+1]
+
+
+ def reset(self, fac = 0):
+ self.fac = fac
+ self._gen()
+
+
+ def table(self):
+ return self.tbl
+
+
+ def regen(self, fac = 0):
+ self.fac = fac
+ self._gen()
+ return self.tbl
Added:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/gr/qa_waveshape.py
===================================================================
---
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/gr/qa_waveshape.py
(rev 0)
+++
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/gr/qa_waveshape.py
2008-10-28 05:44:14 UTC (rev 9880)
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest
+
+class test_waveshape(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+
+ def tearDown(self):
+ self.tb = None
+
+
+# tres simple: waveshaping function just inverts signal
+
+ def test_001(self):
+ ws_table = (+1.0, 0.0, -1.0)
+ src_data = (-1.0, -0.5, 0.0, 0.5, 1.0)
+ expected = ( 1.0, 0.5, 0.0, -0.5, -1.0)
+ expected = tuple([-x for x in src_data])
+
+ src = gr.vector_source_f(src_data)
+ op = gr.waveshape_ff(ws_table)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect (src, op, dst)
+ self.tb.run()
+ res_data = dst.data()
+
+ self.assertFloatTuplesAlmostEqual(expected, res_data)
+
+
+ def test_002(self):
+ ws_table = (+1.0, 0.0, -1.0)
+ src_data = (-1.0-1.0j,
+ -0.5-0.5j,
+ 0.0+0.0j,
+ 0.5+0.5j,
+ 1.0+1.0j)
+ expected = tuple([complex(-z.real,-z.imag) for z in src_data])
+
+ src = gr.vector_source_c(src_data)
+ op = gr.waveshape_cc(ws_table, ws_table)
+ dst = gr.vector_sink_c()
+
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ res_data = dst.data()
+
+ self.assertComplexTuplesAlmostEqual(expected, res_data)
+
+
+if __name__ == '__main__':
+ gr_unittest.main ()
+
Property changes on:
gnuradio/branches/developers/brickle/neww/gnuradio-core/src/python/gnuradio/gr/qa_waveshape.py
___________________________________________________________________
Name: svn:executable
+ *
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9880 - in gnuradio/branches/developers/brickle/neww/gnuradio-core/src: lib/general python/gnuradio python/gnuradio/gr,
brickle <=