mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
renamed Window and WinFunc to Coeffs and CoeffsFunc and moved to own header
This commit is contained in:
parent
f9992b5372
commit
6c5a418693
2 changed files with 57 additions and 36 deletions
49
coeffs.hh
Normal file
49
coeffs.hh
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
Coefficient array helper
|
||||
|
||||
Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#ifndef COEFFS_HH
|
||||
#define COEFFS_HH
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
struct CoeffsFunc
|
||||
{
|
||||
virtual TYPE operator () (int, int) = 0;
|
||||
virtual ~CoeffsFunc() = default;
|
||||
};
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
class Coeffs
|
||||
{
|
||||
TYPE w[TAPS];
|
||||
public:
|
||||
Coeffs(CoeffsFunc<TYPE> *func)
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = (*func)(n, TAPS);
|
||||
}
|
||||
Coeffs(CoeffsFunc<TYPE> *func0, CoeffsFunc<TYPE> *func1)
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = (*func0)(n, TAPS) * (*func1)(n, TAPS);
|
||||
}
|
||||
void normalize(TYPE divisor = 1)
|
||||
{
|
||||
TYPE sum(0);
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
sum += w[n];
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] /= divisor * std::abs(sum);
|
||||
}
|
||||
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