1 /* B.Angr 2 * Dynamic distorted bandpass filter plugin 3 * 4 * Copyright (C) 2021 by Sven Jähnichen 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software Foundation, 18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21 #ifndef BUTTERWORTHLOWPASSFILTER_HPP_ 22 #define BUTTERWORTHLOWPASSFILTER_HPP_ 23 24 #include "ButterworthFilter.hpp" 25 26 class ButterworthLowPassFilter : public ButterworthFilter 27 { 28 public: ButterworthLowPassFilter(const double rate,const double cutoff,const int order)29 ButterworthLowPassFilter (const double rate, const double cutoff, const int order) : 30 ButterworthFilter (order) 31 { 32 set (rate, cutoff, order); 33 } 34 set(const double rate,const double cutoff,const int order)35 void set (const double rate, const double cutoff, const int order) 36 { 37 38 this->order = order; 39 o2 = order / 2; 40 f1 = 2; 41 42 const double a = tan (M_PI * cutoff / rate); 43 const double a2 = a * a; 44 45 for (int i = 0; i < o2; ++i) 46 { 47 const double r = sin (M_PI * (2.0 * double (i) + 1.0) / (2.0 * double (order))); 48 const double s = a2 + 2.0 * a * r + 1.0; 49 coeff0[i] = a2 / s; 50 coeff1[i] = 2.0 * (1.0 - a2) / s; 51 coeff2[i] = -(a2 - 2.0 * a * r + 1.0) / s; 52 } 53 } 54 55 }; 56 57 #endif /* BUTTERWORTHLOWPASSFILTER_HPP_ */ 58