AGC algorithm for Arduino

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rubidium
 
Posts: 43
Joined: Sun Nov 18, 2012 10:36 am

AGC algorithm for Arduino

Post by rubidium »

Before developing code from scratch, I'm sure there are existing libraries out there so I thought I'd ask.

I have an application where I need to digitally process an input audio stream in an Arduino Due, e.g. perform FFT's, etc. The input to the Due's ADC is taken from a TI PGS2311 audio volume control chip, so that I may control the input level to the ADC by varying the PGA2311 gain via appropriate SPI commands. Right now, I manually control that gain via push buttons on the Arduino. I would like to have a control loop that automatically adjusts the PGA2311 gain (and thus the level of the input applied to the ADC), to optimize the dynamic range of the ADC data as the level of the input audio stream varies - without having the gain max out when the input audio is absent and there is just noise present. I know algorithms of this type exist that include thresholds to address the presence of signal vs noise, and also include user-chosen attack and decay time constants to define the dynamic response of AGC action. I'm just curious if anyone knows of some existing C code that does this.

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: AGC algorithm for Arduino

Post by thefatmoop »

I would just keep a small array of the data and measure the peak value. If the peak value is too small then increase gain. if it's too large decrease gain. Then watch the uptime to limit how often it makes these adjustments. If you're willing to do some more work then do it by RMS of the samples in the array.

IF you want to do it with hardware then make a peak detector and make it's discharge rate slow. When in doubt find an oscilliscope to give you better eyes

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”