1/* 2 Digitan RC-filter implementation in Faust 3 Copyright(C) 2010 Sampo Savolainen <v2@iki.fi> 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 Thanks to Torben Hohn and 19 http://www.dsplog.com/2007/12/02/digital-implementation-of-rc-low-pass-filter/ 20*/ 21 22 23// Note that float precision might limit how well these work.. 24 25passive_lp(resistance, uf) = (filter ~ _) 26with { 27 // simplified to minimize floating point precision problems 28 filter(prev,x) = prev + (( x - prev) * 1000000) / (resistance * uf * SR); 29 30 // readable implementation 31 //filter(prev,x) = prev + k * ( x - prev); 32 //k = 1 / RC * dt; 33 //RC = resistance * uf / 1000000; 34 //dt = 1 / SR; 35}; 36 37passive_hp(resistance, uf) = (filter ~ _) 38with { 39 40 filter(prev,x) = alpha * prev + alpha * (x - x'); 41 42 alpha = RC / (RC + dt); 43 44 RC = resistance * uf / 1000000; 45 dt = 1 / SR; 46}; 47