mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added Kaiser window
This commit is contained in:
parent
c53e782b3c
commit
c6de7e95e0
1 changed files with 29 additions and 0 deletions
29
window.hh
29
window.hh
|
|
@ -7,6 +7,8 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
#ifndef WINDOW_HH
|
||||
#define WINDOW_HH
|
||||
|
||||
#include "kahan.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
|
|
@ -65,6 +67,33 @@ public:
|
|||
inline operator const TYPE * () const { return w; }
|
||||
};
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
class Kaiser
|
||||
{
|
||||
TYPE w[TAPS];
|
||||
TYPE i0(TYPE x)
|
||||
{
|
||||
Kahan<TYPE> sum(1.0);
|
||||
TYPE val = 1.0;
|
||||
// converges for -3*M_PI:3*M_PI in less than:
|
||||
// float: 25 iterations
|
||||
// double: 35 iterations
|
||||
for (int n = 1; n < 35; ++n) {
|
||||
TYPE tmp = x / TYPE(2 * n);
|
||||
sum(val *= tmp * tmp);
|
||||
}
|
||||
return sum();
|
||||
}
|
||||
public:
|
||||
Kaiser(TYPE a)
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = i0(TYPE(M_PI) * a * std::sqrt(TYPE(1) - std::pow(TYPE(2 * n) / TYPE(TAPS - 1) - TYPE(1), TYPE(2)))) / i0(TYPE(M_PI) * a);
|
||||
}
|
||||
inline TYPE operator () (int n) { return n >= 0 && n < TAPS ? w[n] : 0; }
|
||||
inline operator const TYPE * () const { return w; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue