DiFipp/include/Butterworth.h

56 wiersze
1.5 KiB
C
Czysty Zwykły widok Historia

#pragma once
2018-12-17 05:48:44 +00:00
#include "DigitalFilter.h"
2018-12-14 10:04:41 +00:00
#include "typedefs.h"
2018-12-14 11:30:44 +00:00
#include <cmath>
#include <complex>
namespace fratio {
// https://www.dsprelated.com/showarticle/1119.php
2018-12-18 07:16:47 +00:00
// https://www.dsprelated.com/showarticle/1135.php
// https://www.dsprelated.com/showarticle/1128.php
2018-12-18 09:23:09 +00:00
// https://www.dsprelated.com/showarticle/1131.php
template <typename T>
2018-12-14 10:04:41 +00:00
class Butterworth : public DigitalFilter<T> {
2018-12-14 09:55:16 +00:00
public:
T PI = static_cast<T>(M_PI);
public:
enum class Type {
LowPass,
2018-12-18 07:16:47 +00:00
HighPass,
BandPass,
BandReject
};
// public:
// static double minimumRequiredFrequency(...);
public:
Butterworth(Type type = Type::LowPass);
2018-12-17 05:48:44 +00:00
Butterworth(int order, T fc, T fs, Type type = Type::LowPass);
2018-12-18 09:23:09 +00:00
Butterworth(int order, T fLower, T fUpper, T fs, Type type = Type::BandPass);
2018-12-18 09:23:09 +00:00
void setFilterParameters(int order, T fc, T fs);
void setFilterParameters(int order, T f0, T fLimit, T fs);
private:
2018-12-18 09:23:09 +00:00
void initialize(int order, T f0, T fLimit, T fs); // f0 = fc for LowPass/HighPass filter
2018-12-18 07:16:47 +00:00
void computeDigitalRep(T fc);
2018-12-18 09:23:09 +00:00
void computeBandDigitalRep(T fLower, T fUpper);
2018-12-18 07:16:47 +00:00
std::complex<T> generateAnalogPole(int k, T fpw);
2018-12-18 09:23:09 +00:00
std::pair<std::complex<T>, std::complex<T>> generateBandAnalogPole(int k, T fpw0, T bw);
vectXc_t<T> generateAnalogZeros(T f0 = T());
void scaleAmplitude(const vectX_t<T>& aCoeff, Eigen::Ref<vectX_t<T>> bCoeff, const std::complex<T>& bpS = T());
private:
Type m_type;
2018-12-17 05:48:44 +00:00
int m_order;
T m_fs;
2018-12-18 07:16:47 +00:00
vectXc_t<T> m_poles;
};
} // namespace fratio
2018-12-14 10:04:41 +00:00
#include "Butterworth.tpp"