mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 22:35:45 +00:00
added FIR LPF, HPF and BPF
This commit is contained in:
parent
f3c22ed3cc
commit
00501fa433
2 changed files with 68 additions and 0 deletions
61
filter.hh
Normal file
61
filter.hh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
Some finite impulse response filter functions
|
||||
|
||||
Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#ifndef FILTER_HH
|
||||
#define FILTER_HH
|
||||
|
||||
#include "const.hh"
|
||||
#include "utils.hh"
|
||||
#include "coeffs.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
class LowPass : public CoeffsFunc<TYPE>
|
||||
{
|
||||
TYPE f;
|
||||
public:
|
||||
LowPass(TYPE cutoff) : f(TYPE(2) * cutoff) {}
|
||||
TYPE operator () (int n, int N)
|
||||
{
|
||||
TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1);
|
||||
return f * sinc(f * x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TYPE>
|
||||
class HighPass : public CoeffsFunc<TYPE>
|
||||
{
|
||||
TYPE f;
|
||||
public:
|
||||
HighPass(TYPE cutoff) : f(TYPE(2) * cutoff) {}
|
||||
TYPE operator () (int n, int N)
|
||||
{
|
||||
TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1);
|
||||
// if (N%1) return delta(x) - f * sinc(f * x);
|
||||
return sinc(x) - f * sinc(f * x);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template <typename TYPE>
|
||||
class BandPass : public CoeffsFunc<TYPE>
|
||||
{
|
||||
TYPE f0, f1;
|
||||
public:
|
||||
BandPass(TYPE cutoff0, TYPE cutoff1) :
|
||||
f0(TYPE(2) * cutoff0), f1(TYPE(2) * cutoff1) {}
|
||||
TYPE operator () (int n, int N)
|
||||
{
|
||||
TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1);
|
||||
return f1 * sinc(f1 * x) - f0 * sinc(f0 * x);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue