-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanning.hpp
106 lines (91 loc) · 2.39 KB
/
hanning.hpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* function w = hanning(varargin)
% HANNING Hanning window.
% HANNING(N) returns the N-point symmetric Hanning window in a column
% vector. Note that the first and last zero-weighted window samples
% are not included.
%
% HANNING(N,'symmetric') returns the same result as HANNING(N).
%
% HANNING(N,'periodic') returns the N-point periodic Hanning window,
% and includes the first zero-weighted window sample.
%
% NOTE: Use the HANN function to get a Hanning window which has the
% first and last zero-weighted samples.ep
itype = 1 --> periodic
itype = 0 --> symmetric
default itype=0 (symmetric)
Copyright 1988-2004 The MathWorks, Inc.
% $Revision: 1.11.4.3 $ $Date: 2007/12/14 15:05:04 $
*/
#define PI 3.14159265359
float *rectwin(int N, short itype)
{
float *w;
w = (float*) calloc(N, sizeof(float));
memset(w, 0, N*sizeof(float));
for(int i = 0; i < N; i++)
{
w[i] = 1.0f;
}
return(w);
}
std::vector<float> bartlett(int N)
{
std::vector<float> w(N, 0.0f);
// w = (float*) calloc(N, sizeof(float));
// memset(w, 0, N*sizeof(float));
if (N == 1)
{
// Special case for n == 1.
w[0] = 1.0;
}
else
{
const unsigned denominator = (N - 1);
for (unsigned i = 0; i < N; ++i)
{
w[i] = 1.0 - fabs(2.0 * i - (N - 1)) / denominator;
}
}
return(w);
}
std::vector<float> hanning(int N, short itype)
{
int half, i, idx, n;
std::vector<float> w(N, 0.0f);
// w = (float*) calloc(N, sizeof(float));
// memset(w, 0, N*sizeof(float));
if(itype==1) //periodic function
n = N-1;
else
n = N;
if(n%2==0)
{
half = n/2;
for(i=0; i<half; i++) //CALC_HANNING Calculates Hanning window samples.
w[i] = 0.5 * (1 - cos(2*PI*(i+1) / (n+1)));
idx = half-1;
for(i=half; i<n; i++) {
w[i] = w[idx];
idx--;
}
}
else
{
half = (n+1)/2;
for(i=0; i<half; i++) //CALC_HANNING Calculates Hanning window samples.
w[i] = 0.5 * (1 - cos(2*PI*(i+1) / (n+1)));
idx = half-2;
for(i=half; i<n; i++) {
w[i] = w[idx];
idx--;
}
}
if(itype==1) //periodic function
{
for(i=N-1; i>=1; i--)
w[i] = w[i-1];
w[0] = 0.0;
}
return(w);
}