[Top][All Lists]

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

[Discuss-gnuradio] Software AGC

From: Achilleas Anastasopoulos
Subject: [Discuss-gnuradio] Software AGC
Date: Tue, 25 Jan 2005 11:48:00 -0500
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)


I will get to it ASAP; I can't wait to write my first
C++ block.

However, sometimes there is need for one block to control the gain
of another block, which cannot be handled by this primitive.

Some time ago Chuck sent a piece of code that can be modified as

def build_graph (stuff) :
   fg = gr.flow_graph ()
   chan_filter = gr.fir....
   return fg, chan_filter            <--- returns a tuple

def main () :
    tuple = build_graph (stuff)
    tuple[0].start()                 <--- access 1st item in tuple
    while True:
        newtaps = ...generate the new taps
        tuple[1].set_taps (newtaps)  <--- access 2nd item in tuple

For some reason I cannot get something like this to work with
GUI applications. Once the app.MainLoop() is invoked, the
code that follows is not executed. Is there anything like
the start() method in gui applications?

Does anyone know how to do this?


On Mon, Jan 24, 2005 at 09:20:28PM -0500, Anastasopoulos Achilleas wrote:

Also, there is one thing that would be cool to implement:
some sort of software AGC that measures the pilot power and updates
the gain (to maintain a unit power subcarrier) every, say, 5 secs.
One idea is to get the squared signal, measure the DC component
and call filter.set_taps((...)) once every 5 seconds...
I am not sure how to implement this (maybe using time.sleep(5))

You don't want to use time.sleep (...)

Here's an AGC primitive from the gnuradio-0.9 tarball.
It does it constantly.  It approximates power as absolute value, uses
a loop filter to control that adaptation rate and provides scaling of
the data passing through the block.

rate controls the adaptation rate.
reference is the value you want to drive the avg power to.

gain is the knob that's controlled by the loop.

/* -*- 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
 * 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
 * Power is approximated by absolute value

class gri_agc {

  gri_agc (float rate = 1e-4, float reference = 1.0, float gain = 1.0)
    : d_rate(rate), d_reference(reference), d_gain(gain) {};

  float rate () const      { return d_rate; }
  float reference () const { return d_reference; }
  float gain () const      { return d_gain;  }

  void setd_rate (float rate) { d_rate = rate; }
  void setd_reference (float reference) { d_reference = reference; }
  void setd_gain (float gain) { d_gain = gain; }

  float scale (float input){
    float output = input * d_gain;
    d_gain += (d_reference - fabsf (output)) * d_rate;
    return output;

  void scale_n (float output[], const float input[], unsigned n){
    for (unsigned i = 0; i < n; i++)
      output[i] = scale (input[i]);
  float d_rate;                 // adjustment rate
  float d_reference;            // reference value
  float d_gain;                 // current gain

#endif /* INCLUDED_GRI_AGC_H */

A (very) minor amount of effort would be required to integrate it into
2.x Just derive a new block called gr_agc_ff (or gr_agc_cc) from
gr_sync_block.  Use gri_agc.h to do the work (call scale_n in the work

If you need a complex version, it's a minor variation on this theme.

See http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html

If you've got time, please write gr_agc_{ff,cc}.{h,cc} and submit a patch.


reply via email to

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