commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] gnuradio-core/src/lib/general Makefile.am gener...


From: Johnathan Corgan
Subject: [Commit-gnuradio] gnuradio-core/src/lib/general Makefile.am gener...
Date: Sun, 18 Jun 2006 19:20:01 +0000

CVSROOT:        /sources/gnuradio
Module name:    gnuradio-core
Changes by:     Johnathan Corgan <jcorgan>      06/06/18 19:20:01

Modified files:
        src/lib/general: Makefile.am general.i 
Added files:
        src/lib/general: gr_pwr_squelch_ff.cc gr_pwr_squelch_ff.h 
                         gr_pwr_squelch_ff.i 

Log message:
        Added gr_pwr_squelch_ff block.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/Makefile.am?cvsroot=gnuradio&r1=1.105&r2=1.106
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/general.i?cvsroot=gnuradio&r1=1.73&r2=1.74
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.cc?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.h?cvsroot=gnuradio&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnuradio-core/src/lib/general/gr_pwr_squelch_ff.i?cvsroot=gnuradio&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/Makefile.am,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -b -r1.105 -r1.106
--- Makefile.am 18 Jun 2006 06:52:46 -0000      1.105
+++ Makefile.am 18 Jun 2006 19:20:00 -0000      1.106
@@ -171,6 +171,7 @@
        gr_probe_avg_mag_sqrd_f.cc      \
        gr_probe_signal_f.cc            \
        gr_pwr_squelch_cc.cc            \
+       gr_pwr_squelch_ff.cc            \
        gr_quadrature_demod_cf.cc       \
        gr_random.cc                    \
        gr_remez.cc                     \
@@ -291,6 +292,7 @@
        gr_probe_avg_mag_sqrd_f.h       \
        gr_probe_signal_f.h             \
        gr_pwr_squelch_cc.h             \
+       gr_pwr_squelch_ff.h             \
        gr_quadrature_demod_cf.h        \
        gr_random.h                     \
        gr_remez.h                      \
@@ -411,6 +413,7 @@
        gr_probe_avg_mag_sqrd_f.i       \
        gr_probe_signal_f.i             \
        gr_pwr_squelch_cc.i             \
+       gr_pwr_squelch_ff.i             \
        gr_quadrature_demod_cf.i        \
        gr_remez.i                      \
        gr_rms_cf.i                     \

Index: general.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/general.i,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -b -r1.73 -r1.74
--- general.i   18 Jun 2006 06:52:46 -0000      1.73
+++ general.i   18 Jun 2006 19:20:00 -0000      1.74
@@ -107,6 +107,7 @@
 #include <gr_map_bb.h>
 #include <gr_feval.h>
 #include <gr_pwr_squelch_cc.h>
+#include <gr_pwr_squelch_ff.h>
 
 %}
 
@@ -196,5 +197,6 @@
 %include "gr_map_bb.i"
 %include "gr_feval.i"
 %include "gr_pwr_squelch_cc.i"
+%include "gr_pwr_squelch_ff.i"
 
 %include "general_generated.i"

Index: gr_pwr_squelch_ff.cc
===================================================================
RCS file: gr_pwr_squelch_ff.cc
diff -N gr_pwr_squelch_ff.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_pwr_squelch_ff.cc        18 Jun 2006 19:20:00 -0000      1.1
@@ -0,0 +1,148 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006 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 <cmath>
+#include <gr_pwr_squelch_ff.h>
+#include <gr_io_signature.h>
+
+gr_pwr_squelch_ff_sptr
+gr_make_pwr_squelch_ff(double threshold, double alpha, int ramp, bool gate)
+{
+  return gr_pwr_squelch_ff_sptr(new gr_pwr_squelch_ff(threshold, alpha, ramp, 
gate));
+}
+
+gr_pwr_squelch_ff::gr_pwr_squelch_ff(double threshold, double alpha, int ramp, 
bool gate) : 
+       gr_block("pwr_squelch_ff",
+       gr_make_io_signature (1, 1, sizeof(float)),
+       gr_make_io_signature (1, 1, sizeof(float))),
+       d_iir(alpha)
+{
+  set_threshold(threshold);
+  set_ramp(ramp);
+  set_gate(gate);
+  d_state = ST_MUTED;
+  d_envelope = d_ramp ? 0.0 : 1.0;
+  d_ramped = 0;
+}
+
+gr_pwr_squelch_ff::~gr_pwr_squelch_ff()
+{
+}
+
+double gr_pwr_squelch_ff::threshold() const
+{
+  return 10*log10(d_threshold);
+}
+
+void gr_pwr_squelch_ff::set_threshold(double db)
+{
+  d_threshold = std::pow(10.0, db/10);
+}
+
+void gr_pwr_squelch_ff::set_alpha(double alpha)
+{
+  d_iir.set_taps(alpha);
+}
+
+void gr_pwr_squelch_ff::set_gate(bool gate)
+{
+  d_gate = gate;
+}
+
+void gr_pwr_squelch_ff::set_ramp(int ramp)
+{
+  d_ramp = ramp;
+}  
+
+bool gr_pwr_squelch_ff::unmuted() const
+{
+  return (d_state == ST_UNMUTED || d_state == ST_ATTACK);
+}
+
+std::vector<float> gr_pwr_squelch_ff::squelch_range() const
+{
+  std::vector<float> r(3);
+  r[0] = -50.0;                                // min  FIXME
+  r[1] = +50.0;                                // max  FIXME
+  r[2] = (r[1] - r[0]) / 100;          // step size
+
+  return r;
+}
+
+int gr_pwr_squelch_ff::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];
+  float *out = (float *) output_items[0];
+
+  int j = 0;
+
+  for (int i = 0; i < noutput_items; i++) {
+    // Calculate average power
+    double mag_sqrd = in[i]*in[i];
+    double f = d_iir.filter(mag_sqrd);
+
+    // Update squelch state based on power vs. threshold
+    switch(d_state) {
+      case ST_MUTED:
+        if (f >= d_threshold) 
+          d_state = d_ramp ? ST_ATTACK : ST_UNMUTED; // If not ramping, go 
straight to unmuted
+        break;
+
+      case ST_UNMUTED:
+        if (f < d_threshold)
+          d_state = d_ramp ? ST_DECAY : ST_MUTED;    // If not ramping, go 
straight to muted
+        break;
+
+      case ST_ATTACK:
+        d_envelope = 0.5-std::cos(M_PI*(++d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
+        if (d_ramped >= d_ramp) {                    // use >= in case d_ramp 
is set to lower value elsewhere
+         d_state = ST_UNMUTED;
+         d_envelope = 1.0;
+        }
+        break;
+
+      case ST_DECAY:
+        d_envelope = 0.5-std::cos(M_PI*(--d_ramped)/d_ramp)/2.0; // FIXME: 
precalculate window for speed
+        if (d_ramped == 0)
+         d_state = ST_MUTED;
+        break;
+    };
+       
+    // If unmuted, copy input times envelope to output
+    // Otherwise, if not gating, copy zero to output
+    if (d_state != ST_MUTED)
+      out[j++] = in[i]*d_envelope;
+    else
+      if (!d_gate)
+          out[j++] = 0.0;
+  }
+
+  consume_each(noutput_items);  // Use all the inputs
+  return j;                    // But only report outputs copied
+}

Index: gr_pwr_squelch_ff.h
===================================================================
RCS file: gr_pwr_squelch_ff.h
diff -N gr_pwr_squelch_ff.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_pwr_squelch_ff.h 18 Jun 2006 19:20:00 -0000      1.1
@@ -0,0 +1,78 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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_PWR_SQUELCH_FF_H
+#define INCLUDED_GR_PWR_SQUELCH_FF_H
+
+#include <gr_block.h>
+#include <gr_single_pole_iir.h>
+
+class gr_pwr_squelch_ff;
+typedef boost::shared_ptr<gr_pwr_squelch_ff> gr_pwr_squelch_ff_sptr;
+
+gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double alpha = 
0.0001, int ramp=0, bool gate=false);
+
+/*!
+ * \brief gate or zero output when input power below threshold
+ * \ingroup block
+ */
+class gr_pwr_squelch_ff : public gr_block
+{
+  enum state_t { ST_MUTED, ST_ATTACK, ST_UNMUTED, ST_DECAY };
+
+  double                                  d_threshold;
+  int                                     d_ramp;
+  bool                                    d_gate;
+
+  gr_single_pole_iir<double,double,double> d_iir;
+  state_t                                 d_state;
+  int                                     d_ramped;
+  double                                  d_envelope;
+
+  friend gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double 
alpha, int ramp, bool gate);
+  gr_pwr_squelch_ff(double db, double alpha, int ramp, bool gate);
+  
+ public:
+  ~gr_pwr_squelch_ff();
+
+  double threshold() const;
+  void set_threshold(double db);
+
+  void set_alpha(double alpha);
+
+  int ramp() const { return d_ramp; }
+  void set_ramp(int ramp);
+
+  bool gate() const { return d_gate; }
+  void set_gate(bool gate);
+
+  bool unmuted() const;
+
+  std::vector<float> squelch_range() const;
+
+  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_PWR_SQUELCH_FF_H */

Index: gr_pwr_squelch_ff.i
===================================================================
RCS file: gr_pwr_squelch_ff.i
diff -N gr_pwr_squelch_ff.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gr_pwr_squelch_ff.i 18 Jun 2006 19:20:00 -0000      1.1
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 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,pwr_squelch_ff);
+
+gr_pwr_squelch_ff_sptr gr_make_pwr_squelch_ff(double db, double alpha=0.0001, 
int ramp=0, bool gate=false);
+
+class gr_pwr_squelch_ff : public gr_block
+{
+ private:
+  gr_pwr_squelch_ff(double db, double alpha, int ramp, bool gate);
+
+ public:
+  double threshold() const;
+  void set_threshold(double db);
+
+  void set_alpha(double alpha);
+
+  int ramp() const { return d_ramp; }
+  void set_ramp(int ramp);
+
+  bool gate() const { return d_gate; }
+  void set_gate(bool gate);
+
+  bool unmuted() const;
+
+  std::vector<float> squelch_range() const;
+};




reply via email to

[Prev in Thread] Current Thread [Next in Thread]