DiFipp/include/Butterworth.h

57 wiersze
1.4 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
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 07:16:47 +00:00
Butterworth(int order, T bw, T fs, T fCenter, Type type = Type::BandPass);
2018-12-18 07:16:47 +00:00
void setFilterParameters(int order, T fc, T fs, T fCenter = T(0));
private:
2018-12-18 07:16:47 +00:00
void initialize(int order, T fc, T fs, T fCenter = T(0)); // fc = bw for bandPass filter
void computeDigitalRep(T fc);
void computeBandDigitalRep(T bw, T fCenter);
std::complex<T> generateAnalogPole(int k, T fpw);
std::pair<std::complex<T>, std::complex<T>> generateBandAnalogPole(int k, T fpw1, T fpw2);
vectXc_t<T> generateAnalogZeros();
2018-12-17 08:16:01 +00:00
void scaleAmplitude(Eigen::Ref<vectX_t<T>> aCoeff, Eigen::Ref<vectX_t<T>> bCoeff);
private:
Type m_type;
2018-12-17 05:48:44 +00:00
int m_order;
T m_fc;
2018-12-18 07:16:47 +00:00
T m_bw;
T m_fs;
2018-12-18 07:16:47 +00:00
T m_fCenter;
vectXc_t<T> m_poles;
};
} // namespace fratio
2018-12-14 10:04:41 +00:00
#include "Butterworth.tpp"