Advertisement
prog

AGC

Jul 30th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Radio
  4. {
  5.     public class AutomaticGainControl : IFilter
  6.     {
  7.         private const double MeanLevel = 0.02;
  8.         private const double MaxFactor = 5000.0;
  9.         private const double MinFactor = 1.0;
  10.         private const double TimeConst = 0.001;
  11.  
  12.         private readonly Integrator _integrator = new Integrator(TimeConst);
  13.  
  14.         public double Process(double sample)
  15.         {
  16.             var dc = _integrator.Process(Math.Abs(sample));
  17.             var factor = MeanLevel / dc;
  18.             if (factor > MaxFactor)
  19.             {
  20.                 factor = MaxFactor;
  21.             }
  22.             if (factor < MinFactor)
  23.             {
  24.                 factor = MinFactor;
  25.             }
  26.             return sample * factor;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement