Krotos Modules 3
Loading...
Searching...
No Matches
LowpassFilter.cpp
Go to the documentation of this file.
1//=====================================================================================
7//=====================================================================================
8
9#include "LowpassFilter.h"
10
11//=====================================================================================
12krotos::LowpassFilter::LowpassFilter() : x_1(0), x_2(0), y_1(0), y_2(0) { configure(0.3f); }
13
14//=====================================================================================
15void krotos::LowpassFilter::configure(float normalisedCutoff)
16{
17 assert(normalisedCutoff <= 0.5);
18 assert(normalisedCutoff >= 0.0);
19
20 float K = static_cast<float>(tan(M_PI * normalisedCutoff));
21
22 float denominator = 1.f + sqrtf(2.f) * K + (K * K);
23
24 b0 = (K * K) / denominator;
25 b1 = (2.f * K * K) / denominator;
26 b2 = b0;
27 a1 = (2.f * (K * K - 1.f)) / denominator;
28 a2 = (1.f - sqrtf(2.f) * K + (K * K)) / denominator;
29}
30
31//=====================================================================================
33{
34 float y = b0 * x + b1 * x_1 + b2 * x_2 - a1 * y_1 - a2 * y_2;
35
36 x_2 = x_1;
37 x_1 = x;
38 y_2 = y_1;
39 y_1 = y;
40
41 return y;
42}
LowpassFilter()
Definition LowpassFilter.cpp:12
void configure(float normalisedCutoff)
Definition LowpassFilter.cpp:15
float processSample(float x)
Definition LowpassFilter.cpp:32
#define M_PI
Definition windowing.h:9