示例#1
0
/* complex IFFT ----------------------------------------------------------------
* cpx=ifft(cpx)
* args   : fftwf_plan plan  I   fftw plan (NULL: create new plan)
*          cpx_t  *cpx      I/O input/output complex data
*          int    n         I   number of input/output data
* return : none
*-----------------------------------------------------------------------------*/
extern void cpxifft(fftwf_plan plan, cpx_t *cpx, int n)
{
    if (plan==NULL) {
        mlock(hfftmtx); 
        fftwf_plan_with_nthreads(NFFTTHREAD); /* fft execute in multi threads */
        plan=fftwf_plan_dft_1d(n,cpx,cpx,FFTW_BACKWARD,FFTW_ESTIMATE);
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
        fftwf_destroy_plan(plan);
        unmlock(hfftmtx);
    } else {
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
    }
}
示例#2
0
文件: fftw_fft.c 项目: KL-Yang/fft
void fftw1d_c2c(fftwplan_h h, complex float *pi, int idist, int nmemb, 
        complex float *po, int odist, int repeat, int flag)
{
    fftwplan_t *t = (fftwplan_t*)h;
    if(flag>0) {
        for(int i=0; i<repeat; i++) 
            for(int j=0; j<nmemb; j++) 
                fftwf_execute_dft(t->fwd, (fftwf_complex*)(pi+j*idist), 
                        (fftwf_complex*)(po+j*odist));
    } else {
        for(int i=0; i<repeat; i++) 
            for(int j=0; j<nmemb; j++) 
                fftwf_execute_dft(t->rvs, (fftwf_complex*)(pi+j*idist), 
                        (fftwf_complex*)(po+j*odist));
    }
}
示例#3
0
/* complex FFT -----------------------------------------------------------------
* cpx=fft(cpx)
* args   : fftwf_plan plan  I   fftw plan (NULL: create new plan)
*          cpx_t  *cpx      I/O input/output complex data
*          int    n         I   number of input/output data
* return : none
*-----------------------------------------------------------------------------*/
extern void cpxfft(fftwf_plan plan, cpx_t *cpx, int n)
{
#ifdef FFTMTX
        mlock(hfftmtx);
#endif
    if (plan==NULL) {
        fftwf_plan_with_nthreads(NFFTTHREAD); /* fft execute in multi threads */
        plan=fftwf_plan_dft_1d(n,cpx,cpx,FFTW_FORWARD,FFTW_ESTIMATE);
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
        fftwf_destroy_plan(plan);
    } else {
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
    }
#ifdef FFTMTX
        unmlock(hfftmtx);
#endif
}
示例#4
0
void cyclic_cc2cs(CC *in, CS *out, const struct cyclic_work *w) {
    fftwf_execute_dft(w->cc2cs, in->data, out->data);
    out->imjd = in->imjd;
    out->fmjd = in->fmjd;
    out->ref_phase = in->ref_phase;
    out->ref_freq = in->ref_freq;
    out->rf = in->rf;
    out->bw = in->bw;
}
示例#5
0
extern void cpxfft(fftwf_plan plan, cpx_t *cpx, int n)
{
#ifdef TEST    
    if (plan==NULL) {
        mlock(hfftmtx); 
        fftwf_plan_with_nthreads(NFFTTHREAD); /* fft execute in multi threads */
        plan=fftwf_plan_dft_1d(n,cpx,cpx,FFTW_FORWARD,FFTW_ESTIMATE);
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
        fftwf_destroy_plan(plan);
        unmlock(hfftmtx);
    } else {
        fftwf_execute_dft(plan,cpx,cpx); /* fft */
    }
#else
    sfft_plan *p;
    p=sfft_make_plan(n, 50, SFFT_VERSION_3, FFTW_ESTIMATE);
    sfft_exec(p, cpx, cpx);
#endif
}
示例#6
0
void SingleParticle2dx::Utilities::FFTCalculator::performBackwardFFT (fft_array2d_type* fourier_data, real_array2d_type* real_data)
{
	size_type nx = fourier_data->shape()[0];
	size_type ny = fourier_data->shape()[1];
	size_type n_part = SingleParticle2dx::ConfigContainer::Instance()->getParticleSize();
	
	SingleParticle2dx::Utilities::FFTPlanContainer* plan_cont = SingleParticle2dx::Utilities::FFTPlanContainer::Instance();
		
	fftwf_complex* in = (fftwf_complex *) fftwf_malloc ( sizeof(fftwf_complex)*nx*ny);
	fftwf_complex* out = (fftwf_complex *) fftwf_malloc ( sizeof(fftwf_complex)*nx*ny);
		
	fftwf_complex* out_pointer = out;
	
	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			out_pointer[j+i*ny][0] = (*fourier_data)[i][j].real();
			out_pointer[j+i*ny][1] = (*fourier_data)[i][j].imag();
		}
	}
	
	fftwf_plan p2_bw;
	real_array2d_type* pow_array;
	
	if( nx == 4*n_part )
	{
		p2_bw = plan_cont->getBW_4_2d();
		pow_array = plan_cont->getLargePowArray2D();
	}
	else
	{
		p2_bw = plan_cont->getBW_2d();
		pow_array = plan_cont->getSmallPowArray2D();
	}
	
//	fftw3_mkl.verbose = 10;
	fftwf_execute_dft(p2_bw, out, in);
	
	fftwf_complex* in_pointer = in;
	value_type power;
	
	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			power = (*pow_array)[i][j];
			//((*real_data)[i][j]) = in.get()[j+i*ny][0] * powf(-1.0,i+j) / n;
			((*real_data)[i][j]) = in_pointer[j+i*ny][0] * power;
		}
	}
	
	fftwf_free(in);
	fftwf_free(out);
}
示例#7
0
void SingleParticle2dx::Utilities::FFTCalculator::performForwardFFT(real_array2d_type* real_data, fft_array2d_type* fourier_data)
{
	size_type nx = fourier_data->shape()[0];
	size_type ny = fourier_data->shape()[1];
	
	size_type n_part = SingleParticle2dx::ConfigContainer::Instance()->getParticleSize();
	
	SingleParticle2dx::Utilities::FFTPlanContainer* plan_cont = SingleParticle2dx::Utilities::FFTPlanContainer::Instance();
	
	fftwf_plan p2_fw;
	real_array2d_type* pow_array;
	
	if( nx == 4*n_part )
	{
		p2_fw = plan_cont->getFW_4_2d();
		pow_array = plan_cont->getLargePowArray2D();
	}
	else
	{
		p2_fw = plan_cont->getFW_2d();
		pow_array = plan_cont->getSmallPowArray2D();
	}
	
	fftwf_complex* in = (fftwf_complex *) fftwf_malloc (sizeof(fftwf_complex)*nx*ny);
	fftwf_complex* out = (fftwf_complex *) fftwf_malloc (sizeof(fftwf_complex)*nx*ny);

	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			in[j+i*ny][0] = ((*real_data)[i][j]) * ((*pow_array)[i][j]);
			in[j+i*ny][1] = 0;
		}
	}
	
	fftwf_execute_dft(p2_fw, in, out);
	
	fft_type value2set(0,0);
	
	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			value2set.real(out[j+i*ny][0]);
			value2set.imag(out[j+i*nx][1]);
			(*fourier_data)[i][j] = value2set;
		}
	}
	
	fftwf_free(in);
	fftwf_free(out);
}
示例#8
0
void SingleParticle2dx::Utilities::FFTCalculator::performForwardFFT(real_array3d_type* real_data, fft_array3d_type* fourier_data)
{
	size_type nx = fourier_data->shape()[0];
	size_type ny = fourier_data->shape()[1];
	size_type nz = fourier_data->shape()[2];
	
	value_type n = getScalingFactor3d (nx, ny, nz);
	
	SingleParticle2dx::Utilities::FFTPlanContainer* plan_cont = SingleParticle2dx::Utilities::FFTPlanContainer::Instance();
	
	fftwf_complex* in = (fftwf_complex *) fftwf_malloc (sizeof(fftwf_complex)*nx*ny*nz);
	fftwf_complex* out = (fftwf_complex *) fftwf_malloc (sizeof(fftwf_complex)*nx*ny*nz);
	
	real_array3d_type* power_array = plan_cont->getPowArray3D();

	value_type power;
	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			for (size_type k=0; k<nz; k++)
			{
				power = (*power_array)[i][j][k];
				//in.get()[k+j*ny+i*nx*ny][0] = ((*real_data)[i][j][k]) * powf(-1,i+j+k) / n;
				in[k+j*ny+i*nx*ny][0] = ((*real_data)[i][j][k]) * power / n;
				in[k+j*ny+i*nx*ny][1] = 0;
			}
		}
	}
	
	fftwf_plan p3_fw = plan_cont->getFW_3d();
	fftwf_execute_dft(p3_fw, in, out);
	
	fft_type value2set(0,0);
	for (size_type i=0; i<nx; i++)
	{
		for (size_type j=0; j<ny; j++)
		{
			for (size_type k=0; k<nz; k++)
			{
				value2set.real(out[k+j*ny+i*nx*ny][0]);
				value2set.imag(out[k+j*ny+i*nx*ny][1]);
				(*fourier_data)[i][j][k] = value2set;
			}
		}
	}
	
	fftwf_free(in);
	fftwf_free(out);
}
示例#9
0
文件: fft.c 项目: Markusjsommer/bart
static void fft_apply(const operator_data_t* _plan, unsigned int N, void* args[N])
{
	complex float* dst = args[0];
	const complex float* src = args[1];
	const struct fft_plan_s* plan = CONTAINER_OF(_plan, const struct fft_plan_s, base);

	assert(2 == N);

#ifdef  USE_CUDA
	if (cuda_ondevice(src)) {

		assert(NULL != plan->cuplan);
		fft_cuda_exec(plan->cuplan, dst, src);

	} else 
#endif
	{
		assert(NULL != plan->fftw);
		fftwf_execute_dft(plan->fftw, (complex float*)src, dst);
	}
}
示例#10
0
文件: fft.c 项目: hcmh/bart
static void fft_apply(const operator_data_t* _plan, unsigned int N, void* args[N])
{
	complex float* dst = args[0];
	const complex float* src = args[1];
	const struct fft_plan_s* plan = CAST_DOWN(fft_plan_s, _plan);

	assert(2 == N);

#ifdef  USE_CUDA
	if (cuda_ondevice(src)) {
#ifdef	LAZY_CUDA
          if (NULL == plan->cuplan)
		((struct fft_plan_s*)plan)->cuplan = fft_cuda_plan(plan->D, plan->dims, plan->flags, plan->ostrs, plan->istrs, plan->backwards);
#endif
		assert(NULL != plan->cuplan);
		fft_cuda_exec(plan->cuplan, dst, src);

	} else 
#endif
	{
		assert(NULL != plan->fftw);
		fftwf_execute_dft(plan->fftw, (complex float*)src, dst);
	}
}
int main(int argc, char *argv[]) {
  char *outfile=NULL, buf[256];
  struct stat statbuf;
  int nbytes,nread,nsamples;
  std::string tmpbuf("");
  int i=0,j;

  if ((argc < 2) || (argc > 3)) {
    fprintf(stderr,"%s infile [outfile]\n",argv[0]);
    exit(1);
  }
  char *infile=argv[1];
  if (argc==3) {
    outfile=argv[2];
  } 
  FILE *in=fopen(infile,"r");
  FILE *out;
  if (outfile) {
    out=fopen(outfile,"w");
  } else {
    out=stdout;
  }
  stat(infile,&statbuf);
  nbytes=statbuf.st_size;
  fseek(in,0,SEEK_SET);
  tmpbuf.reserve(nbytes);
  // read entire file into a buffer.
  while ((nread=(int)fread(buf,1,sizeof(buf),in))) {
    tmpbuf+=std::string(&(buf[0]),nread);
  }
  // parse the header
  header.parse_xml(tmpbuf);
  // decode the data
  std::vector<unsigned char> datav(
    xml_decode_field<unsigned char>(tmpbuf,"data") 
  );
  tmpbuf.clear();
  nsamples=header.group_info->data_desc.nsamples;
  nbytes=nsamples*header.group_info->recorder_cfg->bits_per_sample/8;
  if (datav.size() < nbytes) {
    fprintf(stderr,"Data size does not match number of samples\n");
    exit(1);
  }
  // convert the data to floating point
  sah_complex *fpdata=(sah_complex *)calloc(nsamples,sizeof(sah_complex));
  sah_complex *fpout=(sah_complex *)calloc(2048,sizeof(sah_complex));
  sah_complex *tmpb=(sah_complex *)calloc(1024,sizeof(sah_complex));
  if (!fpdata || !fpout) {
    fprintf(stderr,"Memory allocation failure\n");
    exit(1);
  }
  bits_to_floats(&(datav[0]),fpdata,nsamples);
  datav.clear();

  sah_complex workbuf[2048];
  fftwf_plan reverse=fftwf_plan_dft_1d(2048,workbuf,fpout,FFTW_BACKWARD,FFTW_MEASURE);
  fftwf_plan forward=fftwf_plan_dft_1d(1024,tmpb,workbuf,FFTW_FORWARD,FFTW_MEASURE|FFTW_PRESERVE_INPUT);

  while (i<nsamples) {
    // Do the forward transform.
    fftwf_execute_dft(forward, fpdata+i, workbuf);
    // shift 64 frequency bins
    memmove((void *)(workbuf+64), (void *)workbuf, 1024*sizeof(sah_complex));
    // now move the upper 64 into the low bins
    memmove((void *)workbuf,(void *)(workbuf+1024),64*sizeof(sah_complex));
    // clear the upper range
    memset((void *)(workbuf+1024),0,64*sizeof(sah_complex));
    // Do the reverse transform
    fftwf_execute_dft(reverse,workbuf,fpout);
    //
    for (j=0; j<2048; j++) {
      fprintf(out,"%f\n",fpout[j][0]/1024.0);
    }
    i+=1024;
  }
  exit(0);
}
示例#12
0
文件: dft_fftw.c 项目: mfkiwl/srsLTE
void srslte_dft_run_c_zerocopy(srslte_dft_plan_t *plan, const cf_t *in, cf_t *out) {
  fftwf_execute_dft(plan->p, (cf_t*) in, out);
}
示例#13
0
/*--------------------------------------------------------------------------*/
void _fftwfE (fftwf_plan p, fftwf_complex *in, fftwf_complex *out)  /*execute*/
{
  fftwf_execute_dft(p, in, out);
  return;
}
示例#14
0
void filter_freq2time(struct filter_freq *in, struct filter_time *out, 
        const struct cyclic_work *w) {
    fftwf_execute_dft(w->freq2time, in->data, out->data);
}