discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] patch to add complex implementations of agc and singl


From: Martin Dvh
Subject: [Discuss-gnuradio] patch to add complex implementations of agc and single pole iir filter
Date: Wed, 01 Feb 2006 23:32:06 +0100
User-agent: Debian Thunderbird 1.0.2 (X11/20051002)

I implemented complex versions of agc and single pole iir filter.
To do this I had add an extra calc_type parameter to the gr_single_pole_iir 
template.
(I changed all blocks that use this accordingly)
If this extra parameter is not wanted I could still implement a complex iir 
filter but then I am forced to use also a complex value for the tap.
Which is not quite intuitive, and also has a higher computational load as 
result.

I also added a qa_single_pole_iir_cc.py (which succeeds, just as 
qa_single_pole_iir.py still succeeds)

I hope this can go into the tree but I am open for feedback on this.

Changelog below and attached is the diff against cvs.

Greetings,
Martin


2006-02-01  Martin Dudok van Heel <nldudok1 at olifantasia.com>

        Addded complex implementations of agc and single pole iir filter.
        new blocks gr_agc_cc, gr_single_pole_iir_filter_cc
        new gri_agc_cc qa_single_pole_iir_cc.py

        The template in gr_single_pole_iir.h got an extra parameter for 
calc_type.
        Previously tap_type was used for the temporary variables in the 
calculations.
        For complex calculations this is a no_go if you use double taps so you 
now have seperate types for tap and calc.
        You can now instantiate like 
gr_single_pole_iir<gr_complex,gr_complex,double,gr_complexd>
        input values are complex
        output values are complex
        tap values are double
        calculations are done using complex double temporary variables
        For non-complex instantiations you can just copy the tap type to the 
calc_type.

        * src/lib/atsc/GrAtscBitTimingLoop.h: changed to use new calc_type 
parameter in gr_single_pole_iir instantiation
        * src/lib/atsc/GrAtscBitTimingLoop2.h: changed to use new calc_type 
parameter in gr_single_pole_iir instantiation
        * src/lib/atsc/GrAtscFPLL.h: changed to use new calc_type parameter in 
gr_single_pole_iir instantiation
        * src/lib/atsc/atsc_slicer_agc.h: changed to use new calc_type 
parameter in gr_single_pole_iir instantiation
        * src/lib/filter/GrRemoveDcFFF.h: changed to use new calc_type 
parameter in gr_single_pole_iir instantiation
        * src/lib/filter/Makefile.am: changed, added 
gr_single_pole_iir_filter_cc.*
        * src/lib/filter/filter.i: changed, added gr_single_pole_iir_filter_cc.*
        * src/lib/filter/gr_single_pole_iir.h: changed, added new calc_type 
parameter to gr_single_pole_iir template
        * src/lib/filter/gr_single_pole_iir_filter_cc.cc: new
        * src/lib/filter/gr_single_pole_iir_filter_cc.h: new
        * src/lib/filter/gr_single_pole_iir_filter_cc.i: new
        * src/lib/filter/gr_single_pole_iir_filter_ff.h: changed to use new 
calc_type parameter in gr_single_pole_iir instantiation
        * src/lib/general/Makefile.am: changed, added gr_agc_cc.* and 
gri_agc_cc.*
        * src/lib/general/general.i: changed, added gr_agc_cc.* and gri_agc_cc.*
        * src/lib/general/gr_agc_cc.cc: new
        * src/lib/general/gr_agc_cc.h: new
        * src/lib/general/gr_agc_cc.i: new
        * src/lib/general/gr_probe_avg_mag_sqrd_c.h: changed to use new 
calc_type parameter in gr_single_pole_iir instantiation
        * src/lib/general/gr_probe_avg_mag_sqrd_f.h: changed to use new 
calc_type parameter in gr_single_pole_iir instantiation
        * src/lib/general/gr_rms_cf.h: changed to use new calc_type parameter 
in gr_single_pole_iir instantiation
        * src/lib/general/gr_rms_ff.h: changed to use new calc_type parameter 
in gr_single_pole_iir instantiation
        * src/lib/general/gr_simple_squelch_cc.h: changed to use new calc_type 
parameter in gr_single_pole_iir instantiation
        * src/lib/general/gri_agc_cc.h: new
        * src/lib/general/gri_agc_cc.i: new
        * src/python/gnuradio/gr/Makefile.am: changed, added 
qa_single_pole_iir_cc.py
        * src/python/gnuradio/gr/qa_single_pole_iir_cc.py: new
Index: src/lib/atsc/GrAtscBitTimingLoop.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/atsc/GrAtscBitTimingLoop.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 GrAtscBitTimingLoop.h
--- src/lib/atsc/GrAtscBitTimingLoop.h  10 Apr 2004 17:59:51 -0000      1.1.1.1
+++ src/lib/atsc/GrAtscBitTimingLoop.h  1 Feb 2006 21:56:43 -0000
@@ -75,7 +75,7 @@
   double                               w;              // timing control word
   double                               mu;             // fractional delay
   iType                                        last_right;     // last right 
hand sample
-  gr_single_pole_iir<double,double,double>     loop;
+  gr_single_pole_iir<double,double,double,double>      loop;
   bool                                 debug_no_update;// debug
 
   double                               d_loop_filter_tap;
Index: src/lib/atsc/GrAtscBitTimingLoop2.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/atsc/GrAtscBitTimingLoop2.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 GrAtscBitTimingLoop2.h
--- src/lib/atsc/GrAtscBitTimingLoop2.h 10 Apr 2004 17:59:51 -0000      1.1.1.1
+++ src/lib/atsc/GrAtscBitTimingLoop2.h 1 Feb 2006 21:56:43 -0000
@@ -69,7 +69,7 @@
   float filter_error (float e);
 
   VrSampleIndex                                next_input;
-  gr_single_pole_iir<float,float,float>        dc;             // used to 
estimate DC component
+  gr_single_pole_iir<float,float,float,float>  dc;             // used to 
estimate DC component
   gr_mmse_fir_interpolator             intr;
   float                                        mu;             // fractional 
delay
   iType                                        last_right;     // last right 
hand sample
Index: src/lib/atsc/GrAtscFPLL.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/atsc/GrAtscFPLL.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 GrAtscFPLL.h
--- src/lib/atsc/GrAtscFPLL.h   10 Apr 2004 17:59:53 -0000      1.1.1.1
+++ src/lib/atsc/GrAtscFPLL.h   1 Feb 2006 21:56:43 -0000
@@ -75,8 +75,8 @@
   bool                         debug_no_update;
   gr_nco<float,float>          nco;
   gr_agc                       agc;    // automatic gain control
-  gr_single_pole_iir<float,float,float>        afci;
-  gr_single_pole_iir<float,float,float>        afcq;
+  gr_single_pole_iir<float,float,float,float>  afci;
+  gr_single_pole_iir<float,float,float,float>  afcq;
   
 #ifdef _FPLL_DIAG_OUTPUT_
   FILE                         *fp;
Index: src/lib/atsc/atsc_slicer_agc.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/atsc/atsc_slicer_agc.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 atsc_slicer_agc.h
--- src/lib/atsc/atsc_slicer_agc.h      10 Apr 2004 18:00:09 -0000      1.1.1.1
+++ src/lib/atsc/atsc_slicer_agc.h      1 Feb 2006 21:56:43 -0000
@@ -62,7 +62,7 @@
   static const float                   REFERENCE = 1.25;       // pilot 
reference value
   static const float                   RATE = 1.0e-5;          // adjustment 
rate
   float                                        _gain;                  // 
current gain
-  gr_single_pole_iir<float,float,float>        dc;
+  gr_single_pole_iir<float,float,float,float>  dc;
 };
 
 #endif /* _ATSC_SLICER_AGC_H_ */
Index: src/lib/filter/GrRemoveDcFFF.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/GrRemoveDcFFF.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 GrRemoveDcFFF.h
--- src/lib/filter/GrRemoveDcFFF.h      10 Apr 2004 18:00:15 -0000      1.1.1.1
+++ src/lib/filter/GrRemoveDcFFF.h      1 Feb 2006 21:56:43 -0000
@@ -44,7 +44,7 @@
                    VrSampleRange inputs[], void *i[]);
 
  protected:
-  gr_single_pole_iir<float,float,float>        d_iir;
+  gr_single_pole_iir<float,float,float,float>  d_iir;
 };
 
 #endif /* _GRREMOVEDCFFF_H_ */
Index: src/lib/filter/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/Makefile.am,v
retrieving revision 1.30
diff -u -r1.30 Makefile.am
--- src/lib/filter/Makefile.am  25 Jan 2006 21:24:14 -0000      1.30
+++ src/lib/filter/Makefile.am  1 Feb 2006 21:56:43 -0000
@@ -178,6 +178,7 @@
        gr_single_pole_rec_filter_ff.cc \
        gr_single_zero_avg_filter_ff.cc \
        gr_single_zero_rec_filter_ff.cc \
+       gr_single_pole_iir_filter_cc.cc \
        gri_mmse_fir_interpolator.cc    \
        gri_mmse_fir_interpolator_cc.cc \
        complex_dotprod_generic.cc      \
@@ -235,6 +236,7 @@
        gr_single_pole_rec_filter_ff.h  \
        gr_single_zero_avg_filter_ff.h  \
        gr_single_zero_rec_filter_ff.h  \
+       gr_single_pole_iir_filter_cc.h  \
        gr_single_zero_avg.h            \
        gr_single_zero_rec.h            \
        gri_iir.h                       \
@@ -285,7 +287,8 @@
        gr_single_pole_avg_filter_ff.i  \
        gr_single_pole_rec_filter_ff.i  \
        gr_single_zero_avg_filter_ff.i  \
-       gr_single_zero_rec_filter_ff.i  
+       gr_single_zero_rec_filter_ff.i  \
+       gr_single_pole_iir_filter_cc.i  
 
        $(GENERATED_I)
 
Index: src/lib/filter/filter.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/filter.i,v
retrieving revision 1.7
diff -u -r1.7 filter.i
--- src/lib/filter/filter.i     20 Jul 2005 05:34:17 -0000      1.7
+++ src/lib/filter/filter.i     1 Feb 2006 21:56:43 -0000
@@ -23,6 +23,7 @@
 %{
 #include <gr_iir_filter_ffd.h>
 #include <gr_single_pole_iir_filter_ff.h>
+#include <gr_single_pole_iir_filter_cc.h>
 #include <gr_hilbert_fc.h>
 #include <gr_filter_delay_fc.h>
 #include <gr_fft_filter_ccc.h>
@@ -31,6 +32,7 @@
 
 %include "gr_iir_filter_ffd.i"
 %include "gr_single_pole_iir_filter_ff.i"
+%include "gr_single_pole_iir_filter_cc.i"
 %include "gr_hilbert_fc.i"
 %include "gr_filter_delay_fc.i"
 %include "gr_fft_filter_ccc.i"
Index: src/lib/filter/gr_single_pole_iir.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/filter/gr_single_pole_iir.h,v
retrieving revision 1.2
diff -u -r1.2 gr_single_pole_iir.h
--- src/lib/filter/gr_single_pole_iir.h 23 Feb 2005 07:49:28 -0000      1.2
+++ src/lib/filter/gr_single_pole_iir.h 1 Feb 2006 21:56:44 -0000
@@ -23,11 +23,10 @@
 #define _GR_SINGLE_POLE_IIR_H_
 
 #include <stdexcept>
-
 /*!
  * \brief class template for single pole IIR filter
  */
-template<class o_type, class i_type, class tap_type> 
+template<class o_type, class i_type, class tap_type,class calc_type> 
 class gr_single_pole_iir {
 public:
   /*!
@@ -71,34 +70,34 @@
     d_prev_output = 0;
   }
 
-  tap_type prev_output () { return d_prev_output; }
+  calc_type prev_output () { return d_prev_output; }
     
 protected:
   tap_type     d_alpha;
   tap_type     d_one_minus_alpha;
-  tap_type     d_prev_output;
+  calc_type    d_prev_output;
 };
 
 
 //
 // general case.  We may want to specialize this
 //
-template<class o_type, class i_type, class tap_type> 
+template<class o_type, class i_type, class tap_type, class calc_type> 
 o_type
-gr_single_pole_iir<o_type, i_type, tap_type>::filter (const i_type input)
+gr_single_pole_iir<o_type, i_type, tap_type, calc_type>::filter (const i_type 
input)
 {
-  tap_type     output;
+  calc_type    output;
 
-  output = d_alpha * input + d_one_minus_alpha * d_prev_output;
+  output = d_alpha * (calc_type)input + d_one_minus_alpha * d_prev_output;
   d_prev_output = output;
 
   return (o_type) output;
 }
 
 
-template<class o_type, class i_type, class tap_type> 
+template<class o_type, class i_type, class tap_type, class calc_type> 
 void 
-gr_single_pole_iir<o_type, i_type, tap_type>::filterN (o_type output[],
+gr_single_pole_iir<o_type, i_type, tap_type, calc_type>::filterN (o_type 
output[],
                                                       const i_type input[],
                                                       unsigned long n)
 {
Index: src/lib/filter/gr_single_pole_iir_filter_cc.cc
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.cc
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.cc      1 Feb 2006 21:56:44 
-0000
@@ -0,0 +1,81 @@
+/* -*- 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 <gr_single_pole_iir_filter_cc.h>
+#include <gr_io_signature.h>
+#include <stdio.h>
+
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen)
+{
+  return gr_single_pole_iir_filter_cc_sptr(new 
gr_single_pole_iir_filter_cc(alpha, vlen));
+}
+
+gr_single_pole_iir_filter_cc::gr_single_pole_iir_filter_cc (
+                                   double alpha, unsigned int vlen)
+  : gr_sync_block ("single_pole_iir_filter_cc",
+                  gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
+                  gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen)),
+    d_vlen(vlen), d_iir(vlen)
+{
+  set_taps(alpha);
+}
+
+gr_single_pole_iir_filter_cc::~gr_single_pole_iir_filter_cc ()
+{
+  // nop
+}
+
+void
+gr_single_pole_iir_filter_cc::set_taps (double alpha)
+{
+  for (unsigned int i = 0; i < d_vlen; i++)
+    d_iir[i].set_taps(alpha);
+}
+
+int
+gr_single_pole_iir_filter_cc::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];
+  gr_complex *out = (gr_complex *) output_items[0];
+  unsigned int vlen = d_vlen;
+
+  if (d_vlen == 1){
+    for (int i = 0; i < noutput_items; i++)
+      out[i] = d_iir[0].filter (in[i]);
+  }
+  else {
+    for (int i = 0; i < noutput_items; i++){
+      for (unsigned int j = 0; j < vlen; j++){
+       *out++ = d_iir[j].filter (*in++);
+      }
+    }
+  }
+  return noutput_items;
+};
Index: src/lib/filter/gr_single_pole_iir_filter_cc.h
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.h
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.h       1 Feb 2006 21:56:44 
-0000
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2005 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_SINGLE_POLE_IIR_FILTER_CC_H
+#define        INCLUDED_GR_SINGLE_POLE_IIR_FILTER_CC_H
+
+#include <gr_sync_block.h>
+#include <gr_single_pole_iir.h>
+#include <gr_complex.h>
+#include <stdexcept>
+
+class gr_single_pole_iir_filter_cc;
+typedef boost::shared_ptr<gr_single_pole_iir_filter_cc> 
gr_single_pole_iir_filter_cc_sptr;
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen=1);
+
+/*!
+ * \brief  single pole IIR filter with complex input, complex output
+ * \ingroup filter
+ *
+ * The input and output satisfy a difference equation of the form
+
+ \f[
+ y[n] - (1-alpha) y[n-1] = alpha x[n]
+ \f]
+
+ * with the corresponding rational system function
+
+ \f[
+ H(z) = \frac{alpha}{1 - (1-alpha) z^{-1}}
+ \f]
+
+ * Note that some texts define the system function with a + in the denominator.
+ * If you're using that convention, you'll need to negate the feedback tap.
+ */
+class gr_single_pole_iir_filter_cc : public gr_sync_block
+{
+ private:
+  friend gr_single_pole_iir_filter_cc_sptr 
+  gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen);
+
+  unsigned int                                         d_vlen;
+  std::vector<gr_single_pole_iir<gr_complex,gr_complex,double,gr_complexd> >   
d_iir;
+
+  gr_single_pole_iir_filter_cc (double alpha, unsigned int vlen);
+
+ public:
+  ~gr_single_pole_iir_filter_cc ();
+
+  void set_taps (double alpha);
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif
Index: src/lib/filter/gr_single_pole_iir_filter_cc.i
===================================================================
RCS file: src/lib/filter/gr_single_pole_iir_filter_cc.i
diff -N src/lib/filter/gr_single_pole_iir_filter_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/filter/gr_single_pole_iir_filter_cc.i       1 Feb 2006 21:56:44 
-0000
@@ -0,0 +1,34 @@
+/* -*- 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,single_pole_iir_filter_cc);
+
+gr_single_pole_iir_filter_cc_sptr 
+gr_make_single_pole_iir_filter_cc (double alpha, unsigned int vlen=1);
+
+class gr_single_pole_iir_filter_cc : public gr_sync_block
+{
+ public:
+  ~gr_single_pole_iir_filter_cc ();
+
+  void set_taps (double alpha);
+};
Index: src/lib/filter/gr_single_pole_iir_filter_ff.h
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/filter/gr_single_pole_iir_filter_ff.h,v
retrieving revision 1.1
diff -u -r1.1 gr_single_pole_iir_filter_ff.h
--- src/lib/filter/gr_single_pole_iir_filter_ff.h       15 Mar 2005 07:06:16 
-0000      1.1
+++ src/lib/filter/gr_single_pole_iir_filter_ff.h       1 Feb 2006 21:56:44 
-0000
@@ -59,7 +59,7 @@
   gr_make_single_pole_iir_filter_ff (double alpha, unsigned int vlen);
 
   unsigned int                                         d_vlen;
-  std::vector<gr_single_pole_iir<float,float,double> > d_iir;
+  std::vector<gr_single_pole_iir<float,float,double,double> >  d_iir;
 
   gr_single_pole_iir_filter_ff (double alpha, unsigned int vlen);
 
Index: src/lib/general/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/Makefile.am,v
retrieving revision 1.73
diff -u -r1.73 Makefile.am
--- src/lib/general/Makefile.am 29 Dec 2005 10:40:51 -0000      1.73
+++ src/lib/general/Makefile.am 1 Feb 2006 21:56:44 -0000
@@ -154,6 +154,7 @@
        gr_simple_correlator.cc         \
        gr_simple_squelch_cc.cc         \
        gr_agc_ff.cc                \
+       gr_agc_cc.cc                \
        gr_stream_to_streams.cc         \
        gr_streams_to_stream.cc         \
        gr_streams_to_vector.cc         \
@@ -194,6 +195,7 @@
        $(GENERATED_H)                  \
        malloc16.h                      \
        gri_agc.h                       \
+       gri_agc_cc.h                    \
        gr_align_on_samplenumbers_ss.h          \
        gr_bytes_to_syms.h              \
        gr_check_counting_s.h           \
@@ -255,6 +257,7 @@
        gr_simple_framer_sync.h         \
        gr_simple_squelch_cc.h          \
        gr_agc_ff.h                 \
+       gr_agc_cc.h                 \
        gr_stream_to_streams.h          \
        gr_streams_to_stream.h          \
        gr_streams_to_vector.h          \
@@ -344,7 +347,9 @@
        gr_simple_framer.i              \
        gr_simple_squelch_cc.i          \
        gri_agc.i                 \
+       gri_agc_cc.i                 \
        gr_agc_ff.i                 \
+       gr_agc_cc.i                 \
        gr_stream_to_streams.i          \
        gr_streams_to_stream.i          \
        gr_streams_to_vector.i          \
Index: src/lib/general/general.i
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/general.i,v
retrieving revision 1.45
diff -u -r1.45 general.i
--- src/lib/general/general.i   29 Dec 2005 10:40:51 -0000      1.45
+++ src/lib/general/general.i   1 Feb 2006 21:56:44 -0000
@@ -61,6 +61,7 @@
 #include <gr_deinterleave.h>
 #include <gr_simple_squelch_cc.h>
 #include <gr_agc_ff.h>
+#include <gr_agc_cc.h>
 #include <gr_rms_cf.h>
 #include <gr_rms_ff.h>
 #include <gr_nlog10_ff.h>
@@ -127,6 +128,7 @@
 %include "gr_deinterleave.i"
 %include "gr_simple_squelch_cc.i"
 %include "gr_agc_ff.i"
+%include "gr_agc_cc.i"
 %include "gr_rms_cf.i"
 %include "gr_rms_ff.i"
 %include "gr_nlog10_ff.i"
Index: src/lib/general/gr_agc_cc.cc
===================================================================
RCS file: src/lib/general/gr_agc_cc.cc
diff -N src/lib/general/gr_agc_cc.cc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.cc        1 Feb 2006 21:56:44 -0000
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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 <gr_agc_cc.h>
+#include <gr_io_signature.h>
+#include <gri_agc_cc.h>
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate, float reference, float gain)
+{
+  return gr_agc_cc_sptr (new gr_agc_cc (rate, reference, gain));
+}
+
+gr_agc_cc::gr_agc_cc (float rate, float reference, float gain)
+  : gr_sync_block ("gr_agc_cc",
+                  gr_make_io_signature (1, 1, sizeof (gr_complex)),
+                  gr_make_io_signature (1, 1, sizeof (gr_complex)))
+  , gri_agc_cc (rate,  reference, gain)
+{
+}
+
+int
+gr_agc_cc::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];
+  gr_complex *out = (gr_complex *) output_items[0];
+  scaleN (out, in, noutput_items);
+  return noutput_items;
+}
Index: src/lib/general/gr_agc_cc.h
===================================================================
RCS file: src/lib/general/gr_agc_cc.h
diff -N src/lib/general/gr_agc_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.h 1 Feb 2006 21:56:44 -0000
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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_AGC_CC_H
+#define INCLUDED_GR_AGC_CC_H
+
+#include <gr_sync_block.h>
+#include <gri_agc_cc.h>
+class gr_agc_cc;
+typedef boost::shared_ptr<gr_agc_cc> gr_agc_cc_sptr;
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+class gr_agc_cc : public gr_sync_block, public gri_agc_cc
+{
+  friend gr_agc_cc_sptr gr_make_agc_cc (float rate, float reference, float 
gain);
+  gr_agc_cc (float rate, float reference, float gain);
+
+ public:
+  virtual int work (int noutput_items,
+                   gr_vector_const_void_star &input_items,
+                   gr_vector_void_star &output_items);
+};
+
+
+#endif /* INCLUDED_GR_AGC_CC_H */
Index: src/lib/general/gr_agc_cc.i
===================================================================
RCS file: src/lib/general/gr_agc_cc.i
diff -N src/lib/general/gr_agc_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gr_agc_cc.i 1 Feb 2006 21:56:44 -0000
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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,agc_cc)
+
+%include <gri_agc_cc.i>
+
+gr_agc_cc_sptr
+gr_make_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+
+class gr_agc_cc : public gr_sync_block , public gri_agc_cc
+{
+  gr_agc_cc (float rate, float reference, float gain);
+};
Index: src/lib/general/gr_probe_avg_mag_sqrd_c.h
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_c.h,v
retrieving revision 1.1
diff -u -r1.1 gr_probe_avg_mag_sqrd_c.h
--- src/lib/general/gr_probe_avg_mag_sqrd_c.h   7 Dec 2005 22:30:07 -0000       
1.1
+++ src/lib/general/gr_probe_avg_mag_sqrd_c.h   1 Feb 2006 21:56:44 -0000
@@ -44,7 +44,7 @@
 class gr_probe_avg_mag_sqrd_c : public gr_sync_block
 {
   double                                       d_threshold;
-  gr_single_pole_iir<double,double,double>     d_iir;
+  gr_single_pole_iir<double,double,double,double>      d_iir;
   bool                                         d_unmuted;
   double                                       d_level;
 
Index: src/lib/general/gr_probe_avg_mag_sqrd_f.h
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_probe_avg_mag_sqrd_f.h,v
retrieving revision 1.1
diff -u -r1.1 gr_probe_avg_mag_sqrd_f.h
--- src/lib/general/gr_probe_avg_mag_sqrd_f.h   7 Dec 2005 22:30:07 -0000       
1.1
+++ src/lib/general/gr_probe_avg_mag_sqrd_f.h   1 Feb 2006 21:56:44 -0000
@@ -44,7 +44,7 @@
 class gr_probe_avg_mag_sqrd_f : public gr_sync_block
 {
   double                                       d_threshold;
-  gr_single_pole_iir<double,double,double>     d_iir;
+  gr_single_pole_iir<double,double,double,double>      d_iir;
   bool                                         d_unmuted;
   double                                       d_level;
 
Index: src/lib/general/gr_rms_cf.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_rms_cf.h,v
retrieving revision 1.1
diff -u -r1.1 gr_rms_cf.h
--- src/lib/general/gr_rms_cf.h 25 Feb 2005 22:00:51 -0000      1.1
+++ src/lib/general/gr_rms_cf.h 1 Feb 2006 21:56:44 -0000
@@ -36,7 +36,7 @@
  */
 class gr_rms_cf : public gr_sync_block
 {
-  gr_single_pole_iir<double,double,double>     d_iir;
+  gr_single_pole_iir<double,double,double,double>      d_iir;
   bool                                         d_unmuted;
 
   friend gr_rms_cf_sptr
Index: src/lib/general/gr_rms_ff.h
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/lib/general/gr_rms_ff.h,v
retrieving revision 1.1
diff -u -r1.1 gr_rms_ff.h
--- src/lib/general/gr_rms_ff.h 25 Feb 2005 22:00:51 -0000      1.1
+++ src/lib/general/gr_rms_ff.h 1 Feb 2006 21:56:44 -0000
@@ -36,7 +36,7 @@
  */
 class gr_rms_ff : public gr_sync_block
 {
-  gr_single_pole_iir<double,double,double>     d_iir;
+  gr_single_pole_iir<double,double,double,double>      d_iir;
   bool                                         d_unmuted;
 
   friend gr_rms_ff_sptr
Index: src/lib/general/gr_simple_squelch_cc.h
===================================================================
RCS file: 
/sources/gnuradio/gnuradio-core/src/lib/general/gr_simple_squelch_cc.h,v
retrieving revision 1.1
diff -u -r1.1 gr_simple_squelch_cc.h
--- src/lib/general/gr_simple_squelch_cc.h      23 Feb 2005 07:49:28 -0000      
1.1
+++ src/lib/general/gr_simple_squelch_cc.h      1 Feb 2006 21:56:44 -0000
@@ -37,7 +37,7 @@
 class gr_simple_squelch_cc : public gr_sync_block
 {
   double                                       d_threshold;
-  gr_single_pole_iir<double,double,double>     d_iir;
+  gr_single_pole_iir<double,double,double,double>      d_iir;
   bool                                         d_unmuted;
 
   friend gr_simple_squelch_cc_sptr
Index: src/lib/general/gri_agc_cc.h
===================================================================
RCS file: src/lib/general/gri_agc_cc.h
diff -N src/lib/general/gri_agc_cc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gri_agc_cc.h        1 Feb 2006 21:56:44 -0000
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 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 _GRI_AGC_CC_H_
+#define _GRI_AGC_CC_H_
+
+#include <math.h>
+
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+class gri_agc_cc {
+
+ public:
+  gri_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0)
+    : _rate(rate), _reference(reference), _gain(gain) {};
+
+  float rate () const      { return _rate; }
+  float reference () const { return _reference; }
+  float gain () const     { return _gain;  }
+
+  void set_rate (float rate) { _rate = rate; }
+  void set_reference (float reference) { _reference = reference; }
+  void set_gain (float gain) { _gain = gain; }
+
+  gr_complex scale (gr_complex input){
+    gr_complex output = input * _gain;
+    _gain += (_reference - 
sqrt(output.real()*output.real()+output.imag()*output.imag())) * _rate;//use 
abs or cabs to get approximation by absolute value, 
+                                                 //note that abs is 
computationally more intensive then norm for a complex number
+    return output;
+  }
+
+  void scaleN (gr_complex output[], const gr_complex input[], unsigned n){
+    for (unsigned i = 0; i < n; i++)
+      output[i] = scale (input[i]);
+  }
+  
+ protected:
+  float _rate;                 // adjustment rate
+  float        _reference;             // reference value
+  float        _gain;                  // current gain
+};
+
+#endif /* _GRI_AGC_CC_H_ */
Index: src/lib/general/gri_agc_cc.i
===================================================================
RCS file: src/lib/general/gri_agc_cc.i
diff -N src/lib/general/gri_agc_cc.i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/lib/general/gri_agc_cc.i        1 Feb 2006 21:56:44 -0000
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 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.
+ */
+
+#include <math.h>
+
+/*!
+ * \brief high performance Automatic Gain Control class
+ *
+ * For Power the absolute value of the complex number is used.
+ */
+
+
+class gri_agc_cc {
+
+ public:
+  gri_agc_cc (float rate = 1e-4, float reference = 1.0, float gain = 1.0);
+  float rate ();
+  float reference ();
+  float gain ();
+  };
Index: src/python/gnuradio/gr/Makefile.am
===================================================================
RCS file: /sources/gnuradio/gnuradio-core/src/python/gnuradio/gr/Makefile.am,v
retrieving revision 1.29
diff -u -r1.29 Makefile.am
--- src/python/gnuradio/gr/Makefile.am  6 Oct 2005 02:39:18 -0000       1.29
+++ src/python/gnuradio/gr/Makefile.am  1 Feb 2006 21:56:44 -0000
@@ -62,6 +62,7 @@
        qa_pipe_fittings.py             \
        qa_rational_resampler.py        \
        qa_sig_source.py                \
-       qa_single_pole_iir.py           
+       qa_single_pole_iir.py           \       
+       qa_single_pole_iir_cc.py                
 
 CLEANFILES = *.pyc
Index: src/python/gnuradio/gr/qa_single_pole_iir_cc.py
===================================================================
RCS file: src/python/gnuradio/gr/qa_single_pole_iir_cc.py
diff -N src/python/gnuradio/gr/qa_single_pole_iir_cc.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/python/gnuradio/gr/qa_single_pole_iir_cc.py     1 Feb 2006 21:56:44 
-0000
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# Copyright 2005 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.
+# 
+
+from gnuradio import gr, gr_unittest
+
+class test_single_pole_iir_cc(gr_unittest.TestCase):
+
+    def setUp (self):
+        self.fg = gr.flow_graph ()
+
+    def tearDown (self):
+        self.fg = None
+
+    def test_001(self):
+        src_data = (0+0j, 1000+1000j, 2000+2000j, 3000+3000j, 4000+4000j, 
5000+5000j)
+        expected_result = src_data
+        src = gr.vector_source_c(src_data)
+        op = gr.single_pole_iir_filter_cc (1.0)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, op, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data)
+
+    def test_002(self):
+        src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), 
complex(3000,-3000), complex(4000,-4000), complex(5000,-5000))
+        expected_result = (complex(0,0), complex(125,-125), 
complex(359.375,-359.375), complex(689.453125,-689.453125), 
complex(1103.271484,-1103.271484), complex(1590.36255,-1590.36255))
+        src = gr.vector_source_c(src_data)
+        op = gr.single_pole_iir_filter_cc (0.125)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, op, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3)
+
+    def test_003(self):
+        block_size = 2
+        src_data = (complex(0,0), complex(1000,-1000), complex(2000,-2000), 
complex(3000,-3000), complex(4000,-4000), complex(5000,-5000))
+        expected_result = (complex(0,0), complex(125,-125), complex(250,-250), 
complex(484.375,-484.375), complex(718.75,-718.75), 
complex(1048.828125,-1048.828125))
+        src = gr.vector_source_c(src_data)
+        s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, block_size)
+        op = gr.single_pole_iir_filter_cc (0.125, block_size)
+        p2s = gr.parallel_to_serial(gr.sizeof_gr_complex, block_size)
+        dst = gr.vector_sink_c()
+        self.fg.connect (src, s2p, op, p2s, dst)
+        self.fg.run()
+        result_data = dst.data()
+        self.assertComplexTuplesAlmostEqual (expected_result, result_data, 3)
+
+
+if __name__ == '__main__':
+    gr_unittest.main ()
+        

reply via email to

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