summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/general
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2013-02-20 12:21:29 -0500
committerTom Rondeau <trondeau@vt.edu>2013-02-20 12:41:04 -0500
commit83b45543ee5a5533b3a384a3eed2e5ca0047a70c (patch)
tree70e2fe5f1f72354dcf67f7ef5be9865d67c5426e /gnuradio-core/src/lib/general
parent7cbeddfd5a0cffba51a3946a8dd44b9838e42361 (diff)
digital: cleaning up conversion to 3.7 for simple_correlator.
blocks: same for count_bits.
Diffstat (limited to 'gnuradio-core/src/lib/general')
-rw-r--r--gnuradio-core/src/lib/general/CMakeLists.txt3
-rw-r--r--gnuradio-core/src/lib/general/general.i2
-rw-r--r--gnuradio-core/src/lib/general/gr_count_bits.cc93
-rw-r--r--gnuradio-core/src/lib/general/gr_count_bits.h33
-rw-r--r--gnuradio-core/src/lib/general/gr_simple_correlator.cc237
-rw-r--r--gnuradio-core/src/lib/general/gr_simple_correlator.h111
-rw-r--r--gnuradio-core/src/lib/general/gr_simple_correlator.i31
7 files changed, 0 insertions, 510 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt
index 26dab910c9..c562224009 100644
--- a/gnuradio-core/src/lib/general/CMakeLists.txt
+++ b/gnuradio-core/src/lib/general/CMakeLists.txt
@@ -69,7 +69,6 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_BINARY_DIR}/gr_constants.cc)
########################################################################
list(APPEND gnuradio_core_sources
${CMAKE_CURRENT_SOURCE_DIR}/gr_circular_file.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/gr_count_bits.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_fast_atan2f.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_fxpt.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_misc.cc
@@ -102,7 +101,6 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/gr_core_api.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_circular_file.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_constants.h
- ${CMAKE_CURRENT_SOURCE_DIR}/gr_count_bits.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_expj.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_fxpt.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_fxpt_nco.h
@@ -174,7 +172,6 @@ set(gr_core_general_triple_threats
gr_remez
gr_rms_cf
gr_rms_ff
- gr_simple_correlator
gr_skiphead
gr_stretch_ff
gr_test
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index e379c40867..53dcac6fb6 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -32,7 +32,6 @@
#include <gr_check_counting_s.h>
#include <gr_lfsr_32k_source_s.h>
#include <gr_check_lfsr_32k_s.h>
-#include <gr_simple_correlator.h>
#include <gr_align_on_samplenumbers_ss.h>
#include <gr_complex_to_xxx.h>
#include <gr_complex_to_interleaved_short.h>
@@ -82,7 +81,6 @@
%include "gr_check_counting_s.i"
%include "gr_lfsr_32k_source_s.i"
%include "gr_check_lfsr_32k_s.i"
-%include "gr_simple_correlator.i"
%include "gr_align_on_samplenumbers_ss.i"
%include "gr_complex_to_xxx.i"
%include "gr_complex_to_interleaved_short.i"
diff --git a/gnuradio-core/src/lib/general/gr_count_bits.cc b/gnuradio-core/src/lib/general/gr_count_bits.cc
deleted file mode 100644
index 4776fe61a9..0000000000
--- a/gnuradio-core/src/lib/general/gr_count_bits.cc
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2003 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.
- */
-
-#include <gr_count_bits.h>
-
-/*
- * these are slow and obvious. If you need something faster, fix these
- */
-
-// return number of set bits in the low 8 bits of x
-unsigned int
-gr_count_bits8 (unsigned int x)
-{
- int count = 0;
-
- for (int i = 0; i < 8; i++)
- if (x & (1 << i))
- count++;
-
- return count;
-}
-
-// return number of set bits in the low 16 bits of x
-unsigned int
-gr_count_bits16 (unsigned int x)
-{
- int count = 0;
-
- for (int i = 0; i < 16; i++)
- if (x & (1 << i))
- count++;
-
- return count;
-
-}
-
-
-#if 0 // slow and obvious
-
-// return number of set bits in the low 32 bits of x
-unsigned int
-gr_count_bits32 (unsigned int x)
-{
- int count = 0;
-
- for (int i = 0; i < 32; i++)
- if (x & (1 << i))
- count++;
-
- return count;
-}
-
-#else // fast and not so obvious
-
-// return number of set bits in the low 32 bits of x
-unsigned int
-gr_count_bits32 (unsigned int x)
-{
- unsigned res = (x & 0x55555555) + ((x >> 1) & 0x55555555);
- res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
- res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
- res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
- return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
-}
-
-#endif
-
-
-// return number of set bits in the low 64 bits of x
-unsigned int
-gr_count_bits64 (unsigned long long x)
-{
- return gr_count_bits32((x >> 32) & 0xffffffff) + gr_count_bits32(x & 0xffffffff);
-}
diff --git a/gnuradio-core/src/lib/general/gr_count_bits.h b/gnuradio-core/src/lib/general/gr_count_bits.h
deleted file mode 100644
index 76d0173eb5..0000000000
--- a/gnuradio-core/src/lib/general/gr_count_bits.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2003 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 _GR_COUNT_BITS_H_
-#define _GR_COUNT_BITS_H_
-
-#include <gr_core_api.h>
-
-GR_CORE_API unsigned int gr_count_bits8(unsigned int x); // return number of set bits in the low 8 bits of x
-GR_CORE_API unsigned int gr_count_bits16(unsigned int x); // return number of set bits in the low 16 bits of x
-GR_CORE_API unsigned int gr_count_bits32(unsigned int x); // return number of set bits in the low 32 bits of x
-GR_CORE_API unsigned int gr_count_bits64(unsigned long long int x);
-
-#endif /* _GR_COUNT_BITS_H_ */
diff --git a/gnuradio-core/src/lib/general/gr_simple_correlator.cc b/gnuradio-core/src/lib/general/gr_simple_correlator.cc
deleted file mode 100644
index b9209e74f0..0000000000
--- a/gnuradio-core/src/lib/general/gr_simple_correlator.cc
+++ /dev/null
@@ -1,237 +0,0 @@
-/* -*- c++ -*- */
-/*
- * Copyright 2004,2010 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_simple_correlator.h>
-#include <gr_simple_framer_sync.h>
-#include <gr_io_signature.h>
-#include <assert.h>
-#include <stdexcept>
-#include <gr_count_bits.h>
-#include <string.h>
-#include <cstdio>
-
-
-static const int THRESHOLD = 3;
-
-gr_simple_correlator_sptr
-gr_make_simple_correlator (int payload_bytesize)
-{
- return gnuradio::get_initial_sptr(new gr_simple_correlator (payload_bytesize));
-}
-
-gr_simple_correlator::gr_simple_correlator (int payload_bytesize)
- : gr_block ("simple_correlator",
- gr_make_io_signature (1, 1, sizeof (float)),
- gr_make_io_signature (1, 1, sizeof (unsigned char))),
- d_payload_bytesize (payload_bytesize),
- d_state (ST_LOOKING), d_osi (0),
- d_bblen ((payload_bytesize + GRSF_PAYLOAD_OVERHEAD) * GRSF_BITS_PER_BYTE),
- d_bitbuf (new unsigned char [d_bblen]),
- d_pktbuf (new unsigned char [d_bblen/GRSF_BITS_PER_BYTE]),
- d_bbi (0)
-{
- d_avbi = 0;
- d_accum = 0.0;
- d_avg = 0.0;
- for (int i = 0; i < AVG_PERIOD; i++)
- d_avgbuf[i] = 0.0;
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- d_debug_fp = fopen("corr.log", "w");
-#endif
- enter_looking ();
-
-}
-
-gr_simple_correlator::~gr_simple_correlator ()
-{
-#ifdef DEBUG_SIMPLE_CORRELATOR
- fclose(d_debug_fp);
-#endif
- delete [] d_bitbuf;
- delete [] d_pktbuf;
-}
-
-
-void
-gr_simple_correlator::enter_looking ()
-{
- fflush (stdout);
- // fprintf (stderr, ">>> enter_looking\n");
- d_state = ST_LOOKING;
- for (int i = 0; i < OVERSAMPLE; i++)
- d_shift_reg[i] = 0;
- d_osi = 0;
-
- d_avbi = 0;
- d_avg = d_avg * 0.5;
- d_accum = 0;
- for (int i = 0; i < AVG_PERIOD; i++)
- d_avgbuf[i] = 0.0;
-}
-
-void
-gr_simple_correlator::enter_under_threshold ()
-{
- fflush (stdout);
- // fprintf (stderr, ">>> enter_under_threshold\n");
- d_state = ST_UNDER_THRESHOLD;
- d_transition_osi = d_osi;
-}
-
-void
-gr_simple_correlator::enter_locked ()
-{
- d_state = ST_LOCKED;
- int delta = sub_index (d_osi, d_transition_osi);
- d_center_osi = add_index (d_transition_osi, delta/2);
- d_center_osi = add_index (d_center_osi, 3); // FIXME
- d_bbi = 0;
- fflush (stdout);
- // fprintf (stderr, ">>> enter_locked d_center_osi = %d\n", d_center_osi);
-
- d_avg = std::max(-1.0, std::min(1.0, d_accum * (1.0/AVG_PERIOD)));
- // fprintf(stderr, ">>> enter_locked d_avg = %g\n", d_avg);
-}
-
-static void
-packit (unsigned char *pktbuf, const unsigned char *bitbuf, int bitcount)
-{
- for (int i = 0; i < bitcount; i += 8){
- int t = bitbuf[i+0] & 0x1;
- t = (t << 1) | (bitbuf[i+1] & 0x1);
- t = (t << 1) | (bitbuf[i+2] & 0x1);
- t = (t << 1) | (bitbuf[i+3] & 0x1);
- t = (t << 1) | (bitbuf[i+4] & 0x1);
- t = (t << 1) | (bitbuf[i+5] & 0x1);
- t = (t << 1) | (bitbuf[i+6] & 0x1);
- t = (t << 1) | (bitbuf[i+7] & 0x1);
- *pktbuf++ = t;
- }
-}
-
-void
-gr_simple_correlator::update_avg(float x)
-{
- d_accum -= d_avgbuf[d_avbi];
- d_avgbuf[d_avbi] = x;
- d_accum += x;
- d_avbi = (d_avbi + 1) & (AVG_PERIOD-1);
-}
-
-
-int
-gr_simple_correlator::general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
-{
- const float *in = (const float *) input_items[0];
- unsigned char *out = (unsigned char *) output_items[0];
-
-
- int n = 0;
- int nin = ninput_items[0];
- int decision;
- int hamming_dist;
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- struct debug_data {
- float raw_data;
- float sampled;
- float enter_locked;
- } debug_data;
-#endif
-
- while (n < nin){
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- debug_data.raw_data = in[n];
- debug_data.sampled = 0.0;
- debug_data.enter_locked = 0.0;
-#endif
-
- switch (d_state){
-
- case ST_LOCKED:
- if (d_osi == d_center_osi){
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- debug_data.sampled = 1.0;
-#endif
- decision = slice (in[n]);
-
- d_bitbuf[d_bbi] = decision;
- d_bbi++;
- if (d_bbi >= d_bblen){
- // printf ("got whole packet\n");
- packit (d_pktbuf, d_bitbuf, d_bbi);
- printf ("seqno %3d\n", d_pktbuf[0]);
- memcpy (out, &d_pktbuf[GRSF_PAYLOAD_OVERHEAD], d_payload_bytesize);
- enter_looking ();
- consume_each (n + 1);
- return d_payload_bytesize;
- }
- }
- break;
-
- case ST_LOOKING:
- case ST_UNDER_THRESHOLD:
- update_avg(in[n]);
- decision = slice (in[n]);
- d_shift_reg[d_osi] = (d_shift_reg[d_osi] << 1) | decision;
-
- hamming_dist = gr_count_bits64 (d_shift_reg[d_osi] ^ GRSF_SYNC);
- // printf ("%2d %d\n", hamming_dist, d_osi);
-
- if (d_state == ST_LOOKING && hamming_dist <= THRESHOLD){
- // We're seeing a good PN code, remember location
- enter_under_threshold ();
- }
- else if (d_state == ST_UNDER_THRESHOLD && hamming_dist > THRESHOLD){
- // no longer seeing good PN code, compute center of goodness
- enter_locked ();
-#ifdef DEBUG_SIMPLE_CORRELATOR
- debug_data.enter_locked = 1.0;
-#endif
- }
- break;
-
- default:
- assert (0);
- }
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- fwrite(&debug_data, sizeof (debug_data), 1, d_debug_fp);
-#endif
-
- d_osi = add_index (d_osi, 1);
- n++;
- }
-
- consume_each (n);
- return 0;
-}
diff --git a/gnuradio-core/src/lib/general/gr_simple_correlator.h b/gnuradio-core/src/lib/general/gr_simple_correlator.h
deleted file mode 100644
index 37d00c125e..0000000000
--- a/gnuradio-core/src/lib/general/gr_simple_correlator.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- 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_SIMPLE_CORRELATOR_H
-#define INCLUDED_GR_SIMPLE_CORRELATOR_H
-
-#include <gr_core_api.h>
-#include <gr_block.h>
-#include <assert.h>
-
-//#define DEBUG_SIMPLE_CORRELATOR
-
-class gr_simple_correlator;
-typedef boost::shared_ptr<gr_simple_correlator> gr_simple_correlator_sptr;
-
-GR_CORE_API gr_simple_correlator_sptr gr_make_simple_correlator (int payload_bytesize);
-
-/*!
- * \brief inverse of gr_simple_framer (more or less)
- * \ingroup sync_blk
- */
-class GR_CORE_API gr_simple_correlator : public gr_block
-{
- static const int OVERSAMPLE = 8;
- enum state_t { ST_LOOKING, ST_UNDER_THRESHOLD, ST_LOCKED };
-
- int d_payload_bytesize;
- state_t d_state;
- unsigned int d_osi; // over sample index [0,OVERSAMPLE-1]
- unsigned int d_transition_osi; // first index where Hamming dist < thresh
- unsigned int d_center_osi; // center of bit
- unsigned long long int d_shift_reg[OVERSAMPLE];
- int d_bblen; // length of bitbuf
- unsigned char *d_bitbuf; // demodulated bits
- unsigned char *d_pktbuf; // temp packet buf
- int d_bbi; // bitbuf index
-
- static const int AVG_PERIOD = 512; // must be power of 2 (for freq offset correction)
- int d_avbi;
- float d_avgbuf[AVG_PERIOD];
- float d_avg;
- float d_accum;
-
-#ifdef DEBUG_SIMPLE_CORRELATOR
- FILE *d_debug_fp; // binary log file
-#endif
-
- friend GR_CORE_API gr_simple_correlator_sptr gr_make_simple_correlator (int payload_bytesize);
- gr_simple_correlator (int payload_bytesize);
-
-
- inline int slice (float x)
- {
- return x >= d_avg ? 1 : 0;
- }
-
- void update_avg(float x);
-
- void enter_locked ();
- void enter_under_threshold ();
- void enter_looking ();
-
- static int add_index (int a, int b)
- {
- int t = a + b;
- if (t >= OVERSAMPLE)
- t -= OVERSAMPLE;
- assert (t >= 0 && t < OVERSAMPLE);
- return t;
- }
-
- static int sub_index (int a, int b)
- {
- int t = a - b;
- if (t < 0)
- t += OVERSAMPLE;
- assert (t >= 0 && t < OVERSAMPLE);
- return t;
- }
-
-
- public:
- ~gr_simple_correlator ();
-
- int general_work (int noutput_items,
- gr_vector_int &ninput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items);
-};
-
-
-#endif /* INCLUDED_GR_SIMPLE_CORRELATOR_H */
diff --git a/gnuradio-core/src/lib/general/gr_simple_correlator.i b/gnuradio-core/src/lib/general/gr_simple_correlator.i
deleted file mode 100644
index 24d133072f..0000000000
--- a/gnuradio-core/src/lib/general/gr_simple_correlator.i
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- 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.
- */
-
-GR_SWIG_BLOCK_MAGIC(gr,simple_correlator);
-
-gr_simple_correlator_sptr gr_make_simple_correlator (int payload_bytesize);
-
-class gr_simple_correlator : public gr_block
-{
- private:
- gr_simple_correlator (int payload_bytesize);
-};