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;
- }
- }
- public class DcRemover : IFilter
- {
- private readonly Integrator _integrator;
- public DcRemover()
- {
- _integrator = new Integrator(0.01);
- }
- public DcRemover(double ratio)
- {
- _integrator = new Integrator(ratio);
- }
- public double Process(double sample)
- {
- return sample - _integrator.Process(sample);
- }
- }
- public class AmDetector : IDetector
- {
- private readonly DcRemover _dcRemover = new DcRemover();
- public double Demodulate(Complex d)
- {
- var sample = d.Modulus();
- return _dcRemover.Process(sample);
- }
- }
- public class LsbDetector : IDetector
- {
- private int _sampleRate;
- private readonly Oscillator _bfo = new Oscillator();
- public LsbDetector()
- {
- _bfo.Frequency = Radio.BfoFrequency;
- }
- public double Demodulate(Complex sample)
- {
- _bfo.Tick();
- var product = sample * _bfo.Out.Conjugate();
- return product.Real + product.Imag;
- }
- public int SampleRate
- {
- get { return _sampleRate; }
- set
- {
- _sampleRate = value;
- _bfo.SampleRate = value;
- }
- }
- }
- public class UsbDetector : IDetector
- {
- private int _sampleRate;
- private readonly Oscillator _bfo = new Oscillator();
- public UsbDetector()
- {
- _bfo.Frequency = Radio.BfoFrequency;
- }
- public double Demodulate(Complex sample)
- {
- _bfo.Tick();
- var product = sample * _bfo;
- return product.Real + product.Imag;
- }
- public int SampleRate
- {
- get { return _sampleRate; }
- set
- {
- _sampleRate = value;
- _bfo.SampleRate = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement