comparison libaf/window.c @ 14274:012426ca576b

less namespace pollution
author alex
date Wed, 29 Dec 2004 19:41:21 +0000
parents 14090f7300a8
children 07abe94a9cc4
comparison
equal deleted inserted replaced
14273:dcdbe7055e62 14274:012426ca576b
22 // Boxcar 22 // Boxcar
23 // 23 //
24 // n window length 24 // n window length
25 // w buffer for the window parameters 25 // w buffer for the window parameters
26 */ 26 */
27 void boxcar(int n, _ftype_t* w) 27 void af_window_boxcar(int n, _ftype_t* w)
28 { 28 {
29 int i; 29 int i;
30 // Calculate window coefficients 30 // Calculate window coefficients
31 for (i=0 ; i<n ; i++) 31 for (i=0 ; i<n ; i++)
32 w[i] = 1.0; 32 w[i] = 1.0;
42 // w = 1.0 - --------------- 42 // w = 1.0 - ---------------
43 // N+1 43 // N+1
44 // n window length 44 // n window length
45 // w buffer for the window parameters 45 // w buffer for the window parameters
46 */ 46 */
47 void triang(int n, _ftype_t* w) 47 void af_window_triang(int n, _ftype_t* w)
48 { 48 {
49 _ftype_t k1 = (_ftype_t)(n & 1); 49 _ftype_t k1 = (_ftype_t)(n & 1);
50 _ftype_t k2 = 1/((_ftype_t)n + k1); 50 _ftype_t k2 = 1/((_ftype_t)n + k1);
51 int end = (n + 1) >> 1; 51 int end = (n + 1) >> 1;
52 int i; 52 int i;
63 // w = 0.5 - 0.5*cos(------), where 0 < k <= N 63 // w = 0.5 - 0.5*cos(------), where 0 < k <= N
64 // N+1 64 // N+1
65 // n window length 65 // n window length
66 // w buffer for the window parameters 66 // w buffer for the window parameters
67 */ 67 */
68 void hanning(int n, _ftype_t* w) 68 void af_window_hanning(int n, _ftype_t* w)
69 { 69 {
70 int i; 70 int i;
71 _ftype_t k = 2*M_PI/((_ftype_t)(n+1)); // 2*pi/(N+1) 71 _ftype_t k = 2*M_PI/((_ftype_t)(n+1)); // 2*pi/(N+1)
72 72
73 // Calculate window coefficients 73 // Calculate window coefficients
82 // N-1 82 // N-1
83 // 83 //
84 // n window length 84 // n window length
85 // w buffer for the window parameters 85 // w buffer for the window parameters
86 */ 86 */
87 void hamming(int n,_ftype_t* w) 87 void af_window_hamming(int n,_ftype_t* w)
88 { 88 {
89 int i; 89 int i;
90 _ftype_t k = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1) 90 _ftype_t k = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1)
91 91
92 // Calculate window coefficients 92 // Calculate window coefficients
101 // N-1 N-1 101 // N-1 N-1
102 // 102 //
103 // n window length 103 // n window length
104 // w buffer for the window parameters 104 // w buffer for the window parameters
105 */ 105 */
106 void blackman(int n,_ftype_t* w) 106 void af_window_blackman(int n,_ftype_t* w)
107 { 107 {
108 int i; 108 int i;
109 _ftype_t k1 = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1) 109 _ftype_t k1 = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1)
110 _ftype_t k2 = 2*k1; // 4*pi/(N-1) 110 _ftype_t k2 = 2*k1; // 4*pi/(N-1)
111 111
121 // N-1 N-1 121 // N-1 N-1
122 // 122 //
123 // n window length 123 // n window length
124 // w buffer for the window parameters 124 // w buffer for the window parameters
125 */ 125 */
126 void flattop(int n,_ftype_t* w) 126 void af_window_flattop(int n,_ftype_t* w)
127 { 127 {
128 int i; 128 int i;
129 _ftype_t k1 = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1) 129 _ftype_t k1 = 2*M_PI/((_ftype_t)(n-1)); // 2*pi/(N-1)
130 _ftype_t k2 = 2*k1; // 4*pi/(N-1) 130 _ftype_t k2 = 2*k1; // 4*pi/(N-1)
131 131
140 // y = sum( (x/(2*n))^2 ) 140 // y = sum( (x/(2*n))^2 )
141 // n 141 // n
142 */ 142 */
143 #define BIZ_EPSILON 1E-21 // Max error acceptable 143 #define BIZ_EPSILON 1E-21 // Max error acceptable
144 144
145 _ftype_t besselizero(_ftype_t x) 145 static _ftype_t besselizero(_ftype_t x)
146 { 146 {
147 _ftype_t temp; 147 _ftype_t temp;
148 _ftype_t sum = 1.0; 148 _ftype_t sum = 1.0;
149 _ftype_t u = 1.0; 149 _ftype_t u = 1.0;
150 _ftype_t halfx = x/2.0; 150 _ftype_t halfx = x/2.0;
184 // 6.764 4.32 0.00275 -70 184 // 6.764 4.32 0.00275 -70
185 // 7.865 5.0 0.000868 -80 185 // 7.865 5.0 0.000868 -80
186 // 8.960 5.7 0.000275 -90 186 // 8.960 5.7 0.000275 -90
187 // 10.056 6.4 0.000087 -100 187 // 10.056 6.4 0.000087 -100
188 */ 188 */
189 void kaiser(int n, _ftype_t* w, _ftype_t b) 189 void af_window_kaiser(int n, _ftype_t* w, _ftype_t b)
190 { 190 {
191 _ftype_t tmp; 191 _ftype_t tmp;
192 _ftype_t k1 = 1.0/besselizero(b); 192 _ftype_t k1 = 1.0/besselizero(b);
193 int k2 = 1 - (n & 1); 193 int k2 = 1 - (n & 1);
194 int end = (n + 1) >> 1; 194 int end = (n + 1) >> 1;