using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GettingStarted.Filter
{
    class LowPassFilter : IFilter
    {
        private double _alpha;
        private double _previousOutput;

        public LowPassFilter(double cutoffFreq, double dt)
        {
            if (cutoffFreq <= 0.0 || dt <= 0.0)
                throw new ArgumentException("Cutoff frequency and dt must be greater than 0.");

            double rc = 1.0 / (2 * Math.PI * cutoffFreq);
            _alpha = dt / (rc + dt);

            _previousOutput = 0.0;
        }

        public double Filter(double input)
        {
            double output = _previousOutput + _alpha * (input - _previousOutput);
            _previousOutput = output;

            return output;
        }
    }
}
