diff options
author | jcorgan | 2008-09-13 23:43:19 +0000 |
---|---|---|
committer | jcorgan | 2008-09-13 23:43:19 +0000 |
commit | c4b73c460d21b3f0f6c608d38144eb7ae09c43ae (patch) | |
tree | d2e0a765bbb533b91ddf0b0a586e0909d3ab412d /gnuradio-core/src/lib | |
parent | bdcae56ac025ffd4c596201e672db87d192398d1 (diff) | |
download | gnuradio-c4b73c460d21b3f0f6c608d38144eb7ae09c43ae.tar.gz gnuradio-c4b73c460d21b3f0f6c608d38144eb7ae09c43ae.tar.bz2 gnuradio-c4b73c460d21b3f0f6c608d38144eb7ae09c43ae.zip |
Merged r9564:9568 from jcorgan/bert into trunk. Adds BPSK bit error testing examples and support blocks.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9569 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r-- | gnuradio-core/src/lib/general/Makefile.am | 13 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_density_b.cc | 68 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_density_b.h | 72 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_density_b.i | 36 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc | 85 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h | 82 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i | 39 |
8 files changed, 395 insertions, 4 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index 024363253..b46590070 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -165,7 +165,9 @@ libgeneral_la_SOURCES = \ malloc16.c \ gr_unpack_k_bits_bb.cc \ gr_descrambler_bb.cc \ - gr_scrambler_bb.cc + gr_scrambler_bb.cc \ + gr_probe_mpsk_snr_c.cc \ + gr_probe_density_b.cc libgeneral_qa_la_SOURCES = \ qa_general.cc \ @@ -324,8 +326,9 @@ grinclude_HEADERS = \ random.h \ gr_unpack_k_bits_bb.h \ gr_descrambler_bb.h \ - gr_scrambler_bb.h - + gr_scrambler_bb.h \ + gr_probe_mpsk_snr_c.h \ + gr_probe_density_b.h noinst_HEADERS = \ qa_general.h \ @@ -454,7 +457,9 @@ swiginclude_HEADERS = \ gri_agc2_cc.i \ gri_agc2_ff.i \ gr_descrambler_bb.i \ - gr_scrambler_bb.i + gr_scrambler_bb.i \ + gr_probe_mpsk_snr_c.i \ + gr_probe_density_b.i CLEANFILES = $(BUILT_SOURCES) *.pyc diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 8326b27b0..542bf6064 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -131,6 +131,8 @@ #include <gr_decode_ccsds_27_fb.h> #include <gr_descrambler_bb.h> #include <gr_scrambler_bb.h> +#include <gr_probe_mpsk_snr_c.h> +#include <gr_probe_density_b.h> %} %include "gr_nop.i" @@ -242,3 +244,5 @@ %include "gr_decode_ccsds_27_fb.i" %include "gr_descrambler_bb.i" %include "gr_scrambler_bb.i" +%include "gr_probe_mpsk_snr_c.i" +%include "gr_probe_density_b.i" diff --git a/gnuradio-core/src/lib/general/gr_probe_density_b.cc b/gnuradio-core/src/lib/general/gr_probe_density_b.cc new file mode 100644 index 000000000..dae4eec74 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_density_b.cc @@ -0,0 +1,68 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * 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_probe_density_b.h> +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +gr_probe_density_b_sptr +gr_make_probe_density_b(double alpha) +{ + return gr_probe_density_b_sptr(new gr_probe_density_b(alpha)); +} + +gr_probe_density_b::gr_probe_density_b(double alpha) + : gr_sync_block("density_b", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(0, 0, 0)) +{ + set_alpha(alpha); + d_density = 1.0; +} + +gr_probe_density_b::~gr_probe_density_b() +{ +} + +int +gr_probe_density_b::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char *)input_items[0]; + + for (int i = 0; i < noutput_items; i++) + d_density = d_alpha*(double)in[i] + d_beta*d_density; + + return noutput_items; +} + +void +gr_probe_density_b::set_alpha(double alpha) +{ + d_alpha = alpha; + d_beta = 1.0-d_alpha; +} + diff --git a/gnuradio-core/src/lib/general/gr_probe_density_b.h b/gnuradio-core/src/lib/general/gr_probe_density_b.h new file mode 100644 index 000000000..92b98d193 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_density_b.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * 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_PROBE_DENSITY_B_H +#define INCLUDED_GR_PROBE_DENSITY_B_H + +#include <gr_sync_block.h> + +class gr_probe_density_b; + +typedef boost::shared_ptr<gr_probe_density_b> gr_probe_density_b_sptr; + +gr_probe_density_b_sptr gr_make_probe_density_b(double alpha); + +/*! + * This block maintains a running average of the input stream and + * makes it available as an accessor function. The input stream + * is type unsigned char. + * + * If you send this block a stream of unpacked bytes, it will tell + * you what the bit density is. + * + * \param alpha Average filter constant + * + */ + +class gr_probe_density_b : public gr_sync_block +{ +private: + friend gr_probe_density_b_sptr gr_make_probe_density_b(double alpha); + + double d_alpha; + double d_beta; + double d_density; + + gr_probe_density_b(double alpha); + +public: + ~gr_probe_density_b(); + + /*! + * \brief Returns the current density value + */ + double density() const { return d_density; } + + /*! + * \brief Set the average filter constant + */ + void set_alpha(double alpha); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_PROBE_DENSITY_B_H */ diff --git a/gnuradio-core/src/lib/general/gr_probe_density_b.i b/gnuradio-core/src/lib/general/gr_probe_density_b.i new file mode 100644 index 000000000..54ed07cf5 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_density_b.i @@ -0,0 +1,36 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,probe_density_b); + +gr_probe_density_b_sptr gr_make_probe_density_b(double alpha); + +class gr_probe_density_b : public gr_sync_block +{ +public: + double density() const; + + void set_alpha(double alpha); + +private: + gr_probe_density_b(); +}; diff --git a/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc new file mode 100644 index 000000000..a0bb99ce1 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.cc @@ -0,0 +1,85 @@ +/* -*- 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_probe_mpsk_snr_c.h> +#include <gr_io_signature.h> + +gr_probe_mpsk_snr_c_sptr +gr_make_probe_mpsk_snr_c(double alpha) +{ + return gr_probe_mpsk_snr_c_sptr(new gr_probe_mpsk_snr_c(alpha)); +} + +gr_probe_mpsk_snr_c::gr_probe_mpsk_snr_c(double alpha) + : gr_sync_block ("probe_mpsk_snr_c", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(0, 0, 0)), + d_signal_mean(0.0), + d_noise_variance(0.0) +{ + set_alpha(alpha); +} + +gr_probe_mpsk_snr_c::~gr_probe_mpsk_snr_c() +{ +} + +int +gr_probe_mpsk_snr_c::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const gr_complex *in = (const gr_complex *) input_items[0]; + + for (int i = 0; i < noutput_items; i++){ + // Update of signal mean estimate + double mag = abs(in[i]); + d_signal_mean = d_alpha*abs(in[i]) + d_beta*d_signal_mean; + + // Update noise variance estimate + double noise = mag-d_signal_mean; + double var = noise*noise; + d_noise_variance = d_alpha*var + d_beta*d_noise_variance; + } + + return noutput_items; +} + +double +gr_probe_mpsk_snr_c::snr() const +{ + if (d_noise_variance == 0.0) + return 0.0; + else + return 10*log10(d_signal_mean*d_signal_mean/d_noise_variance); +} + +void +gr_probe_mpsk_snr_c::set_alpha(double alpha) +{ + d_alpha = alpha; + d_beta = 1.0-alpha; +} diff --git a/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h new file mode 100644 index 000000000..67492f686 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.h @@ -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. + */ +#ifndef INCLUDED_GR_PROBE_MPSK_SNR_C_H +#define INCLUDED_GR_PROBE_MPSK_SNR_C_H + +#include <gr_sync_block.h> + +class gr_probe_mpsk_snr_c; +typedef boost::shared_ptr<gr_probe_mpsk_snr_c> gr_probe_mpsk_snr_c_sptr; + +gr_probe_mpsk_snr_c_sptr +gr_make_probe_mpsk_snr_c(double alpha = 0.0001); + +/*! + * Compute the estimate SNR of an MPSK signal using the Squared Signal + * to Noise Variance (SNV) technique. + * + * This technique assumes an AWGN channel. + * + * \param alpha Mean and variance smoothing filter constant + * \ingroup sink + * + * Compute the running average of the signal mean and noise variance. + * The estimated signal mean, noise variance, and SNR are available + * via accessors. + * + * This SNR estimator is inaccurate below about 7dB SNR. + * + */ +class gr_probe_mpsk_snr_c : public gr_sync_block +{ + double d_alpha; + double d_beta; + double d_signal_mean; + double d_noise_variance; + + // Factory function returning shared pointer of this class + friend gr_probe_mpsk_snr_c_sptr + gr_make_probe_mpsk_snr_c(double alpha); + + // Private constructor + gr_probe_mpsk_snr_c(double alpha); + +public: + ~gr_probe_mpsk_snr_c(); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // Return the estimated signal mean + double signal_mean() const { return d_signal_mean; } + + // Return the estimated noise variance + double noise_variance() const { return d_noise_variance; } + + // Return the estimated signal-to-noise ratio in decibels + double snr() const; + + void set_alpha(double alpha); +}; + +#endif /* INCLUDED_GR_PROBE_MPSK_SNR_C_H */ diff --git a/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i new file mode 100644 index 000000000..37a86b23d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_probe_mpsk_snr_c.i @@ -0,0 +1,39 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,probe_mpsk_snr_c); + +gr_probe_mpsk_snr_c_sptr +gr_make_probe_mpsk_snr_c(double alpha = 0.0001); + +class gr_probe_mpsk_snr_c : public gr_sync_block +{ +private: + void gr_probe_mpsk_snr_c(double alpha); + +public: + double signal_mean(); + double noise_variance(); + double snr(); + + void set_alpha (double alpha); +}; |