mirror of
https://github.com/simon987/wavelib.git
synced 2025-04-10 14:06:46 +00:00
const-correct header/wavelib.h; drop duplicate src/wavelib.h; break everything
This commit is contained in:
parent
e2f6ddafe0
commit
f238fb1ce6
@ -26,7 +26,7 @@ typedef struct cplx_t {
|
||||
|
||||
typedef struct wave_set* wave_object;
|
||||
|
||||
wave_object wave_init(char* wname);
|
||||
wave_object wave_init(const char* wname);
|
||||
|
||||
struct wave_set{
|
||||
char wname[50];
|
||||
@ -83,7 +83,7 @@ struct conv_set{
|
||||
|
||||
typedef struct wt_set* wt_object;
|
||||
|
||||
wt_object wt_init(wave_object wave,char* method, int siglength, int J);
|
||||
wt_object wt_init(wave_object wave,const char* method, int siglength, int J);
|
||||
|
||||
struct wt_set{
|
||||
wave_object wave;
|
||||
@ -165,7 +165,7 @@ struct wpt_set{
|
||||
|
||||
typedef struct cwt_set* cwt_object;
|
||||
|
||||
cwt_object cwt_init(char* wave, double param, int siglength,double dt, int J);
|
||||
cwt_object cwt_init(const char* wave, double param, int siglength,double dt, int J);
|
||||
|
||||
struct cwt_set{
|
||||
char wave[10];// Wavelet - morl/morlet,paul,dog/dgauss
|
||||
@ -191,33 +191,33 @@ struct cwt_set{
|
||||
};
|
||||
|
||||
|
||||
void dwt(wt_object wt, double *inp);
|
||||
void dwt(wt_object wt, const double *inp);
|
||||
|
||||
void idwt(wt_object wt, double *dwtop);
|
||||
|
||||
void wtree(wtree_object wt, double *inp);
|
||||
void wtree(wtree_object wt, const double *inp);
|
||||
|
||||
void dwpt(wpt_object wt, double *inp);
|
||||
void dwpt(wpt_object wt, const double *inp);
|
||||
|
||||
void idwpt(wpt_object wt, double *dwtop);
|
||||
|
||||
void swt(wt_object wt, double *inp);
|
||||
void swt(wt_object wt, const double *inp);
|
||||
|
||||
void iswt(wt_object wt, double *swtop);
|
||||
|
||||
void modwt(wt_object wt, double *inp);
|
||||
void modwt(wt_object wt, const double *inp);
|
||||
|
||||
void imodwt(wt_object wt, double *dwtop);
|
||||
|
||||
void setDWTExtension(wt_object wt, char *extension);
|
||||
void setDWTExtension(wt_object wt, const char *extension);
|
||||
|
||||
void setWTREEExtension(wtree_object wt, char *extension);
|
||||
void setWTREEExtension(wtree_object wt, const char *extension);
|
||||
|
||||
void setDWPTExtension(wpt_object wt, char *extension);
|
||||
void setDWPTExtension(wpt_object wt, const char *extension);
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, char *entropy, double eparam);
|
||||
void setDWPTEntropy(wpt_object wt, const char *entropy, double eparam);
|
||||
|
||||
void setWTConv(wt_object wt, char *cmethod);
|
||||
void setWTConv(wt_object wt, const char *cmethod);
|
||||
|
||||
int getWTREENodelength(wtree_object wt, int X);
|
||||
|
||||
@ -227,13 +227,13 @@ int getDWPTNodelength(wpt_object wt, int X);
|
||||
|
||||
void getDWPTCoeffs(wpt_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, char *type, int power);
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, const char *type, int power);
|
||||
|
||||
void setCWTScaleVector(cwt_object wt, double *scale, int J, double s0, double dj);
|
||||
void setCWTScaleVector(cwt_object wt, const double *scale, int J, double s0, double dj);
|
||||
|
||||
void setCWTPadding(cwt_object wt, int pad);
|
||||
|
||||
void cwt(cwt_object wt, double *inp);
|
||||
void cwt(cwt_object wt, const double *inp);
|
||||
|
||||
void icwt(cwt_object wt, double *cwtop);
|
||||
|
||||
|
@ -20,7 +20,6 @@ set(HEADER_FILES conv.h
|
||||
real.h
|
||||
wavefilt.h
|
||||
wavefunc.h
|
||||
wavelib.h
|
||||
wtmath.h
|
||||
)
|
||||
|
||||
@ -28,5 +27,5 @@ add_library(wavelib STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
set_property(TARGET wavelib PROPERTY FOLDER "lib")
|
||||
|
||||
target_include_directories(wavelib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(wavelib PUBLIC ${CMAKE_SOURCE_DIR}/header)
|
||||
|
||||
|
534
src/wavelib.c
534
src/wavelib.c
@ -2,9 +2,17 @@
|
||||
Copyright (c) 2014, Rafat Hussain
|
||||
*/
|
||||
|
||||
#include "wavelib.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
wave_object wave_init(char* wname) {
|
||||
#include "cwt.h"
|
||||
#include "wavelib.h"
|
||||
#include "wtmath.h"
|
||||
|
||||
|
||||
wave_object wave_init(const char* wname) {
|
||||
wave_object obj = NULL;
|
||||
int retval;
|
||||
retval = 0;
|
||||
@ -30,7 +38,7 @@ wave_object wave_init(char* wname) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
wt_object wt_init(wave_object wave,char* method, int siglength,int J) {
|
||||
wt_object wt_init(wave_object wave,const char* method, int siglength,int J) {
|
||||
int size,i,MaxIter;
|
||||
wt_object obj = NULL;
|
||||
|
||||
@ -258,13 +266,13 @@ wpt_object wpt_init(wave_object wave, int siglength, int J) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
cwt_object cwt_init(char* wave, double param,int siglength, double dt, int J) {
|
||||
cwt_object cwt_init(const char* wave, double param,int siglength, double dt, int J) {
|
||||
cwt_object obj = NULL;
|
||||
int N, i,nj2,ibase2,mother;
|
||||
double s0, dj;
|
||||
double t1;
|
||||
int m, odd;
|
||||
char *pdefault = "pow";
|
||||
const char *pdefault = "pow";
|
||||
|
||||
m = (int)param;
|
||||
odd = 1;
|
||||
@ -700,7 +708,7 @@ static void dwt1(wt_object wt,double *sig,int len_sig, double *cA, int len_cA, d
|
||||
free(cA_undec);
|
||||
}
|
||||
|
||||
void dwt(wt_object wt,double *inp) {
|
||||
void dwt(wt_object wt,const double *inp) {
|
||||
int i,J,temp_len,iter,N,lp;
|
||||
int len_cA;
|
||||
double *orig,*orig2;
|
||||
@ -817,7 +825,7 @@ void dwt(wt_object wt,double *inp) {
|
||||
free(orig2);
|
||||
}
|
||||
|
||||
void wtree(wtree_object wt,double *inp) {
|
||||
void wtree(wtree_object wt,const double *inp) {
|
||||
int i,J,temp_len,iter,N,lp,p2,k,N2,Np;
|
||||
int len_cA,t,t2,it1;
|
||||
double *orig;
|
||||
@ -959,7 +967,7 @@ static int ipow2(int n) {
|
||||
return p;
|
||||
}
|
||||
|
||||
void dwpt(wpt_object wt, double *inp) {
|
||||
void dwpt(wpt_object wt, const double *inp) {
|
||||
int i, J, temp_len, iter, N, lp, p2, k, N2, Np;
|
||||
int temp, elength, temp2,size,nodes,llb,n1,j;
|
||||
double eparam,v1,v2;
|
||||
@ -1327,7 +1335,7 @@ int getCWTScaleLength(int N) {
|
||||
return J;
|
||||
}
|
||||
|
||||
void setCWTScales(cwt_object wt, double s0, double dj,char *type,int power) {
|
||||
void setCWTScales(cwt_object wt, double s0, double dj,const char *type,int power) {
|
||||
int i;
|
||||
strcpy(wt->type,type);
|
||||
//s0*pow(2.0, (double)(j - 1)*dj);
|
||||
@ -1353,7 +1361,7 @@ void setCWTScales(cwt_object wt, double s0, double dj,char *type,int power) {
|
||||
wt->dj = dj;
|
||||
}
|
||||
|
||||
void setCWTScaleVector(cwt_object wt, double *scale, int J,double s0,double dj) {
|
||||
void setCWTScaleVector(cwt_object wt, const double *scale, int J,double s0,double dj) {
|
||||
int i;
|
||||
|
||||
if (J != wt->J) {
|
||||
@ -1378,7 +1386,7 @@ void setCWTPadding(cwt_object wt, int pad) {
|
||||
}
|
||||
}
|
||||
|
||||
void cwt(cwt_object wt, double *inp) {
|
||||
void cwt(cwt_object wt, const double *inp) {
|
||||
int i, N, npad,nj2,j,j2;
|
||||
N = wt->siglength;
|
||||
if (wt->sflag == 0) {
|
||||
@ -1772,251 +1780,251 @@ void idwpt(wpt_object wt, double *dwtop) {
|
||||
llb = 1;
|
||||
index2 = xlen / p;
|
||||
indexp = 0;
|
||||
if (wt->basisvector[0] == 1) {
|
||||
for (i = 0; i < wt->siglength; ++i) {
|
||||
dwtop[i] = wt->output[i];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < J; ++i) {
|
||||
llb *= 2;
|
||||
n1 += llb;
|
||||
}
|
||||
|
||||
for (i = 0; i < xlen; ++i) {
|
||||
X[i] = 0.0;
|
||||
}
|
||||
|
||||
for (i = 0; i < llb; ++i) {
|
||||
prep[i] = (int)wt->basisvector[n1 - llb + i];
|
||||
ptemp[i] = 0;
|
||||
}
|
||||
|
||||
if (!strcmp(wt->ext, "per")) {
|
||||
app_len = wt->length[0];
|
||||
det_len = wt->length[1];
|
||||
index = 0;
|
||||
|
||||
|
||||
for (i = 0; i < J; ++i) {
|
||||
p = ipow2(J - i - 1);
|
||||
det_len = wt->length[i + 1];
|
||||
index2 *= 2;
|
||||
index3 = 0;
|
||||
index4 = 0;
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
n1 -= llb;
|
||||
for (l = 0; l < llb; ++l) {
|
||||
if (ptemp[l] != 2) {
|
||||
prep[l] = (int)wt->basisvector[n1 + l];
|
||||
}
|
||||
else {
|
||||
prep[l] = ptemp[l];
|
||||
}
|
||||
ptemp[l] = 0;
|
||||
}
|
||||
|
||||
|
||||
for (l = 0; l < p; ++l) {
|
||||
if (prep[2 * l] == 1 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = wt->output[index + det_len + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += 2 * det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 1 && prep[2 * l + 1] == 2) {
|
||||
index4 += indexp;
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = X[index4 + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = wt->output[index + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 2) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = X[index4 + indexp + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index4 += 2 * indexp;
|
||||
index3 += index2;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else {
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
idwt_per(wt, out, det_len, wt->output + iter, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
out[k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
|
||||
iter += det_len;
|
||||
det_len = wt->length[i + 2];
|
||||
*/
|
||||
llb /= 2;
|
||||
indexp = index2;
|
||||
}
|
||||
|
||||
//free(X_lp);
|
||||
|
||||
}
|
||||
else if (!strcmp(wt->ext, "sym")) {
|
||||
app_len = wt->length[0];
|
||||
det_len = wt->length[1];
|
||||
N = 2 * wt->length[J] - 1;
|
||||
|
||||
//X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||
index = 0;
|
||||
|
||||
for (i = 0; i < J; ++i) {
|
||||
p = ipow2(J - i - 1);
|
||||
det_len = wt->length[i + 1];
|
||||
index2 *= 2;
|
||||
index3 = 0;
|
||||
index4 = 0;
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
n1 -= llb;
|
||||
for (l = 0; l < llb; ++l) {
|
||||
if (ptemp[l] != 2) {
|
||||
prep[l] = (int)wt->basisvector[n1 + l];
|
||||
}
|
||||
else {
|
||||
prep[l] = ptemp[l];
|
||||
}
|
||||
ptemp[l] = 0;
|
||||
}
|
||||
|
||||
|
||||
for (l = 0; l < p; ++l) {
|
||||
if (prep[2 * l] == 1 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = wt->output[index + det_len + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += 2 * det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 1 && prep[2 * l + 1] == 2) {
|
||||
index4 += indexp;
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = X[index4 + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = wt->output[index + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 2) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = X[index4 + indexp + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index4 += 2 * indexp;
|
||||
index3 += index2;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else {
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
/*
|
||||
idwpt_sym(wt, out, det_len, wt->output + iter, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
out[k - lf + 2] = X_lp[k];
|
||||
}
|
||||
|
||||
iter += det_len;
|
||||
det_len = wt->length[i + 2];
|
||||
*/
|
||||
llb /= 2;
|
||||
indexp = index2;
|
||||
}
|
||||
|
||||
//free(X_lp);
|
||||
|
||||
}
|
||||
else {
|
||||
printf("Signal extension can be either per or sym");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (i = 0; i < wt->siglength; ++i) {
|
||||
//printf("%g ", X[i]);
|
||||
dwtop[i] = X[i];
|
||||
}
|
||||
|
||||
if (wt->basisvector[0] == 1) {
|
||||
for (i = 0; i < wt->siglength; ++i) {
|
||||
dwtop[i] = wt->output[i];
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < J; ++i) {
|
||||
llb *= 2;
|
||||
n1 += llb;
|
||||
}
|
||||
|
||||
for (i = 0; i < xlen; ++i) {
|
||||
X[i] = 0.0;
|
||||
}
|
||||
|
||||
for (i = 0; i < llb; ++i) {
|
||||
prep[i] = (int)wt->basisvector[n1 - llb + i];
|
||||
ptemp[i] = 0;
|
||||
}
|
||||
|
||||
if (!strcmp(wt->ext, "per")) {
|
||||
app_len = wt->length[0];
|
||||
det_len = wt->length[1];
|
||||
index = 0;
|
||||
|
||||
|
||||
for (i = 0; i < J; ++i) {
|
||||
p = ipow2(J - i - 1);
|
||||
det_len = wt->length[i + 1];
|
||||
index2 *= 2;
|
||||
index3 = 0;
|
||||
index4 = 0;
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
n1 -= llb;
|
||||
for (l = 0; l < llb; ++l) {
|
||||
if (ptemp[l] != 2) {
|
||||
prep[l] = (int)wt->basisvector[n1 + l];
|
||||
}
|
||||
else {
|
||||
prep[l] = ptemp[l];
|
||||
}
|
||||
ptemp[l] = 0;
|
||||
}
|
||||
|
||||
|
||||
for (l = 0; l < p; ++l) {
|
||||
if (prep[2 * l] == 1 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = wt->output[index + det_len + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += 2 * det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 1 && prep[2 * l + 1] == 2) {
|
||||
index4 += indexp;
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = X[index4 + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = wt->output[index + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 2) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = X[index4 + indexp + k];
|
||||
}
|
||||
idwpt_per(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
X[index3 + k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
index4 += 2 * indexp;
|
||||
index3 += index2;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else {
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
idwt_per(wt, out, det_len, wt->output + iter, det_len, X_lp);
|
||||
for (k = lf / 2 - 1; k < 2 * det_len + lf / 2 - 1; ++k) {
|
||||
out[k - lf / 2 + 1] = X_lp[k];
|
||||
}
|
||||
|
||||
iter += det_len;
|
||||
det_len = wt->length[i + 2];
|
||||
*/
|
||||
llb /= 2;
|
||||
indexp = index2;
|
||||
}
|
||||
|
||||
//free(X_lp);
|
||||
|
||||
}
|
||||
else if (!strcmp(wt->ext, "sym")) {
|
||||
app_len = wt->length[0];
|
||||
det_len = wt->length[1];
|
||||
N = 2 * wt->length[J] - 1;
|
||||
|
||||
//X_lp = (double*)malloc(sizeof(double)* (N + 2 * lf - 1));
|
||||
index = 0;
|
||||
|
||||
for (i = 0; i < J; ++i) {
|
||||
p = ipow2(J - i - 1);
|
||||
det_len = wt->length[i + 1];
|
||||
index2 *= 2;
|
||||
index3 = 0;
|
||||
index4 = 0;
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
n1 -= llb;
|
||||
for (l = 0; l < llb; ++l) {
|
||||
if (ptemp[l] != 2) {
|
||||
prep[l] = (int)wt->basisvector[n1 + l];
|
||||
}
|
||||
else {
|
||||
prep[l] = ptemp[l];
|
||||
}
|
||||
ptemp[l] = 0;
|
||||
}
|
||||
|
||||
|
||||
for (l = 0; l < p; ++l) {
|
||||
if (prep[2 * l] == 1 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = wt->output[index + det_len + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += 2 * det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 1 && prep[2 * l + 1] == 2) {
|
||||
index4 += indexp;
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = wt->output[index + k];
|
||||
out2[k] = X[index4 + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 1) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = wt->output[index + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index += det_len;
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else if (prep[2 * l] == 2 && prep[2 * l + 1] == 2) {
|
||||
for (k = 0; k < det_len; ++k) {
|
||||
out[k] = X[index4 + k];
|
||||
out2[k] = X[index4 + indexp + k];
|
||||
}
|
||||
idwpt_sym(wt, out, det_len, out2, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
X[index3 + k - lf + 2] = X_lp[k];
|
||||
}
|
||||
index4 += 2 * indexp;
|
||||
index3 += index2;
|
||||
ptemp[l] = 2;
|
||||
}
|
||||
else {
|
||||
index3 += index2;
|
||||
index4 += 2 * indexp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//idwt1(wt, temp, cA_up, out, det_len, wt->output + iter, det_len, X_lp, X_hp, out);
|
||||
/*
|
||||
idwpt_sym(wt, out, det_len, wt->output + iter, det_len, X_lp);
|
||||
for (k = lf - 2; k < 2 * det_len; ++k) {
|
||||
out[k - lf + 2] = X_lp[k];
|
||||
}
|
||||
|
||||
iter += det_len;
|
||||
det_len = wt->length[i + 2];
|
||||
*/
|
||||
llb /= 2;
|
||||
indexp = index2;
|
||||
}
|
||||
|
||||
//free(X_lp);
|
||||
|
||||
}
|
||||
else {
|
||||
printf("Signal extension can be either per or sym");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (i = 0; i < wt->siglength; ++i) {
|
||||
//printf("%g ", X[i]);
|
||||
dwtop[i] = X[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2218,7 +2226,7 @@ static void swt_direct(wt_object wt, double *inp) {
|
||||
}
|
||||
|
||||
|
||||
void swt(wt_object wt, double *inp) {
|
||||
void swt(wt_object wt, const double *inp) {
|
||||
if (!strcmp(wt->method, "swt") && !strcmp(wt->cmethod, "direct") ) {
|
||||
swt_direct(wt,inp);
|
||||
}
|
||||
@ -2410,7 +2418,7 @@ static void modwt_per(wt_object wt, int M, double *inp, int N, double *cA, int l
|
||||
free(filt);
|
||||
}
|
||||
|
||||
void modwt(wt_object wt, double *inp) {
|
||||
void modwt(wt_object wt, const double *inp) {
|
||||
int i, J, temp_len, iter, M, N;
|
||||
int lenacc, len_filt;
|
||||
double *cA, *cD;
|
||||
@ -2536,7 +2544,7 @@ void imodwt(wt_object wt, double *dwtop) {
|
||||
free(X);
|
||||
}
|
||||
|
||||
void setDWTExtension(wt_object wt, char *extension) {
|
||||
void setDWTExtension(wt_object wt, const char *extension) {
|
||||
if (!strcmp(extension, "sym")) {
|
||||
strcpy(wt->ext, "sym");
|
||||
}
|
||||
@ -2549,7 +2557,7 @@ void setDWTExtension(wt_object wt, char *extension) {
|
||||
}
|
||||
}
|
||||
|
||||
void setWTREEExtension(wtree_object wt, char *extension) {
|
||||
void setWTREEExtension(wtree_object wt, const char *extension) {
|
||||
if (!strcmp(extension, "sym")) {
|
||||
strcpy(wt->ext, "sym");
|
||||
}
|
||||
@ -2562,7 +2570,7 @@ void setWTREEExtension(wtree_object wt, char *extension) {
|
||||
}
|
||||
}
|
||||
|
||||
void setDWPTExtension(wpt_object wt, char *extension) {
|
||||
void setDWPTExtension(wpt_object wt, const char *extension) {
|
||||
if (!strcmp(extension, "sym")) {
|
||||
strcpy(wt->ext, "sym");
|
||||
}
|
||||
@ -2575,7 +2583,7 @@ void setDWPTExtension(wpt_object wt, char *extension) {
|
||||
}
|
||||
}
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, char *entropy, double eparam) {
|
||||
void setDWPTEntropy(wpt_object wt, const char *entropy, double eparam) {
|
||||
if (!strcmp(entropy, "shannon")) {
|
||||
strcpy(wt->entropy, "shannon");
|
||||
}
|
||||
@ -2596,7 +2604,7 @@ void setDWPTEntropy(wpt_object wt, char *entropy, double eparam) {
|
||||
}
|
||||
}
|
||||
|
||||
void setWTConv(wt_object wt, char *cmethod) {
|
||||
void setWTConv(wt_object wt, const char *cmethod) {
|
||||
if (!strcmp(cmethod, "fft") || !strcmp(cmethod, "FFT")) {
|
||||
strcpy(wt->cmethod, "fft");
|
||||
}
|
||||
|
230
src/wavelib.h
230
src/wavelib.h
@ -1,230 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2014, Rafat Hussain
|
||||
*/
|
||||
#ifndef WAVELIB_H_
|
||||
#define WAVELIB_H_
|
||||
|
||||
#include "wtmath.h"
|
||||
#include "cwt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable : 4200)
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
#ifndef cplx_type
|
||||
#define cplx_type double
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct cplx_t {
|
||||
cplx_type re;
|
||||
cplx_type im;
|
||||
} cplx_data;
|
||||
|
||||
typedef struct wave_set* wave_object;
|
||||
|
||||
wave_object wave_init(char* wname);
|
||||
|
||||
struct wave_set{
|
||||
char wname[50];
|
||||
int filtlength;// When all filters are of the same length. [Matlab uses zero-padding to make all filters of the same length]
|
||||
int lpd_len;// Default filtlength = lpd_len = lpr_len = hpd_len = hpr_len
|
||||
int hpd_len;
|
||||
int lpr_len;
|
||||
int hpr_len;
|
||||
double *lpd;
|
||||
double *hpd;
|
||||
double *lpr;
|
||||
double *hpr;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wt_set* wt_object;
|
||||
|
||||
wt_object wt_init(wave_object wave,char* method, int siglength, int J);
|
||||
|
||||
struct wt_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
char method[10];
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
char cmethod[10]; // Convolution Method - "direct" or "FFT"
|
||||
|
||||
int N; //
|
||||
int cfftset;
|
||||
int zpad;
|
||||
int length[102];
|
||||
double *output;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wtree_set* wtree_object;
|
||||
|
||||
wtree_object wtree_init(wave_object wave, int siglength, int J);
|
||||
|
||||
struct wtree_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
char method[10];
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
|
||||
int N; //
|
||||
int nodes;
|
||||
int cfftset;
|
||||
int zpad;
|
||||
int length[102];
|
||||
double *output;
|
||||
int *nodelength;
|
||||
int *coeflength;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct wpt_set* wpt_object;
|
||||
|
||||
wpt_object wpt_init(wave_object wave, int siglength, int J);
|
||||
|
||||
struct wpt_set{
|
||||
wave_object wave;
|
||||
conv_object cobj;
|
||||
int siglength;// Length of the original signal.
|
||||
int outlength;// Length of the output DWT vector
|
||||
int lenlength;// Length of the Output Dimension Vector "length"
|
||||
int J; // Number of decomposition Levels
|
||||
int MaxIter;// Maximum Iterations J <= MaxIter
|
||||
int even;// even = 1 if signal is of even length. even = 0 otherwise
|
||||
char ext[10];// Type of Extension used - "per" or "sym"
|
||||
char entropy[20];
|
||||
double eparam;
|
||||
|
||||
int N; //
|
||||
int nodes;
|
||||
int length[102];
|
||||
double *output;
|
||||
double *costvalues;
|
||||
double *basisvector;
|
||||
int *nodeindex;
|
||||
int *numnodeslevel;
|
||||
int *coeflength;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
typedef struct cwt_set* cwt_object;
|
||||
|
||||
cwt_object cwt_init(char* wave, double param, int siglength,double dt, int J);
|
||||
|
||||
struct cwt_set{
|
||||
char wave[10];// Wavelet - morl/morlet,paul,dog/dgauss
|
||||
int siglength;// Length of Input Data
|
||||
int J;// Total Number of Scales
|
||||
double s0;// Smallest scale. It depends on the sampling rate. s0 <= 2 * dt for most wavelets
|
||||
double dt;// Sampling Rate
|
||||
double dj;// Separation between scales. eg., scale = s0 * 2 ^ ( [0:N-1] *dj ) or scale = s0 *[0:N-1] * dj
|
||||
char type[10];// Scale Type - Power or Linear
|
||||
int pow;// Base of Power in case type = pow. Typical value is pow = 2
|
||||
int sflag;
|
||||
int pflag;
|
||||
int npad;
|
||||
int mother;
|
||||
double m;// Wavelet parameter param
|
||||
double smean;// Input Signal mean
|
||||
|
||||
cplx_data *output;
|
||||
double *scale;
|
||||
double *period;
|
||||
double *coi;
|
||||
double params[0];
|
||||
};
|
||||
|
||||
|
||||
void dwt(wt_object wt, double *inp);
|
||||
|
||||
void idwt(wt_object wt, double *dwtop);
|
||||
|
||||
void wtree(wtree_object wt, double *inp);
|
||||
|
||||
void dwpt(wpt_object wt, double *inp);
|
||||
|
||||
void idwpt(wpt_object wt, double *dwtop);
|
||||
|
||||
void swt(wt_object wt, double *inp);
|
||||
|
||||
void iswt(wt_object wt, double *swtop);
|
||||
|
||||
void modwt(wt_object wt, double *inp);
|
||||
|
||||
void imodwt(wt_object wt, double *dwtop);
|
||||
|
||||
void setDWTExtension(wt_object wt, char *extension);
|
||||
|
||||
void setWTREEExtension(wtree_object wt, char *extension);
|
||||
|
||||
void setDWPTExtension(wpt_object wt, char *extension);
|
||||
|
||||
void setDWPTEntropy(wpt_object wt, char *entropy, double eparam);
|
||||
|
||||
void setWTConv(wt_object wt, char *cmethod);
|
||||
|
||||
int getWTREENodelength(wtree_object wt, int X);
|
||||
|
||||
void getWTREECoeffs(wtree_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
int getDWPTNodelength(wpt_object wt, int X);
|
||||
|
||||
void getDWPTCoeffs(wpt_object wt, int X, int Y, double *coeffs, int N);
|
||||
|
||||
void setCWTScales(cwt_object wt, double s0, double dj, char *type, int power);
|
||||
|
||||
void setCWTScaleVector(cwt_object wt, double *scale, int J, double s0, double dj);
|
||||
|
||||
void setCWTPadding(cwt_object wt, int pad);
|
||||
|
||||
void cwt(cwt_object wt, double *inp);
|
||||
|
||||
void icwt(cwt_object wt, double *cwtop);
|
||||
|
||||
int getCWTScaleLength(int N);
|
||||
|
||||
void wave_summary(wave_object obj);
|
||||
|
||||
void wt_summary(wt_object wt);
|
||||
|
||||
void wtree_summary(wtree_object wt);
|
||||
|
||||
void wpt_summary(wpt_object wt);
|
||||
|
||||
void cwt_summary(cwt_object wt);
|
||||
|
||||
void wave_free(wave_object object);
|
||||
|
||||
void wt_free(wt_object object);
|
||||
|
||||
void wtree_free(wtree_object object);
|
||||
|
||||
void wpt_free(wpt_object object);
|
||||
|
||||
void cwt_free(cwt_object object);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* WAVELIB_H_ */
|
Loading…
x
Reference in New Issue
Block a user