-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaubechies_6d.c
More file actions
executable file
·77 lines (58 loc) · 1.5 KB
/
daubechies_6d.c
File metadata and controls
executable file
·77 lines (58 loc) · 1.5 KB
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
#include <stdlib.h>
#include <stdio.h>
#define nc 6
double* daubechies_6d(double *a, size_t n) {
static const double h_6[6] = {
0.33267055295008261599851158914,
0.80689150931109257649449360409,
0.45987750211849157009515194215,
-0.13501102001025458869638990670,
-0.08544127388202666169281916918,
0.03522629188570953660274066472
};
static const double g_6[6] = {
0.03522629188570953660274066472,
0.08544127388202666169281916918,
-0.13501102001025458869638990670,
-0.45987750211849157009515194215,
0.80689150931109257649449360409,
-0.33267055295008261599851158914
};
int i, ii, j, jf, k, nmod, n1, ni, nh;
double *out = (double *) malloc(n * sizeof(double));
if (out == NULL) {
fprintf (stderr, "calloc failed\n");
exit(0);
}
double *scratch = (double *) calloc(sizeof(double), n);
if (scratch == NULL) {
fprintf (stderr, "calloc failed\n");
exit(0);
}
/* Init to input */
for (i=0; i<n; i++)
out[i] = a[i];
for (j = n; j >= 2; j >>= 1) {
nmod = nc * j;
n1 = j - 1;
nh = j >> 1;
for (i=0; i<n; i++)
scratch[i] = 0.0;
for (ii = 0, i = 0; i < j; i += 2, ii++) {
double h = 0, g = 0;
ni = i + nmod;
for (k = 0; k < nc; k++) {
jf = n1 & (ni + k);
h += h_6[k] * out[jf];
g += g_6[k] * out[jf];
}
scratch[ii] += h;
scratch[ii + nh] += g;
}
for (i = 0; i < j; i++) {
out[i] = scratch[i];
}
}
free(scratch);
return out;
}