void DiscretePeriodicWavelet::makeTransform()
{
    m_flag.clear();
    m_length.clear();
    m_transformedSignal.clear();
    m_outputSignal.clear();

    if (m_inputSignal.empty()) {
        return;
    }

    dwt(m_inputSignal, m_level, toStdString(m_waveletFunction), m_transformedSignal, m_flag, m_length);
}
void spec_template::sample_log_fwhh_re(size_t t)
{
    double log_fwhh_re_prop;
    double logratio = 0;

    log_fwhh_re_prop=my_normrnd(FTems[t].log_fwhh_re_draw, sqrt(pars.log_fwhh_re_prop_var), rng);

    matrix Lprop (L);

    vector<double> decon(pars.p,0.0);

    FTems[t].build_curve_fwhh_re_prop(pars.x, log_fwhh_re_prop, log_fwhh_draw, pars.freq);

    if(WAVELETS)
	{
	    dwt(FTems[t].curve_prop,pars.nlev, pars.h_vec, decon); 
        Lprop[t] = decon;
	}
    else
    {
		Lprop[t] = FTems[t].curve_prop;    
	}

    logratio = calculate_metropolis_ratio_eta_local(&Lprop);
    
    double logprior=0.0;
  
    logprior+=normlogpdf(log_fwhh_re_prop, 0.0, sqrt(pars.log_fwhh_re_prior_var));
    logprior-=normlogpdf(FTems[t].log_fwhh_re_draw, 0.0, sqrt(pars.log_fwhh_re_prior_var));
    
    //logratio
    //proposal
    //cancels out
    logratio+=logprior;
  
    //logproposal
    double logacceptance=log(my_rand(rng));

    if(logratio>logacceptance)
    {
      FTems[t].prop_accept_log_fwhh_re(log_fwhh_re_prop);
      shape_accepcount=shape_accepcount+1;
      L[t]=Lprop[t];
      FTems[t].log_fwhh_re_draw=log_fwhh_re_prop;
    }
    
}
示例#3
0
void spec_template::sample_log_fwhh()
{
    double log_fwhh_prop;
    double logratio = 0;  
    
    log_fwhh_prop=my_normrnd(log_fwhh_draw, sqrt(pars.log_fwhh_prop_var), rng);

    matrix Lprop (L);

    vector<double> decon(pars.p,0.0);

    for (int t = 0; t < pars.l; t++)
    { 
      FTems[t].build_curve(pars.x,log_fwhh_prop, pars.freq);

      if(WAVELETS)
	  {
    	  dwt(FTems[t].curve_prop,pars.nlev, pars.h_vec, decon); 
    	  Lprop[t] = decon;
	  }
      else
	  {
		  Lprop[t] = FTems[t].curve_prop;
	  }
    }
   
    logratio = calculate_metropolis_ratio_eta_local(&Lprop);
    
    double logprior=0.0;
    logprior+=normlogpdf(log_fwhh_prop, pars.log_fwhh_prior_mean, sqrt(pars.log_fwhh_prior_var));
    logprior-=normlogpdf(log_fwhh_draw, pars.log_fwhh_prior_mean, sqrt(pars.log_fwhh_prior_var));

    logratio+=logprior;
    
    //logproposal
    double logacceptance=log(my_rand(rng));
    if(logratio>logacceptance)
    {
        for (int t = 0; t < pars.l; t++)
		{
	       FTems[t].prop_accept_log_fwhh();
		}
        shape_accepcount=shape_accepcount+1;
        L=Lprop;
        log_fwhh_draw=log_fwhh_prop;
    }
}
示例#4
0
template <typename T> cl_int DWTKernel<T>::run(cl_mem in, cl_mem out, int sizeX, int sizeY, int levels){
	srcMem = in;
	dstMem = out;
	dimX = sizeX;
	dimY = sizeY;

	cl_int error_code = clSetKernelArg(myKernel, 3, sizeof(cl_mem), &srcMem);
	if (CL_SUCCESS != error_code)
	{
		LogError("Error: clSetKernelArg returned %s.\n", TranslateOpenCLError(error_code));
		return error_code;
	}
	error_code = clSetKernelArg(myKernel, 4, sizeof(cl_mem), &dstMem);
	if (CL_SUCCESS != error_code)
	{
		LogError("Error: clSetKernelArg returned %s.\n", TranslateOpenCLError(error_code));
		return error_code;
	}
	dwt(sizeX, sizeY, levels);
	return CL_SUCCESS;
}
示例#5
0
int main() {
	wave_object obj;
	wt_object wt;
	double *inp,*out,*diff;
	int N, i,J;

	FILE *ifp;
	double temp[1200];

	char *name = "db4";
	obj = wave_init(name);// Initialize the wavelet

	ifp = fopen(FILE_SIGNAL, "r");
	i = 0;
	if (!ifp) {
		printf("Cannot Open File");
		exit(100);
	}
	while (!feof(ifp)) {
		fscanf(ifp, "%lf \n", &temp[i]);
		i++;
	}
	N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	diff = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
		inp[i] = temp[i];
		//printf("%g \n",inp[i]);
	}
	J = 3;

	wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
	setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
	setWTConv(wt, "direct");
	
	dwt(wt, inp);// Perform DWT
	//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
	
	for (i = 0; i < wt->outlength; ++i) {
	//	printf("%g ",wt->output[i]);
	}
	
	idwt(wt, out);// Perform IDWT (if needed)
	// Test Reconstruction
	for (i = 0; i < wt->siglength; ++i) {
		diff[i] = out[i] - inp[i];
	}
	
	printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
	
	wt_summary(wt);// Prints the full summary.
	wave_free(obj);
	wt_free(wt);

	free(inp);
	free(out);
	free(diff);
	return 0;
}
示例#6
0
void ReconstructionTest()
{

	wave_object obj;
	wt_object wt;
	double *inp,*out;
	int N, i,J;
    double epsilon = 1e-15;
    char *type = (char*) "dwt";

    N = 79926;
    
    //N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
        inp[i] = (rand() / (double)(RAND_MAX));
	}
    std::vector<std::string > waveletNames;

    for (unsigned int j = 0; j < 36; j++)
    {
        waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
    }
    for (unsigned int j = 0; j < 17; j++)
    {
        waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
    }
    for (unsigned int j = 1; j < 20; j++)
    {
        waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
    }
    
    waveletNames.push_back("bior1.1");
    waveletNames.push_back("bior1.3");
    waveletNames.push_back("bior1.5");
    waveletNames.push_back("bior2.2");
    waveletNames.push_back("bior2.4");
    waveletNames.push_back("bior2.6");
    waveletNames.push_back("bior2.8");
    waveletNames.push_back("bior3.1");
    waveletNames.push_back("bior3.3");
    waveletNames.push_back("bior3.5");
    waveletNames.push_back("bior3.7");
    waveletNames.push_back("bior3.9");
    waveletNames.push_back("bior4.4");
    waveletNames.push_back("bior5.5");
    waveletNames.push_back("bior6.8");
    
    waveletNames.push_back("rbior1.1");
    waveletNames.push_back("rbior1.3");
    waveletNames.push_back("rbior1.5");
    waveletNames.push_back("rbior2.2");
    waveletNames.push_back("rbior2.4");
    waveletNames.push_back("rbior2.6");
    waveletNames.push_back("rbior2.8");
    waveletNames.push_back("rbior3.1");
    waveletNames.push_back("rbior3.3");
    waveletNames.push_back("rbior3.5");
    waveletNames.push_back("rbior3.7");
    waveletNames.push_back("rbior3.9");
    waveletNames.push_back("rbior4.4");
    waveletNames.push_back("rbior5.5");
    waveletNames.push_back("rbior6.8");

    for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
    {
        for (unsigned int sym_per = 0; sym_per < 2; sym_per++)
        {
            for (unsigned int j = 0; j < waveletNames.size(); j++)
            {
                char * name = new char[waveletNames[j].size() + 1];
                memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
                obj = wave_init(name);// Initialize the wavelet
                for (J = 1; J < 3; J++)
                {
                    //J = 3;

                    wt = wt_init(obj,(char*) "dwt", N, J);// Initialize the wavelet transform object
                    if (sym_per == 0)
                        setDWTExtension(wt, (char*) "sym");// Options are "per" and "sym". Symmetric is the default option
                    else
                        setDWTExtension(wt, (char*) "per");
                    if (direct_fft == 0)
                        setWTConv(wt, (char*) "direct");
                    else
                        setWTConv(wt, (char*) "fft");

                    dwt(wt, inp);// Perform DWT

                    idwt(wt, out);// Perform IDWT (if needed)
                    // Test Reconstruction

                    if (direct_fft == 0)
                        epsilon = 1e-8;
                    else
                        epsilon = 1e-10;
                    //BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
                    
					//printf("%g ",RMS_Error(out, inp, wt->siglength));
					if (RMS_Error(out, inp, wt->siglength) > epsilon) {
						printf("\n ERROR : DWT Reconstruction Unit Test Failed. Exiting. \n");
						exit(-1);
					}
                    wt_free(wt);
                }
                wave_free(obj);
                delete[] name;
            }
        }
    }
    
	free(out);
    free(inp);
}