void Scwt_squeezed(float *input, double *squeezed_r, double *squeezed_i, int *pnboctave, int *pnbvoice, int *pinputsize, float *pcenterfrequency) { int nboctave, nbvoice, i, j, inputsize, bigsize; float centerfrequency, a; double *Ri2, *Ri1, *Ii1, *Ii2, *Rdi2, *Idi2, *Ii, *Ri; double *Oreal, *Oimage, *Odreal, *Odimage; centerfrequency = *pcenterfrequency; nboctave = *pnboctave; nbvoice = *pnbvoice; inputsize = *pinputsize; bigsize = inputsize*nbvoice*nboctave; /* Memory allocations ------------------*/ if(!(Oreal = (double *)calloc(bigsize, sizeof(double)))) error("Memory allocation failed for Ri1 in cwt_phase.c \n"); if(!(Oimage = (double *)calloc(bigsize, sizeof(double)))) error("Memory allocation failed for Ii1 in cwt_phase.c \n"); if(!(Odreal = (double *)calloc(bigsize, sizeof(double)))) error("Memory allocation failed for Ri1 in cwt_phase.c \n"); if(!(Odimage = (double *)calloc(bigsize, sizeof(double)))) error("Memory allocation failed for Ii1 in cwt_phase.c \n"); if(!(Ri1 = (double *)calloc(inputsize, sizeof(double)))) error("Memory allocation failed for Ri1 in cwt_phase.c \n"); if(!(Ii1 = (double *)calloc(inputsize, sizeof(double)))) error("Memory allocation failed for Ii1 in cwt_phase.c \n"); if(!(Ii2 = (double *)calloc(inputsize,sizeof(double)))) error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Ri2 = (double *)calloc(inputsize,sizeof(double)))) error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Idi2 = (double *)calloc(inputsize,sizeof(double)))) error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Rdi2 = (double *)calloc(inputsize,sizeof(double)))) error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Ri = (double *)calloc(inputsize, sizeof(double)))) error("Memory allocation failed for Ri in cwt_phase.c \n"); if(!(Ii = (double *)calloc(inputsize, sizeof(double)))) error("Memory allocation failed for Ii in cwt_phase.c \n"); for(i = 0; i < inputsize; i++){ *Ri = (double)(*input); Ri++; input++; } Ri -= inputsize; input -= inputsize; /* Compute fft of the signal -------------------------*/ double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1); /* Multiply signal and wavelets in the Fourier space -------------------------------------------------*/ for(i = 1; i <= nboctave; i++) { for(j=0; j < nbvoice; j++) { a = (float)(pow((double)2,(double)(i+j/((double)nbvoice)))); morlet_frequencyph(centerfrequency,a,Ri2,Idi2,inputsize); multiply(Ri1,Ii1,Ri2,Ii2,Oreal,Oimage,inputsize); multiply(Ri1,Ii1,Rdi2,Idi2,Odreal,Odimage,inputsize); double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); double_fft(Odreal,Odimage,Odreal,Odimage,inputsize,1); Oreal += inputsize; Oimage += inputsize; Odreal += inputsize; Odimage += inputsize; } } Oreal -= bigsize; Odreal -= bigsize; Oimage -= bigsize; Odimage -= bigsize; free((char *)Ri2); free((char *)Ri1); free((char *)Ii1); free((char *)Ii2); free((char *)Ri); free((char *)Ii); /* Normalize the cwt and compute the squeezed transform ----------------------------------------------------*/ normalization(Oreal, Oimage, Odreal, Odimage, bigsize); w_reassign(Oreal, Oimage, Odreal, Odimage, squeezed_r, squeezed_i, centerfrequency,inputsize, nbvoice, nboctave); return; }
void Scwt_phase(double *input, double *Oreal, double *Oimage, double *f, int *pnboctave, int *pnbvoice, int *pinputsize, double *pcenterfrequency) { int nboctave, nbvoice, i, j, inputsize; double centerfrequency, a; double *Ri2, *Ri1, *Ii1, *Ii2, *Rdi2, *Idi2, *Ii, *Ri; double *Odreal, *Odimage; centerfrequency = *pcenterfrequency; nboctave = *pnboctave; nbvoice = *pnbvoice; inputsize = *pinputsize; /* Memory allocations -- is the original use of calloc significant?? Using S_alloc to initialize mem, just in case. note by xian ------------------*/ if(!(Odreal = (double *) S_alloc(inputsize*nbvoice*nboctave, sizeof(double)))) Rf_error("Memory allocation failed for Ri1 in cwt_phase.c \n"); if(!(Odimage = (double *) S_alloc(inputsize*nbvoice*nboctave, sizeof(double)))) Rf_error("Memory allocation failed for Ii1 in cwt_phase.c \n"); if(!(Ri1 = (double *) S_alloc(inputsize, sizeof(double)))) Rf_error("Memory allocation failed for Ri1 in cwt_phase.c \n"); if(!(Ii1 = (double *) S_alloc(inputsize, sizeof(double)))) Rf_error("Memory allocation failed for Ii1 in cwt_phase.c \n"); if(!(Ii2 = (double *) S_alloc(inputsize,sizeof(double)))) Rf_error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Ri2 = (double *) S_alloc(inputsize,sizeof(double)))) Rf_error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Idi2 = (double *) S_alloc(inputsize,sizeof(double)))) Rf_error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Rdi2 = (double *) S_alloc(inputsize,sizeof(double)))) Rf_error("Memory allocation failed for Ri2 in cwt_phase.c \n"); if(!(Ri = (double *) S_alloc(inputsize, sizeof(double)))) Rf_error("Memory allocation failed for Ri in cwt_phase.c \n"); if(!(Ii = (double *) S_alloc(inputsize, sizeof(double)))) Rf_error("Memory allocation failed for Ii in cwt_phase.c \n"); for(i = 0; i < inputsize; i++){ *Ri = (double)(*input); Ri++; input++; } Ri -= inputsize; input -= inputsize; /* Compute fft of the signal -------------------------*/ double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1); /* Multiply signal and wavelets in the Fourier space -------------------------------------------------*/ for(i = 1; i <= nboctave; i++) { for(j=0; j < nbvoice; j++) { a = (double)(pow((double)2,(double)(i+j/((double)nbvoice)))); morlet_frequencyph(centerfrequency,a,Ri2,Idi2,inputsize); multiply(Ri1,Ii1,Ri2,Ii2,Oreal,Oimage,inputsize); multiply(Ri1,Ii1,Rdi2,Idi2,Odreal,Odimage,inputsize); double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); double_fft(Odreal,Odimage,Odreal,Odimage,inputsize,1); Oreal += inputsize; Oimage += inputsize; Odreal += inputsize; Odimage += inputsize; } } Oreal -= inputsize*nbvoice*nboctave; Odreal -= inputsize*nbvoice*nboctave; Oimage -= inputsize*nbvoice*nboctave; Odimage -= inputsize*nbvoice*nboctave; /* Normalize the cwt and compute the f function --------------------------------------------*/ normalization(Oreal, Oimage, Odreal, Odimage, inputsize*nbvoice*nboctave); f_function(Oreal, Oimage, Odreal, Odimage, f, centerfrequency,inputsize,nbvoice,nboctave); return; }