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 alpha)
        {
            if (alpha < 0.0 || alpha > 1.0)
                throw new ArgumentException(nameof(alpha), "Alpha must be between 0 and 1.");

            _alpha = alpha;
            _previousOutput = 0.0;
            _previouseInput = 0.0;
        }

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

            return output;
        }
    }
}
