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

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

        public HighPassFilter(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 = rc / (rc + dt);

            _previousOutput = 0.0;
            _previouseInput = 0.0;
        }

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

            return output;
        }
    }
}
