Debian Codegraph @

demo/_dwt_decompose.c

raw symbols SCIP
1 /*
2 * Note: this currently doesn't get installed. There's also no way to query
3 * the location of wt.h. Conclusion: there is no C API.
4 */
5
6 #include <stdio.h>
7
8 #include "wt.h"
9
10 int main(){
11
12 // Using C API to decompose 1D signal.
13 // Results equivalent to pywt.dwt([1,2,3,4,5,6,7,8], 'db2', 'zpd').
14 // Compile: gcc -I../src dwt_decompose.c ../src/wt.c ../src/wavelets.c ../src/common.c ../src/convolution.c
15
16 Wavelet *w = wavelet('d', 2);
17 MODE mode = MODE_ZEROPAD;
18
19 int i;
20 float input[] = {1,2,3,4,5,6,7,8,9};
21 float *cA, *cD;
22 pywt_index_t input_len, output_len;
23
24 input_len = sizeof input / sizeof input[0];
25 output_len = dwt_buffer_length(input_len, w->dec_len, mode);
26
27 cA = wtcalloc(output_len, sizeof(float));
28 cD = wtcalloc(output_len, sizeof(float));
29
30 printf("Wavelet: %s %d\n\n", w->family_name, w->vanishing_moments_psi);
31
32 float_dec_a(input, input_len, w, cA, output_len, mode);
33 float_dec_d(input, input_len, w, cD, output_len, mode);
34
35 for(i=0; i<output_len; i++){
36 printf("%f ", cA[i]);
37 }
38 printf("\n\n");
39
40 for(i=0; i<output_len; i++){
41 printf("%f ", cD[i]);
42 }
43 printf("\n");
44
45 free_wavelet(w);
46 wtfree(cA);
47 wtfree(cD);
48 return 0;
49 }