Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Radio
- {
- public class AutomaticGainControl : IFilter
- {
- private const double MeanLevel = 0.0001;
- private const double MaxFactor = 1.0;
- private const double MinFactor = 1000.0;
- private const double TimeConst = 0.00005;
- private readonly Integrator _integrator = new Integrator(TimeConst);
- public double Process(double sample)
- {
- var dc = _integrator.Process(sample);
- var factor = MeanLevel / dc;
- if (factor > MaxFactor)
- {
- factor = MaxFactor;
- }
- if (factor < MinFactor)
- {
- factor = MinFactor;
- }
- return sample * factor;
- }
- }
- public class Integrator : IFilter
- {
- private readonly double _ratio;
- private double _mean;
- public Integrator()
- {
- _ratio = 0.01;
- }
- public Integrator(double ratio)
- {
- _ratio = ratio;
- }
- public double Process(double sample)
- {
- _mean = _mean * (1 - _ratio) + sample * _ratio;
- return _mean;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement