-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathdwpttest.c
61 lines (49 loc) · 1.31 KB
/
dwpttest.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "../header/wavelib.h"
double absmax(double *array, int N) {
double max;
int i;
max = 0.0;
for (i = 0; i < N; ++i) {
if (fabs(array[i]) >= max) {
max = fabs(array[i]);
}
}
return max;
}
int main() {
int i, J, N;
wave_object obj;
wpt_object wt;
double *inp, *oup, *diff;
char *name = "db4";
obj = wave_init(name);// Initialize the wavelet
N = 788 + 23;
inp = (double*)malloc(sizeof(double)* N);
oup = (double*)malloc(sizeof(double)* N);
diff = (double*)malloc(sizeof(double)* N);
for (i = 1; i < N + 1; ++i) {
//inp[i - 1] = -0.25*i*i*i + 25 * i *i + 10 * i;
inp[i - 1] = i;
}
J = 4;
wt = wpt_init(obj, N, J);// Initialize the wavelet transform Tree object
setDWPTExtension(wt, "per");// Options are "per" and "sym". Symmetric is the default option
setDWPTEntropy(wt, "logenergy", 0);
dwpt(wt, inp); // Discrete Wavelet Packet Transform
idwpt(wt, oup); // Inverse Discrete Wavelet Packet Transform
for (i = 0; i < N; ++i) {
diff[i] = (inp[i] - oup[i])/inp[i];
}
wpt_summary(wt); // Tree Summary
printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
free(inp);
free(oup);
free(diff);
wave_free(obj);
wpt_free(wt);
return 0;
}