CCommit : CWT/ICWT added
This commit is contained in:
109
test/cwttest.c
Normal file
109
test/cwttest.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "../header/wavelib.h"
|
||||
|
||||
int main() {
|
||||
int i, N, J,subscale,a0,iter,nd,k;
|
||||
double *inp,*oup;
|
||||
double dt, dj,s0, param,mn;
|
||||
double td,tn,den, num, recon_mean, recon_var;
|
||||
cwt_object wt;
|
||||
|
||||
FILE *ifp;
|
||||
double temp[1200];
|
||||
|
||||
char *wave = "morlet";// Set Morlet wavelet. Other options "paul" and "dog"
|
||||
char *type = "pow";
|
||||
|
||||
N = 504;
|
||||
param = 6.0;
|
||||
subscale = 4;
|
||||
dt = 0.25;
|
||||
s0 = dt;
|
||||
dj = 1.0 / (double)subscale;
|
||||
J = 11 * subscale; // Total Number of scales
|
||||
a0 = 2;//power
|
||||
|
||||
ifp = fopen("sst_nino3.dat", "r");
|
||||
i = 0;
|
||||
if (!ifp) {
|
||||
printf("Cannot Open File");
|
||||
exit(100);
|
||||
}
|
||||
while (!feof(ifp)) {
|
||||
fscanf(ifp, "%lf \n", &temp[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
fclose(ifp);
|
||||
|
||||
wt = cwt_init(wave, param, N,dt, J);
|
||||
|
||||
inp = (double*)malloc(sizeof(double)* N);
|
||||
oup = (double*)malloc(sizeof(double)* N);
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
inp[i] = temp[i] ;
|
||||
}
|
||||
|
||||
setCWTScales(wt, s0, dj, type, a0);
|
||||
|
||||
cwt(wt, inp);
|
||||
|
||||
printf("\n MEAN %g \n", wt->smean);
|
||||
|
||||
mn = 0.0;
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
mn += sqrt(wt->output[i].re * wt->output[i].re + wt->output[i].im * wt->output[i].im);
|
||||
}
|
||||
|
||||
cwt_summary(wt);
|
||||
|
||||
printf("\n abs mean %g \n", mn / N);
|
||||
|
||||
printf("\n\n");
|
||||
printf("Let CWT w = w(j, n/2 - 1) where n = %d\n\n", N);
|
||||
nd = N/2 - 1;
|
||||
|
||||
printf("%-15s%-15s%-15s%-15s \n","j","Scale","Period","ABS(w)^2");
|
||||
for(k = 0; k < wt->J;++k) {
|
||||
iter = nd + k * N;
|
||||
printf("%-15d%-15lf%-15lf%-15lf \n",k,wt->scale[k],wt->period[k],
|
||||
wt->output[iter].re * wt->output[iter].re + wt->output[iter].im * wt->output[iter].im);
|
||||
}
|
||||
|
||||
icwt(wt, oup);
|
||||
|
||||
num = den = recon_var = recon_mean = 0.0;
|
||||
printf("\n\n");
|
||||
printf("Signal Reconstruction\n");
|
||||
printf("%-15s%-15s%-15s \n","i","Input(i)","Output(i)");
|
||||
|
||||
for (i = N - 10; i < N; ++i) {
|
||||
printf("%-15d%-15lf%-15lf \n", i,inp[i] , oup[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
//printf("%g %g \n", oup[i] ,inp[i] - wt->smean);
|
||||
td = inp[i] ;
|
||||
tn = oup[i] - td;
|
||||
num += (tn * tn);
|
||||
den += (td * td);
|
||||
recon_mean += oup[i];
|
||||
}
|
||||
|
||||
recon_var = sqrt(num / N);
|
||||
recon_mean /= N;
|
||||
|
||||
printf("\nRMS Error %g \n", sqrt(num) / sqrt(den));
|
||||
printf("\nVariance %g \n", recon_var);
|
||||
printf("\nMean %g \n", recon_mean);
|
||||
|
||||
free(inp);
|
||||
free(oup);
|
||||
cwt_free(wt);
|
||||
return 0;
|
||||
}
|
504
test/sst_nino3.dat
Executable file
504
test/sst_nino3.dat
Executable file
@@ -0,0 +1,504 @@
|
||||
-0.15
|
||||
-0.30
|
||||
-0.14
|
||||
-0.41
|
||||
-0.46
|
||||
-0.66
|
||||
-0.50
|
||||
-0.80
|
||||
-0.95
|
||||
-0.72
|
||||
-0.31
|
||||
-0.71
|
||||
-1.04
|
||||
-0.77
|
||||
-0.86
|
||||
-0.84
|
||||
-0.41
|
||||
-0.49
|
||||
-0.48
|
||||
-0.72
|
||||
-1.21
|
||||
-0.80
|
||||
0.16
|
||||
0.46
|
||||
0.40
|
||||
1.00
|
||||
2.17
|
||||
2.50
|
||||
2.34
|
||||
0.80
|
||||
0.14
|
||||
-0.06
|
||||
-0.34
|
||||
-0.71
|
||||
-0.34
|
||||
-0.73
|
||||
-0.48
|
||||
-0.11
|
||||
0.22
|
||||
0.51
|
||||
0.51
|
||||
0.25
|
||||
-0.10
|
||||
-0.33
|
||||
-0.42
|
||||
-0.23
|
||||
-0.53
|
||||
-0.44
|
||||
-0.30
|
||||
0.15
|
||||
0.09
|
||||
0.19
|
||||
-0.06
|
||||
0.25
|
||||
0.30
|
||||
0.81
|
||||
0.26
|
||||
0.10
|
||||
0.34
|
||||
1.01
|
||||
-0.31
|
||||
-0.90
|
||||
-0.73
|
||||
-0.92
|
||||
-0.73
|
||||
-0.31
|
||||
-0.03
|
||||
0.12
|
||||
0.37
|
||||
0.82
|
||||
1.22
|
||||
1.83
|
||||
1.60
|
||||
0.34
|
||||
-0.72
|
||||
-0.87
|
||||
-0.85
|
||||
-0.40
|
||||
-0.39
|
||||
-0.65
|
||||
0.07
|
||||
0.67
|
||||
0.39
|
||||
0.03
|
||||
-0.17
|
||||
-0.76
|
||||
-0.87
|
||||
-1.36
|
||||
-1.10
|
||||
-0.99
|
||||
-0.78
|
||||
-0.93
|
||||
-0.87
|
||||
-0.44
|
||||
-0.34
|
||||
-0.50
|
||||
-0.39
|
||||
-0.04
|
||||
0.42
|
||||
0.62
|
||||
0.17
|
||||
0.23
|
||||
1.03
|
||||
1.54
|
||||
1.09
|
||||
0.01
|
||||
0.12
|
||||
-0.27
|
||||
-0.47
|
||||
-0.41
|
||||
-0.37
|
||||
-0.36
|
||||
-0.39
|
||||
0.43
|
||||
1.05
|
||||
1.58
|
||||
1.25
|
||||
0.86
|
||||
0.60
|
||||
0.21
|
||||
0.19
|
||||
-0.23
|
||||
-0.29
|
||||
0.18
|
||||
0.12
|
||||
0.71
|
||||
1.42
|
||||
1.59
|
||||
0.93
|
||||
-0.25
|
||||
-0.66
|
||||
-0.95
|
||||
-0.47
|
||||
0.06
|
||||
0.70
|
||||
0.81
|
||||
0.78
|
||||
1.43
|
||||
1.22
|
||||
1.05
|
||||
0.44
|
||||
-0.35
|
||||
-0.67
|
||||
-0.84
|
||||
-0.66
|
||||
-0.45
|
||||
-0.12
|
||||
-0.20
|
||||
-0.16
|
||||
-0.47
|
||||
-0.52
|
||||
-0.79
|
||||
-0.80
|
||||
-0.62
|
||||
-0.86
|
||||
-1.29
|
||||
-1.04
|
||||
-1.05
|
||||
-0.75
|
||||
-0.81
|
||||
-0.90
|
||||
-0.25
|
||||
0.62
|
||||
1.22
|
||||
0.96
|
||||
0.21
|
||||
-0.11
|
||||
-0.25
|
||||
-0.24
|
||||
-0.43
|
||||
0.23
|
||||
0.67
|
||||
0.78
|
||||
0.41
|
||||
0.98
|
||||
1.28
|
||||
1.45
|
||||
1.02
|
||||
0.03
|
||||
-0.59
|
||||
-1.34
|
||||
-0.99
|
||||
-1.49
|
||||
-1.74
|
||||
-1.33
|
||||
-0.55
|
||||
-0.51
|
||||
-0.36
|
||||
-0.99
|
||||
0.32
|
||||
1.04
|
||||
1.41
|
||||
0.99
|
||||
0.66
|
||||
0.50
|
||||
0.22
|
||||
0.71
|
||||
-0.16
|
||||
0.38
|
||||
0.00
|
||||
-1.11
|
||||
-1.04
|
||||
0.05
|
||||
-0.64
|
||||
-0.34
|
||||
-0.50
|
||||
-1.85
|
||||
-0.94
|
||||
-0.78
|
||||
0.29
|
||||
0.27
|
||||
0.69
|
||||
-0.06
|
||||
-0.83
|
||||
-0.80
|
||||
-1.02
|
||||
-0.96
|
||||
-0.09
|
||||
0.62
|
||||
0.87
|
||||
1.03
|
||||
0.70
|
||||
-0.10
|
||||
-0.31
|
||||
0.04
|
||||
-0.46
|
||||
0.04
|
||||
0.24
|
||||
-0.08
|
||||
-0.28
|
||||
0.06
|
||||
0.05
|
||||
-0.31
|
||||
0.11
|
||||
0.27
|
||||
0.26
|
||||
0.04
|
||||
0.12
|
||||
1.11
|
||||
1.53
|
||||
1.23
|
||||
0.17
|
||||
-0.18
|
||||
-0.56
|
||||
0.05
|
||||
0.41
|
||||
0.22
|
||||
0.04
|
||||
-0.19
|
||||
-0.46
|
||||
-0.65
|
||||
-1.06
|
||||
-0.54
|
||||
0.14
|
||||
0.25
|
||||
-0.21
|
||||
-0.73
|
||||
-0.43
|
||||
0.48
|
||||
0.26
|
||||
0.05
|
||||
0.11
|
||||
-0.27
|
||||
-0.08
|
||||
-0.10
|
||||
0.29
|
||||
-0.15
|
||||
-0.28
|
||||
-0.55
|
||||
-0.44
|
||||
-1.40
|
||||
-0.55
|
||||
-0.69
|
||||
0.58
|
||||
0.37
|
||||
0.42
|
||||
1.83
|
||||
1.23
|
||||
0.65
|
||||
0.41
|
||||
1.03
|
||||
0.64
|
||||
-0.07
|
||||
0.98
|
||||
0.36
|
||||
-0.30
|
||||
-1.33
|
||||
-1.39
|
||||
-0.94
|
||||
0.34
|
||||
-0.00
|
||||
-0.15
|
||||
0.06
|
||||
0.39
|
||||
0.36
|
||||
-0.49
|
||||
-0.53
|
||||
0.35
|
||||
0.07
|
||||
-0.24
|
||||
0.20
|
||||
-0.22
|
||||
-0.68
|
||||
-0.44
|
||||
0.02
|
||||
-0.22
|
||||
-0.30
|
||||
-0.59
|
||||
0.10
|
||||
-0.02
|
||||
-0.27
|
||||
-0.60
|
||||
-0.48
|
||||
-0.37
|
||||
-0.53
|
||||
-1.35
|
||||
-1.22
|
||||
-0.99
|
||||
-0.34
|
||||
-0.79
|
||||
-0.24
|
||||
0.02
|
||||
0.69
|
||||
0.78
|
||||
0.17
|
||||
-0.17
|
||||
-0.29
|
||||
-0.27
|
||||
0.31
|
||||
0.44
|
||||
0.38
|
||||
0.24
|
||||
-0.13
|
||||
-0.89
|
||||
-0.76
|
||||
-0.71
|
||||
-0.37
|
||||
-0.59
|
||||
-0.63
|
||||
-1.47
|
||||
-0.40
|
||||
-0.18
|
||||
-0.37
|
||||
-0.43
|
||||
-0.06
|
||||
0.61
|
||||
1.33
|
||||
1.19
|
||||
1.13
|
||||
0.31
|
||||
0.14
|
||||
0.03
|
||||
0.21
|
||||
0.15
|
||||
-0.22
|
||||
-0.02
|
||||
0.03
|
||||
-0.17
|
||||
0.12
|
||||
-0.35
|
||||
-0.06
|
||||
0.38
|
||||
-0.45
|
||||
-0.32
|
||||
-0.33
|
||||
-0.49
|
||||
-0.14
|
||||
-0.56
|
||||
-0.18
|
||||
0.46
|
||||
1.09
|
||||
1.04
|
||||
0.23
|
||||
-0.99
|
||||
-0.59
|
||||
-0.92
|
||||
-0.28
|
||||
0.52
|
||||
1.31
|
||||
1.45
|
||||
0.61
|
||||
-0.11
|
||||
-0.18
|
||||
-0.39
|
||||
-0.39
|
||||
-0.36
|
||||
-0.50
|
||||
-0.81
|
||||
-1.10
|
||||
-0.29
|
||||
0.57
|
||||
0.68
|
||||
0.78
|
||||
0.78
|
||||
0.63
|
||||
0.98
|
||||
0.49
|
||||
-0.42
|
||||
-1.34
|
||||
-1.20
|
||||
-1.18
|
||||
-0.65
|
||||
-0.42
|
||||
-0.97
|
||||
-0.28
|
||||
0.77
|
||||
1.77
|
||||
2.22
|
||||
1.05
|
||||
-0.67
|
||||
-0.99
|
||||
-1.52
|
||||
-1.17
|
||||
-0.22
|
||||
-0.04
|
||||
-0.45
|
||||
-0.46
|
||||
-0.75
|
||||
-0.70
|
||||
-1.38
|
||||
-1.15
|
||||
-0.01
|
||||
0.97
|
||||
1.10
|
||||
0.68
|
||||
-0.02
|
||||
-0.04
|
||||
0.47
|
||||
0.30
|
||||
-0.55
|
||||
-0.51
|
||||
-0.09
|
||||
-0.01
|
||||
0.34
|
||||
0.61
|
||||
0.58
|
||||
0.33
|
||||
0.38
|
||||
0.10
|
||||
0.18
|
||||
-0.30
|
||||
-0.06
|
||||
-0.28
|
||||
0.12
|
||||
0.58
|
||||
0.89
|
||||
0.93
|
||||
2.39
|
||||
2.44
|
||||
1.92
|
||||
0.64
|
||||
-0.24
|
||||
0.27
|
||||
-0.13
|
||||
-0.16
|
||||
-0.54
|
||||
-0.13
|
||||
-0.37
|
||||
-0.78
|
||||
-0.22
|
||||
0.03
|
||||
0.25
|
||||
0.31
|
||||
1.03
|
||||
1.10
|
||||
1.05
|
||||
1.11
|
||||
1.28
|
||||
0.57
|
||||
-0.55
|
||||
-1.16
|
||||
-0.99
|
||||
-0.38
|
||||
0.01
|
||||
-0.29
|
||||
0.09
|
||||
0.46
|
||||
0.57
|
||||
0.24
|
||||
0.39
|
||||
0.49
|
||||
0.86
|
||||
0.51
|
||||
0.95
|
||||
1.25
|
||||
1.33
|
||||
-0.00
|
||||
0.34
|
||||
0.66
|
||||
1.11
|
||||
0.34
|
||||
0.48
|
||||
0.56
|
||||
0.39
|
||||
-0.17
|
||||
1.04
|
||||
0.77
|
||||
0.12
|
||||
-0.35
|
||||
-0.22
|
||||
0.08
|
||||
-0.08
|
||||
-0.18
|
||||
-0.06
|
Reference in New Issue
Block a user