Added first order high pass static method

This commit is contained in:
Anne de Jong 2022-10-20 16:31:55 +02:00
parent fae1847cf8
commit cb72c2ba74
2 changed files with 50 additions and 0 deletions

View File

@ -41,6 +41,45 @@ SeriesBiquad::SeriesBiquad(const vd &filter_coefs) {
"Filter coefficients should have fourth element (a0) equal to 1.0");
}
}
SeriesBiquad SeriesBiquad::firstOrderHighPass(const d fs, const d cuton_Hz) {
if(fs <= 0) {
throw rte("Invalid sampling frequency: " + std::to_string(fs) + " [Hz]");
}
if(cuton_Hz <= 0) {
throw rte("Invalid cuton frequency: " + std::to_string(cuton_Hz) + " [Hz]");
}
if(cuton_Hz >= 0.98*fs/2) {
throw rte("Invalid cuton frequency. We limit this to 0.98* fs / 2. Given value" + std::to_string(cuton_Hz) + " [Hz]");
}
const d tau = 1/(2*arma::datum::pi*cuton_Hz);
const d facnum = 2*fs*tau/(1+2*fs*tau);
const d facden = (1-2*fs*tau)/(1+2*fs*tau);
vd coefs(6);
// b0
coefs(0) = facnum;
// b1
coefs(1) = -facnum;
// b2
coefs(2) = 0;
// a0
coefs(3) = 1;
// a1
coefs(4) = facden;
// a2
coefs(5) = 0;
return SeriesBiquad(coefs);
}
std::unique_ptr<Filter> SeriesBiquad::clone() const {
// sos.as_col() concatenates all columns, exactly what we want.
return std::make_unique<SeriesBiquad>(sos.as_col());

View File

@ -39,6 +39,17 @@ public:
virtual ~SeriesBiquad() override {}
void reset() override final;
std::unique_ptr<Filter> clone() const override final;
/**
* @brief Create a SeriesBiquad object for a first order high-pass filter
*
* @param fs Sampling frequency [Hz]
* @param cuton_Hz Cuton-frequency [Hz]
*
* @return SeriesBiquad object with a single biquad, corresponding to a first
* order high pass filter.
*/
static SeriesBiquad firstOrderHighPass(const d fs, const d cuton_Hz);
};
/**