diff -u -r -N gnuradio-core.orig/ChangeLog gnuradio-core/ChangeLog --- gnuradio-core.orig/ChangeLog 2005-01-02 00:15:36.000000000 +0100 +++ gnuradio-core/ChangeLog 2005-01-12 02:00:49.000000000 +0100 @@ -1,3 +1,6 @@ +2005-01-12 Martin Dvh + * src/lib/general/gr_squelch_cc.[cc,h,i}: new block + 2005-01-01 Eric Blossom * src/lib/io/sdr_1000.i (class sdr_1000_base): removed default arg diff -u -r -N gnuradio-core.orig/src/lib/general/Makefile.am gnuradio-core/src/lib/general/Makefile.am --- gnuradio-core.orig/src/lib/general/Makefile.am 2004-12-22 00:01:05.000000000 +0100 +++ gnuradio-core/src/lib/general/Makefile.am 2005-01-12 01:30:49.000000000 +0100 @@ -99,6 +99,7 @@ libgeneral_la_SOURCES = \ $(GENERATED_CC) \ + gr_abs_cf.cc \ gr_bytes_to_syms.cc \ gr_check_counting_s.cc \ gr_check_lfsr_32k_s.cc \ @@ -129,6 +130,7 @@ gr_short_to_float.cc \ gr_simple_framer.cc \ gr_simple_correlator.cc \ + gr_squelch_cc.cc \ gr_sync_block.cc \ gr_sync_decimator.cc \ gr_sync_interpolator.cc \ @@ -150,6 +152,7 @@ grinclude_HEADERS = \ $(GENERATED_H) \ malloc16.h \ + gr_abs_cf.h \ gr_agc.h \ gr_bytes_to_syms.h \ gr_check_counting_s.h \ @@ -186,6 +189,7 @@ gr_simple_correlator.h \ gr_simple_framer.h \ gr_simple_framer_sync.h \ + gr_squelch_cc.h \ gr_sync_block.h \ gr_sync_decimator.h \ gr_sync_interpolator.h \ @@ -211,6 +215,7 @@ swiginclude_HEADERS = \ general.i \ general_generated.i \ + gr_abs_cf.i \ gr_bytes_to_syms.i \ gr_check_counting_s.i \ gr_check_lfsr_32k_s.i \ @@ -236,6 +241,7 @@ gr_short_to_float.i \ gr_simple_correlator.i \ gr_simple_framer.i \ + gr_squelch_cc.i \ gr_sync_block.i \ gr_sync_decimator.i \ gr_sync_interpolator.i \ diff -u -r -N gnuradio-core.orig/src/lib/general/general.i gnuradio-core/src/lib/general/general.i --- gnuradio-core.orig/src/lib/general/general.i 2004-12-17 21:56:28.000000000 +0100 +++ gnuradio-core/src/lib/general/general.i 2005-01-12 01:30:49.000000000 +0100 @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -64,6 +66,8 @@ %include "gr_sig_source_waveform.h" %include "gr_noise_type.h" %include "gr_quadrature_demod_cf.i" +%include "gr_squelch_cc.i" +%include "gr_abs_cf.i" %include "gr_remez.i" %include "gr_float_to_complex.i" %include "gr_check_counting_s.i" diff -u -r -N gnuradio-core.orig/src/lib/general/gr_abs_cf.cc gnuradio-core/src/lib/general/gr_abs_cf.cc --- gnuradio-core.orig/src/lib/general/gr_abs_cf.cc 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_abs_cf.cc 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,63 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +gr_abs_cf::gr_abs_cf (): +gr_sync_block ("abs_cf", + gr_make_io_signature (1, 1, sizeof (gr_complex)), + gr_make_io_signature (1, 1, sizeof (float))) +{ +} + +gr_abs_cf_sptr +gr_make_abs_cf () +{ + return gr_abs_cf_sptr (new gr_abs_cf ()); +} + +int +gr_abs_cf::work (int noutput_items, + gr_vector_const_void_star & input_items, + gr_vector_void_star & output_items) +{ + gr_complex *in = (gr_complex *) input_items[0]; + float *out = (float *) output_items[0]; + int i; + for ( i = 0; i < noutput_items-3; i+=4)//stride=4 + { + out[i] = abs (in[i]); + out[i+1]=abs (in[i+1]); + out[i+2]=abs (in[i+2]); + out[i+3]=abs (in[i+3]); + } + for (; i < noutput_items; i++) //tail section + { + out[i] = abs (in[i]); + } + return noutput_items; +} diff -u -r -N gnuradio-core.orig/src/lib/general/gr_abs_cf.h gnuradio-core/src/lib/general/gr_abs_cf.h --- gnuradio-core.orig/src/lib/general/gr_abs_cf.h 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_abs_cf.h 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,56 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_ABS_CF_H +#define INCLUDED_GR_ABS_CF_H + +#include + +class gr_abs_cf; +typedef + boost::shared_ptr < + gr_abs_cf > + gr_abs_cf_sptr; +gr_abs_cf_sptr +gr_make_abs_cf (); + +/*! + * \brief abs: compute absolute value, can be used for envelope AM demodulator: complex in, complex out + * \ingroup block + */ +class + gr_abs_cf: + public + gr_sync_block +{ + friend gr_abs_cf_sptr + gr_make_abs_cf (); + gr_abs_cf (); + + public: + int + work (int noutput_items, + gr_vector_const_void_star & input_items, + gr_vector_void_star & output_items); +}; + +#endif /* INCLUDED_GR_ABS_CF_H */ diff -u -r -N gnuradio-core.orig/src/lib/general/gr_abs_cf.i gnuradio-core/src/lib/general/gr_abs_cf.i --- gnuradio-core.orig/src/lib/general/gr_abs_cf.i 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_abs_cf.i 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,30 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +GR_SWIG_BLOCK_MAGIC (gr, abs_cf) + +gr_abs_cf_sptr gr_make_abs_cf ( ); + +class gr_abs_cf : public gr_sync_block +{ + gr_abs_cf ( ); +}; diff -u -r -N gnuradio-core.orig/src/lib/general/gr_squelch_cc.cc gnuradio-core/src/lib/general/gr_squelch_cc.cc --- gnuradio-core.orig/src/lib/general/gr_squelch_cc.cc 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_squelch_cc.cc 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,250 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +//gr_squelch_cc::gr_squelch_cc (float threshold): +gr_squelch_cc::gr_squelch_cc (double sampling_freq, + float threshold, + float avg_time_fast, + float holdtime, + float unmutetime, + bool autothreshold, float avg_time_slow): +gr_sync_block ("squelch_cc", + gr_make_io_signature (1, 1, sizeof (gr_complex)), + gr_make_io_signature (1, 1, sizeof (gr_complex))), +d_threshold (threshold), +d_current_threshold (threshold), +d_avg_time_fast (avg_time_fast), +d_avg_counter_fast(0), +d_avg_time_slow (avg_time_slow), +d_avg_signal_strength_fast (0.0), +d_tmp_avg_signal_strength_fast(0.0), +d_avg_signal_strength_slow (0.0), +d_mute (true), +d_init_counter (0), +d_sampling_freq (sampling_freq), +d_holdtime (holdtime), +d_current_nholdsamples(0), +d_hold_start(false), +d_in_hold_time(false), +d_unmutetime (unmutetime), +d_autothreshold (autothreshold), +d_hold(false), +d_info_counter(0) +{ + d_avg_nsamples_fast = int(d_sampling_freq * d_avg_time_fast); + d_nholdsamples = int(d_sampling_freq* d_holdtime); + d_unmutesamples = int(d_sampling_freq * d_unmutetime); + //set_history (0); // we do not need to look at previous values +} + +gr_squelch_cc_sptr +gr_make_squelch_cc (double sampling_freq, + float treshold, + float avg_time_fast, + float holdtime, + float unmutetime, bool autothreshold, float avg_time_slow) +{ + return gr_squelch_cc_sptr (new gr_squelch_cc (sampling_freq, + treshold, + avg_time_fast, + holdtime, + unmutetime, + autothreshold, + avg_time_slow)); +} + +int +gr_squelch_cc::work (int noutput_items, + gr_vector_const_void_star & input_items, + gr_vector_void_star & output_items) +{ + gr_complex *in = (gr_complex *) input_items[0]; + gr_complex *out = (gr_complex *) output_items[0]; + size_t item_size = input_signature ()->sizeof_stream_item (0); + //size_t item_size = output_signature ()->sizeof_stream_item (0); + //fastaveragetime = frequencyofinterest / fastaverageperiods + + int tmp_avg_counter = d_avg_counter_fast; + const int tmp_avg_nsamples = d_avg_nsamples_fast; + float tmp_avg = d_tmp_avg_signal_strength_fast; + for (int i = 0; i < noutput_items; i++) + { + if (tmp_avg_counter > tmp_avg_nsamples) + { + d_info_counter++; + if(d_info_counter>1000) + { + printf ("d_avg_signal_strength_fast %f\n", d_avg_signal_strength_fast); + printf ("d_avg_signal_strength_slow %f \n", d_avg_signal_strength_slow); + printf ("d_current_threshold %f \n", d_current_threshold); + printf ("d_threshold %f \n", d_threshold); + d_info_counter=0; + } + d_avg_signal_strength_fast = + tmp_avg / tmp_avg_nsamples; + /* d_avg_signal_strength_fast = + * (9 * d_avg_signal_strength_fast + + * tmp_avg / tmp_avg_nsamples) / 10; */ + tmp_avg = 0.0; + tmp_avg_counter=0; + d_avg_counter_fast = 0; + + if (d_autothreshold) + { + if (d_init_counter < 10) + { + d_avg_signal_strength_slow = + d_avg_signal_strength_fast; + d_init_counter++; + printf ("d_init_counter = %i\n", + d_init_counter); + printf ("d_avg_signal_strength_fast = %f\n", d_avg_signal_strength_fast); + } + else + { + if (!d_mute) + { + // printf ("d_avg_signal_strength_fast signal = %f\n", d_avg_signal_strength_fast); + // printf ("d_avg_signal_strength_slow nosignal = %f \n", d_avg_signal_strength_slow); + + d_avg_signal_strength_slow = + (99999 * + d_avg_signal_strength_slow + + + d_avg_signal_strength_fast) + / 100000; + } + else + { + d_avg_signal_strength_slow = + (999 * + d_avg_signal_strength_slow + + + d_avg_signal_strength_fast) + / 1000; + } + } + d_current_threshold = d_avg_signal_strength_slow *d_threshold; + } + else + { +// if (d_avg_signal_strength_fast > d_current_threshold) +// d_mute = false; + d_current_threshold = d_threshold; + } + + break; + } +// else +// { + tmp_avg += abs (in[i]); + tmp_avg_counter++; +// } + } + d_avg_counter_fast = tmp_avg_counter; + d_tmp_avg_signal_strength_fast = tmp_avg; + + if (d_avg_signal_strength_fast > d_current_threshold) + { + d_mute = false; + d_hold = true; + } + else + { + if (!d_mute) + { + d_hold_start = true; + d_in_hold_time = true; + d_current_nholdsamples = 0; + } + d_mute = true;//can be overridden later on if d_in_hold_time + } + if (d_in_hold_time) + { + d_current_nholdsamples += noutput_items; + if (d_current_nholdsamples >= d_nholdsamples) + { + d_hold = false; + d_in_hold_time = false; + //d_mute = true; + } else + { + d_hold=true; + //d_mute=false;//override d_mute=true + } + } + if (d_mute) + { + memset (out, 0, noutput_items * item_size); //is all zeros the right bitpattern for zero complex values? + } + else + { + memcpy (out, in, noutput_items * item_size); + } + + + + + +/* float tmp_avg_signal_strength = 0.0; + for (int i = 0; i < noutput_items; i++) + { + if (d_mute) + { + out[i] = (0.0, 0.0); + } + else + { + out[i] = in[i]; + } + tmp_avg_signal_strength += abs (in[i]); + } + tmp_avg_signal_strength /= noutput_items;*/ + + + + + + return noutput_items; +} + +void +gr_squelch_cc:: set_threshold (double threshold) +{ + d_threshold=threshold; + if(d_autothreshold) + { + d_current_threshold = d_avg_signal_strength_slow *d_threshold; + } + else + { + d_current_threshold = d_threshold; + } + +} diff -u -r -N gnuradio-core.orig/src/lib/general/gr_squelch_cc.h gnuradio-core/src/lib/general/gr_squelch_cc.h --- gnuradio-core.orig/src/lib/general/gr_squelch_cc.h 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_squelch_cc.h 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,129 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef INCLUDED_GR_SQUELCH_CC_H +#define INCLUDED_GR_SQUELCH_CC_H + +#include + +class gr_squelch_cc; +typedef + boost::shared_ptr < + gr_squelch_cc > + gr_squelch_cc_sptr; +gr_squelch_cc_sptr +gr_make_squelch_cc (double sampling_freq, + float threshold, + float avg_time_fast, + float holdtime, + float unmutetime, + bool autothreshold, float avg_time_slow); + +/*! + * \brief squelch: complex in, complex out + * \ingroup block + */ +class + gr_squelch_cc: + public + gr_sync_block +{ + friend gr_squelch_cc_sptr + gr_make_squelch_cc (double sampling_freq, + float threshold, + float avg_time_fast, + float holdtime, + float unmutetime, + bool autothreshold, float avg_time_slow); + gr_squelch_cc (double sampling_freq, + float threshold, + float avg_time_fast, + float holdtime, + float unmutetime, + bool autothreshold, float avg_time_slow); + + float + d_threshold; + float + d_current_threshold; + float + d_avg_time_fast; + int + d_avg_nsamples_fast; + //int d_avg_samples_fast_counter; + int + d_avg_counter_fast; + float + d_avg_time_slow; + float + d_avg_signal_strength_fast; + float + d_tmp_avg_signal_strength_fast; + float + d_avg_signal_strength_slow; + int + d_init_counter; + double + d_sampling_freq; + float + d_holdtime; + int + d_nholdsamples; + int + d_current_nholdsamples; + + bool + d_hold_start; + bool + d_in_hold_time; + + float + d_unmutetime; + int + d_unmutesamples; + bool + d_autothreshold; + + int d_info_counter; + + public: + bool + d_mute; + bool + d_hold; + int + work (int noutput_items, + gr_vector_const_void_star & input_items, + gr_vector_void_star & output_items); + // ACCESSORS + bool get_hold() const { return d_hold; } + bool get_mute() const { return d_mute; } + double get_avg_signal_strength_fast () const { return d_avg_signal_strength_fast; } + double get_d_avg_signal_strength_slow () const { return d_avg_signal_strength_slow; } + double get_threshold () const { return d_threshold; } + double get_current_threshold () const { return d_current_threshold; } + // MANIPULATORS + void set_threshold (double threshold); + //void set_current_threshold (double current_threshold; } +}; + +#endif /* INCLUDED_GR_SQUELCH_CC_H */ diff -u -r -N gnuradio-core.orig/src/lib/general/gr_squelch_cc.i gnuradio-core/src/lib/general/gr_squelch_cc.i --- gnuradio-core.orig/src/lib/general/gr_squelch_cc.i 1970-01-01 01:00:00.000000000 +0100 +++ gnuradio-core/src/lib/general/gr_squelch_cc.i 2005-01-12 01:30:49.000000000 +0100 @@ -0,0 +1,57 @@ +/* -*- 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +GR_SWIG_BLOCK_MAGIC (gr, squelch_cc) + +gr_squelch_cc_sptr gr_make_squelch_cc ( double sampling_freq, +float threshold, +float avg_time_fast, +float holdtime, +float unmutetime, +bool autothreshold, +float avg_time_slow); + +class gr_squelch_cc : public gr_sync_block +{ + gr_squelch_cc ( double sampling_freq, +float threshold, +float avg_time_fast, +float holdtime, +float unmutetime, +bool autothreshold, +float avg_time_slow); + public: + bool + d_mute; + bool + d_hold; + // ACCESSORS + bool get_hold() const { return d_hold; } + bool get_mute() const { return d_mute; } + double get_avg_signal_strength_fast () const { return d_avg_signal_strength_fast; } + double get_d_avg_signal_strength_slow () const { return d_avg_signal_strength_slow; } + double get_threshold () const { return d_threshold; } + double get_current_threshold () const { return d_current_threshold; } + // MANIPULATORS + void set_threshold (double threshold); + //void set_current_threshold (double current_threshold; } +}; diff -u -r -N gnuradio-core.orig/src/lib/swig/Makefile.swigdeps gnuradio-core/src/lib/swig/Makefile.swigdeps --- gnuradio-core.orig/src/lib/swig/Makefile.swigdeps 2004-12-17 21:56:28.000000000 +0100 +++ gnuradio-core/src/lib/swig/Makefile.swigdeps 2005-01-12 01:30:49.000000000 +0100 @@ -19,6 +19,8 @@ ../../../src/lib/general/gr_sig_source_waveform.h \ ../../../src/lib/general/gr_noise_type.h \ ../../../src/lib/general/gr_quadrature_demod_cf.i \ + ../../../src/lib/general/gr_squelch_cc.i \ + ../../../src/lib/general/gr_abs_cf.i \ ../../../src/lib/general/gr_remez.i \ ../../../src/lib/general/gr_float_to_complex.i \ ../../../src/lib/general/gr_check_counting_s.i \ diff -u -r -N gnuradio-core.orig/src/lib/swig/gnuradio_swig_bug_workaround.h gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h --- gnuradio-core.orig/src/lib/swig/gnuradio_swig_bug_workaround.h 2004-12-17 21:56:28.000000000 +0100 +++ gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h 2005-01-12 01:30:49.000000000 +0100 @@ -29,6 +29,7 @@ * %import "gnuradio.i" */ +class gr_abs_cf; class gr_add_cc; class gr_add_const_cc; class gr_add_const_ff; @@ -112,6 +113,7 @@ class gr_sig_source_s; class gr_simple_correlator; class gr_simple_framer; +class gr_squelch_cc; class gr_sub_cc; class gr_sub_ff; class gr_sub_ii;