mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added some window functions
This commit is contained in:
parent
7770fff23c
commit
799c09a0fb
2 changed files with 61 additions and 0 deletions
|
|
@ -10,3 +10,7 @@ What we have included so far:
|
|||
When working with [Floating-point arithmetic](https://en.wikipedia.org/wiki/Floating-point_arithmetic) we soon realize, that addition is not necessarily [associative](https://en.wikipedia.org/wiki/Associative_property).
|
||||
Whenever we need to add numbers with an ever decreasing magnitude to an sum (of the previous numbers) with an ever increasing magnitude, the [Kahan summation algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) comes in handy and helps keeping the error growth small.
|
||||
|
||||
### [window.hh](window.hh)
|
||||
|
||||
Some [Window functions](https://en.wikipedia.org/wiki/Window_function)
|
||||
|
||||
|
|
|
|||
57
window.hh
Normal file
57
window.hh
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Some window functions
|
||||
|
||||
Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#ifndef WINDOW_HH
|
||||
#define WINDOW_HH
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
class Hann
|
||||
{
|
||||
TYPE w[TAPS];
|
||||
public:
|
||||
Hann()
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = TYPE(0.5) * (TYPE(1) - std::cos(TYPE(2) * TYPE(M_PI) * TYPE(n) / TYPE(TAPS - 1)));
|
||||
}
|
||||
inline TYPE operator () (int n) { return n >= 0 && n < TAPS ? w[n] : 0; }
|
||||
inline operator const TYPE * () const { return w; }
|
||||
};
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
class Hamming
|
||||
{
|
||||
TYPE w[TAPS];
|
||||
public:
|
||||
Hamming()
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = TYPE(0.54) - TYPE(0.46) * std::cos(TYPE(2) * TYPE(M_PI) * TYPE(n) / TYPE(TAPS - 1));
|
||||
}
|
||||
inline TYPE operator () (int n) { return n >= 0 && n < TAPS ? w[n] : 0; }
|
||||
inline operator const TYPE * () const { return w; }
|
||||
};
|
||||
|
||||
template <int TAPS, typename TYPE>
|
||||
class Gauss
|
||||
{
|
||||
TYPE w[TAPS];
|
||||
public:
|
||||
Gauss(TYPE o)
|
||||
{
|
||||
for (int n = 0; n < TAPS; ++n)
|
||||
w[n] = std::exp(- TYPE(0.5) * std::pow((TYPE(n) - TYPE(TAPS - 1) / TYPE(2)) / (o * TYPE(TAPS - 1) / TYPE(2)), TYPE(2)));
|
||||
}
|
||||
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