mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +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
|
|
@ -21,6 +21,13 @@ Implemented are the follwing [Window functions](https://en.wikipedia.org/wiki/Wi
|
|||
* [Gaussian window](https://en.wikipedia.org/wiki/Window_function#Gaussian_window)
|
||||
* [Kaiser window](https://en.wikipedia.org/wiki/Window_function#Kaiser_window)
|
||||
|
||||
### [filter.hh](filter.hh)
|
||||
|
||||
Implemented are the following [finite impulse response](https://en.wikipedia.org/wiki/Finite_impulse_response) [filters](https://en.wikipedia.org/wiki/Filter_(signal_processing)):
|
||||
* [low-pass filter](https://en.wikipedia.org/wiki/Low-pass_filter)
|
||||
* [high-pass filter](https://en.wikipedia.org/wiki/High-pass_filter)
|
||||
* [band-pass filter](https://en.wikipedia.org/wiki/Band-pass_filter)
|
||||
|
||||
### [const.hh](const.hh)
|
||||
|
||||
Some constants we need
|
||||
|
|
|
|||
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