1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include "../header/wavelib.h"
6 
absmax(double * array,int N)7 double absmax(double *array, int N) {
8 	double max;
9 	int i;
10 
11 	max = 0.0;
12 	for (i = 0; i < N; ++i) {
13 		if (fabs(array[i]) >= max) {
14 			max = fabs(array[i]);
15 		}
16 	}
17 
18 	return max;
19 }
20 
main()21 int main() {
22 	wave_object obj;
23 	wt_object wt;
24 	double *inp, *out, *diff;
25 	int N, i, J;
26 
27 	FILE *ifp;
28 	double temp[1200];
29 
30 	char *name = "bior3.5";
31 	obj = wave_init(name);// Initialize the wavelet
32 
33 	ifp = fopen("signal.txt", "r");
34 	i = 0;
35 	if (!ifp) {
36 		printf("Cannot Open File");
37 		exit(100);
38 	}
39 	while (!feof(ifp)) {
40 		fscanf(ifp, "%lf \n", &temp[i]);
41 		i++;
42 	}
43 	N = 256;
44 	fclose(ifp);
45 	inp = (double*)malloc(sizeof(double)* N);
46 	out = (double*)malloc(sizeof(double)* N);
47 	diff = (double*)malloc(sizeof(double)* N);
48 	//wmean = mean(temp, N);
49 
50 	for (i = 0; i < N; ++i) {
51 		inp[i] = temp[i];
52 		//printf("%g \n",inp[i]);
53 	}
54 	J = 1;
55 
56 	wt = wt_init(obj, "swt", N, J);// Initialize the wavelet transform object
57 	setWTConv(wt, "direct");
58 
59 
60 	swt(wt, inp);// Perform SWT
61 	//SWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
62 
63 	for (i = 0; i < wt->outlength; ++i) {
64 		printf("%g ",wt->output[i]);
65 	}
66 
67 	iswt(wt, out);// Perform ISWT (if needed)
68 	// Test Reconstruction
69 
70 
71 	for (i = 0; i < wt->siglength; ++i) {
72 		diff[i] = out[i] - inp[i];
73 	}
74 
75 	printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value.
76 
77 	wt_summary(wt);// Prints the full summary.
78 
79 
80 	wave_free(obj);
81 	wt_free(wt);
82 
83 	free(inp);
84 	free(out);
85 	free(diff);
86 	return 0;
87 }
88