示例#1
0
void Svwt_thierry(double *Rinput,double *Iinput,double *Oreal,
   double *Oimage,double *pa,int *pinputsize,
   int *pM)
{	
  int octave, voice, nbvoice, i, j, k, inputsize, M;
  double a;
  double *Ri2, *Ri1, *Ii1, *Ii, *Ri;


  M = *pM;
  a = *pa;
  inputsize = *pinputsize;
  if(!(Ri2 = (double *) R_alloc((size_t) inputsize, sizeof(double) )))
    error("Memory allocation failed for Ri2 in cwt_morlet.c \n");
  if(!(Ri1 = (double *) R_alloc((size_t) inputsize, sizeof(double) )))
    error("Memory allocation failed for Ri1 in cwt_morlet.c \n");
  if(!(Ii1 = (double *) R_alloc((size_t) inputsize, sizeof(double) )))
    error("Memory allocation failed for Ii1 in cwt_morlet.c \n");
  if(!(Ri = (double *) R_alloc((size_t) inputsize, sizeof(double) )))
    error("Memory allocation failed for Ri in cwt_morlet.c \n");
  if(!(Ii = (double *) R_alloc((size_t) inputsize, sizeof(double) )))
    error("Memory allocation failed for Ii in cwt_morlet.c \n");

  for(i = 0; i < inputsize; i++) {
    Ri[i] = (double)Rinput[i]; 
    Ii[i] = (double)Iinput[i];
  }

  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  thierry_frequency(M,a,Ri2,inputsize); 
  multi(Ri1,Ii1,Ri2,Oreal,Oimage,inputsize);
  double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,2); 
  
}
示例#2
0
文件: cwt_morlet.c 项目: cran/Rwave
void Svwt_morlet(double *Rinput,double *Iinput,double *Oreal,
   double *Oimage,double *pa,int *pinputsize,
   double *pcenterfrequency)
{	
  int  i,  inputsize;
  double centerfrequency, a;
  double *Ri2, *Ri1, *Ii1, *Ii, *Ri;


  centerfrequency = *pcenterfrequency;
  a = *pa;
  inputsize = *pinputsize;
  if(!(Ri2 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri2 in cwt_morlet.c \n");
  if(!(Ri1 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri1 in cwt_morlet.c \n");
  if(!(Ii1 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ii1 in cwt_morlet.c \n");
  if(!(Ri = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri in cwt_morlet.c \n");
  if(!(Ii = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ii in cwt_morlet.c \n");

  for(i = 0; i < inputsize; i++) {
    Ri[i] = (double)Rinput[i]; 
    Ii[i] = (double)Iinput[i];
  }

  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  morlet_frequency(centerfrequency,a,Ri2,inputsize); 
  multi(Ri1,Ii1,Ri2,Oreal,Oimage,inputsize);
  double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); 
  
}
示例#3
0
void Scwt_thierry(float *Rinput,float *Iinput,double *Oreal,
   double *Oimage,int *pnboctave,int *pnbvoice,
   int *pinputsize,int *pM)
{	
  int nboctave, nbvoice, i, j, k, inputsize, M;
  float a; /* wavelet scale? */
  double *Ri2, *Ri1, *Ii1, *Ii, *Ri;


  M = *pM;
  nboctave = *pnboctave;
  nbvoice = *pnbvoice;
  inputsize = *pinputsize;

  /********* edit by xian,  Mon 14 Dec 2009 09:19:33 PM MST ****** 
  Changing from malloc(sizeof(double) * inputsize) to R_alloc()
  ******************** edit by xian *****/
  if(!(Ri2 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri2 in cwt_thierry.c \n");
  if(!(Ri1 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri1 in cwt_thierry.c \n");
  if(!(Ii1 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ii1 in cwt_thierry.c \n");
  if(!(Ri = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri in cwt_thierry.c \n");
  if(!(Ii = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ii in cwt_thierry.c \n");

  for(i = 0; i < inputsize; i++) {
    Ri[i] = (double)Rinput[i]; 
    Ii[i] = (double)Iinput[i];
  }

  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  for(i = 1; i <= nboctave; i++) {
    for(j=0; j < nbvoice; j++) {
      a = (float)(pow((double)2,(double)(i+j/((double)nbvoice))));
      thierry_frequency(M,a,Ri2,inputsize); 
      multi(Ri1,Ii1,Ri2,Oreal,Oimage,inputsize);
      double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); 
      Oreal = Oreal + inputsize;
      Oimage = Oimage + inputsize;  
    }
  }

  /********* edit by xian,  Mon 14 Dec 2009 09:19:33 PM MST ****** 
  free((char *)Ri2);
  free((char *)Ri1);
  free((char *)Ii1);
  free((char *)Ri);
  free((char *)Ii);
  ******************** edit by xian *****/
}
示例#4
0
void Scwt_thierry_r(float *input, double *Oreal, double *Oimage,
   int *pnboctave, int *pnbvoice, int *pinputsize, int *pM)
{	
  int nboctave, nbvoice, i, j, inputsize, M;
  float a;
  double *Ri2, *Ri1, *Ii1, *Ii, *Ri;


  M= *pM;
  nboctave = *pnboctave;
  nbvoice = *pnbvoice;
  inputsize = *pinputsize;

  if(!(Ri2 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri2 in cwt_thierry.c \n");
  if(!(Ri1 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri1 in cwt_thierry.c \n");
  if(!(Ii1 = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ii1 in cwt_thierry.c \n");
  if(!(Ri = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ri in cwt_thierry.c \n");
  if(!(Ii = (double *) R_alloc(inputsize, sizeof(double)) ))
    error("Memory allocation failed for Ii in cwt_thierry.c \n");

  for(i = 0; i < inputsize; i++) {
    Ri[i] = (double)input[i]; 
    Ii[i] = 0.0;
  }

  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  for(i = 1; i <= nboctave; i++) {
    for(j=0; j < nbvoice; j++) {
      a = (float)(pow((double)2,(double)(i+j/((double)nbvoice))));
      thierry_frequency(M,a,Ri2,inputsize); 
      multi(Ri1,Ii1,Ri2,Oreal,Oimage,inputsize);
      double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); 
      Oreal = Oreal + inputsize;
      Oimage = Oimage + inputsize;  
    }
  }

  return;
}
示例#5
0
文件: cwt_morlet.c 项目: cran/Rwave
void Scwt_morlet(double *Rinput,double *Iinput,double *Oreal,
   double *Oimage,int *pnboctave,int *pnbvoice,
   int *pinputsize,double *pcenterfrequency)
{	
  int nboctave, nbvoice, i, j, inputsize;
  double centerfrequency, a;
  double *Ri2, *Ri1, *Ii1, *Ii, *Ri;


  centerfrequency = *pcenterfrequency;
  nboctave = *pnboctave;
  nbvoice = *pnbvoice;
  inputsize = *pinputsize;
  if(!(Ri2 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri2 in cwt_morlet.c \n");
  if(!(Ri1 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri1 in cwt_morlet.c \n");
  if(!(Ii1 = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ii1 in cwt_morlet.c \n");
  if(!(Ri = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ri in cwt_morlet.c \n");
  if(!(Ii = (double *) R_alloc(inputsize, sizeof(double) )))
    Rf_error("Memory allocation failed for Ii in cwt_morlet.c \n");

  for(i = 0; i < inputsize; i++) {
    Ri[i] = (double)Rinput[i]; 
    Ii[i] = (double)Iinput[i];
  }

  double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);   
  
  for(i = 1; i <= nboctave; i++) {
    for(j=0; j < nbvoice; j++) {
      a = (double)(pow((double)2,(double)(i+j/((double)nbvoice))));
      morlet_frequency(centerfrequency,a,Ri2,inputsize); 
      multi(Ri1,Ii1,Ri2,Oreal,Oimage,inputsize);
      double_fft(Oreal,Oimage,Oreal,Oimage,inputsize,1); 
      Oreal = Oreal + inputsize;
      Oimage = Oimage + inputsize;  
    }
  }

}
示例#6
0
文件: cwt_phase.c 项目: rforge/rwave
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;

}
示例#7
0
文件: cwt_phase.c 项目: cran/Rwave
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;
}
示例#8
0
文件: wv.c 项目: rforge/rwave
/***********************************************************
*  Function: WV:
*  ---------
*      Continuous Wigner-Ville transform.
*
*   input: input signal
*   Oreal, Oimage: Wigner Ville transform
*                  (real and imaginary parts)
*   pinputsize: signal size
*   pnbfreq: Number of values for the frequency
*   pfreqstep: frequency step
*
***********************************************************/
void WV(double *input,double *Oreal,double *Oimage,int *pnbfreq,
        double *pfreqstep,int *pinputsize)
{
    int nbfreq, i, p, k, ii, inputsize, locsize;
    double freqstep, frequency;
    double *Ri1, *Ii1, *Ii, *Ri, *tmpreal, *tmpimage;


    /* Initialization of S variables */
    nbfreq = *pnbfreq;
    freqstep = *pfreqstep;
    inputsize = *pinputsize;
    locsize = 2*inputsize;

    /* Memory allocation */
    if(!(Ri = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for Ri in WV.c \n");
    if(!(Ii = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for Ii in WV.c \n");

    if(!(Ri1 = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for Ri1 in WV.c \n");
    if(!(Ii1 = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for Ii1 in WV.c \n");

    if(!(tmpreal = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for tmpreal in WV.c \n");
    if(!(tmpimage = (double *)S_alloc(locsize, sizeof(double))))
        error("Memory allocation failed for tmpimage in WV.c \n");

    /* Load signal for FFT */
    for(i = 0; i < inputsize; i++) {
        *Ri = (double)(*input);
        Ri++;
        input++;
    }
    Ri -= inputsize;
    input -= inputsize;

    /* Compute short FFT of the signal */
    double_fft(Ri1,Ii1,Ri,Ii,inputsize,-1);

    /* Interpolate and analytize */
    for(i=1+3*inputsize/2; i<locsize; i++) {
        /* Ri1[i] = 2. * Ri1[i-inputsize];*/
        Ri1[i] = 0.0;
        /* Ii1[i] = 2. * Ii1[i-inputsize]; */
        Ii1[i] = 0.0;
    }
    for(i=1+inputsize/2; i<locsize; i++) {
        Ri1[i] = 0.0;
        Ii1[i] = 0.0;
    }
    Ri1[3*inputsize/2] = 0.0;
    Ii1[3*inputsize/2] = 0.0;

    /* compute long inverse FFT */
    double_fft(Ri,Ii,Ri1,Ii1,locsize,1);

    /* Compute Wigner transform */

    for(p = 0; p < inputsize; p++) {
        WV_mult(p,Ri,Ii,tmpreal,tmpimage,locsize);
        double_fft(tmpreal,tmpimage,tmpreal,tmpimage,locsize,-1);

        for(k=0; k<inputsize; k++) {
            Oreal[p+k*inputsize] = tmpreal[2*k];
            Oimage[p+k*inputsize] = tmpimage[2*k];
        }

    }


    return;
}