-
Notifications
You must be signed in to change notification settings - Fork 3
/
hann.cpp
52 lines (43 loc) · 1.19 KB
/
hann.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "hann.h"
hann::hann (int degree, float f) {
int i;
float sum = 0;
filterKernel = new float [degree];
buffer = new std::complex<float> [degree];
this -> degree = degree;
for (i = 0; i < degree; i ++) {
if (i == degree / 2)
filterKernel [i] = 2 * M_PI * f;
else
filterKernel [i] = sin (2 * M_PI * f * (i - degree / 2)) / (i - degree / 2);
//
// windowing
filterKernel [i] *=
0.5 * (1 - cos ((2 * M_PI * i) / (degree - 1)));
sum += filterKernel [i];
}
for (i = 0; i < degree; i ++) {
filterKernel [i] /= sum;
buffer [i] = std::complex<float> (0, 0);
}
ip = 0;
}
hann::~hann (void) {
delete[] filterKernel;
delete[] buffer;
}
std::complex<float> hann::Pass (std::complex<float> z) {
int16_t i;
std::complex<float> tmp = 0;
buffer [ip] = z;
for (i = 0; i < degree; i ++) {
int16_t index = ip - i;
if (index < 0)
index += degree;
tmp +=
std::complex<float> (real (buffer [index]) * filterKernel [i],
imag (buffer [index]) * filterKernel [i]);
}
ip = (ip + 1) % degree;
return tmp;
}