This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/SW-EK-TM4C1294XL: 1-D Fast Wavelet Transform Algorithm

Part Number: SW-EK-TM4C1294XL

Tool/software: Code Composer Studio

I was sampling a Hanning pulse from a  PWT sensor. I needed to take a wavelet transform of the sampled waveform. I wrote a very basic code using for loops for implementing the 1-D continuous wavelet trasnform by multiplying the scaled adn time shifted wavelets. But the code is very slow and takes about 20 mins to find the Wavelet transform. The wavelet that I am using for 1-D CWT is Morlet wavelet. Is there a better algorithm for implementing the wavelet transform. If yes is a sample code availabe or some references in which they have explained the algorithm. Is there any library that can perfom1-D wavelet transform? 

I have attached the function that I have written. The array g_ui8RxBufA[] contains the sampled waveform from ADC.

void CWT(uint32_t scale)
{
    uint32_t p,j,k,l;
    for(l = 0; l < 512; l++)
      {
    		signal[l] =  (float32_t)g_ui8RxBufA[l] * (3.3/4096.0);
      }

	for( p=1;p<=scale;p++)
    {
        for( j=0;j<CWT_LENGTH;j++)
        {
            for( k=0;k<CWT_LENGTH;k++)
            {
            	cos_1 = cos(5*((k-j)/p));
            	sqrt_1 = sqrt(p);
            	temp_p = (float32_t)p;
            	temp = (-1*((k-j)/temp_p)*((k-j)/temp_p))/2;
            	exp_1 = exp(temp);
            	temp_wavelet = exp_1*cos_1/sqrt_1;
                coefs[p-1][j] = coefs[p-1][j] + signal[k]*temp_wavelet;
            }
        }
    }
}

Thanks for the help!

  • Your question is very application specific. Make sure you are using the hardware floating point support and high levels of C compiler optimization. (The default is hardware floating point and optimization level 2.) I have no suggestions for algorithms.
  • In addition to what Bob said about enabling use of hardware floating point support, the Cortex-M4F only supports single-precision (32-bit) hardware floating point. Double-precision (64-bit) floating point calculations have to be performed with slower software floating point.

    Your code fragment implicitly uses some double-precision calculations since:

    a) Unsuffixed floating point constants such as "3.3" are implicitly double-precision.

    b) Calls the cos, sqrt and exp maths functions which take double-precision arguments.

    The code can be changed to perform single-precision calculations for increased speed, but at reduced accuracy, by:

    a) Adding a "f" suffix to floating point constants.

    b) Calling the cosf, sqrtf and expf maths functions which take single-precision arguments.

    I.e. a suggested code change is:

    void CWT(uint32_t scale)
    {
        uint32_t p,j,k,l;
        for(l = 0; l < 512; l++)
          {
        		signal[l] =  (float32_t)g_ui8RxBufA[l] * (3.3f/4096.0f);
          }
    
    	for( p=1;p<=scale;p++)
        {
            for( j=0;j<CWT_LENGTH;j++)
            {
                for( k=0;k<CWT_LENGTH;k++)
                {
                	cos_1 = cosf(5*((k-j)/p));
                	sqrt_1 = sqrtf(p);
                	temp_p = (float32_t)p;
                	temp = (-1*((k-j)/temp_p)*((k-j)/temp_p))/2;
                	exp_1 = expf(temp);
                	temp_wavelet = exp_1*cos_1/sqrt_1;
                    coefs[p-1][j] = coefs[p-1][j] + signal[k]*temp_wavelet;
                }
            }
        }
    }