-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmwindows_functions.c
106 lines (89 loc) · 2.17 KB
/
cmwindows_functions.c
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
#include <stdio.h>
#include <math.h>
#include "cmwindows.h"
void cm_hann(double *window, long *length) {
int i;
long N = *length - 1;
for (i = 0; i < *length; i++) {
window[i] = 0.5 * (1.0 - cos((2.0 * M_PI) * ((double)i / (double)N)));
}
return;
}
void cm_hamming(double *window, long *length) {
int i;
long N = *length - 1;
for (i = 0; i < *length; i++) {
window[i] = 0.54 - (0.46 * cos((2.0 * M_PI) * ((double)i / (double)N)));
}
return;
}
void cm_rectangular(double *window, long *length) {
int i;
for (i = 0; i < *length; i++) {
window[i] = 1;
}
return;
}
void cm_bartlett(double *window, long *length) {
int i;
long N = *length - 1;
for (i = 0; i < *length; i++) {
if (i < (*length / 2)) {
window[i] = (2 * (double)i) / (double)N;
}
else {
window[i] = 2 - ((2 * (double)i) / (double)N);
}
}
return;
}
void cm_flattop(double *window, long *length) {
int i;
long N = *length - 1;
double a0 = 0.21557895;
double a1 = 0.41663158;
double a2 = 0.277263158;
double a3 = 0.083578947;
double a4 = 0.006947368;
double twopi = M_PI * 2.0;
double fourpi = M_PI * 4.0;
double sixpi = M_PI * 6.0;
double eightpi = M_PI * 8.0;
for (i = 0; i < *length; i++) {
window[i] = a0 - (a1 * cos((twopi * i) / N)) + (a2 * cos((fourpi * i) / N)) - (a3 * cos((sixpi * i) / N)) + (a4 * cos((eightpi * i) / N));
}
return;
}
void cm_gauss2(double *window, long *length) {
int i;
double n;
double N = *length - 1;
double alpha = 2.0;
double stdev = N / (2 * alpha);
for (i = 0; i < *length; i++) {
n = i - N / 2;
window[i] = exp(-0.5 * pow((n / stdev), 2));
}
}
void cm_gauss4(double *window, long *length) {
int i;
double n;
double N = *length - 1;
double alpha = 4.0;
double stdev = N / (2 * alpha);
for (i = 0; i < *length; i++) {
n = i - N / 2;
window[i] = exp(-0.5 * pow((n / stdev), 2));
}
}
void cm_gauss8(double *window, long *length) {
int i;
double n;
double N = *length - 1;
double alpha = 8.0;
double stdev = N / (2 * alpha);
for (i = 0; i < *length; i++) {
n = i - N / 2;
window[i] = exp(-0.5 * pow((n / stdev), 2));
}
}