Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Public Member Functions | List of all members
ska::cheetah::utils::ConvolvePlan Class Reference

Perform a convolution using fft methods. More...

#include <cheetah/utils/ConvolvePlan.h>

Collaboration diagram for ska::cheetah::utils::ConvolvePlan:
Collaboration graph

Public Member Functions

 ConvolvePlan (std::size_t npts, float *a, float *b, float *output)
 fast convolution of two data sets a and b of length npts output = a * b More...
 
void convolve ()
 

Detailed Description

Perform a convolution using fft methods.

Definition at line 39 of file ConvolvePlan.h.

Constructor & Destructor Documentation

◆ ConvolvePlan()

ska::cheetah::utils::ConvolvePlan::ConvolvePlan ( std::size_t  npts,
float *  a,
float *  b,
float *  output 
)

fast convolution of two data sets a and b of length npts output = a * b

note that a and b are overwritten

Definition at line 32 of file ConvolvePlan.cpp.

33  : _a(a)
34  , _b(b)
35  , _output(output)
36  , _npts(npts)
37  , _c(fftwf_alloc_complex(npts))
38 {
39  if(_c == nullptr) throw std::bad_alloc();
40  _d=fftwf_alloc_complex(npts);
41  if(_d == nullptr) {
42  fftwf_free(_c);
43  throw std::bad_alloc();
44  }
45  _fwda = fftwf_plan_dft_r2c_1d(npts, _a, _c, FFTW_MEASURE);
46  if(_fwda == nullptr) {
47  fftwf_free(_c);
48  fftwf_free(_d);
49  throw std::bad_alloc();
50  }
51  _fwdb = fftwf_plan_dft_r2c_1d(npts, _b, _d, FFTW_MEASURE);
52  if(_fwdb == nullptr) {
53  fftwf_free(_c);
54  fftwf_free(_d);
55  fftwf_destroy_plan(_fwda);
56  throw std::bad_alloc();
57  }
58  _bwd = fftwf_plan_dft_c2r_1d(npts, _c, _output, FFTW_MEASURE);
59  if(_bwd == nullptr) {
60  fftwf_free(_c);
61  fftwf_free(_d);
62  fftwf_destroy_plan(_fwda);
63  fftwf_destroy_plan(_fwdb);
64  throw std::bad_alloc();
65  }
66  _scale = (float) npts;
67 }

Member Function Documentation

◆ convolve()

void ska::cheetah::utils::ConvolvePlan::convolve ( )

perform the convolution using the current data in a and b n.b. contents of a and b will be destroyed

Definition at line 78 of file ConvolvePlan.cpp.

79 {
80  std::size_t i, j;
81  fftwf_execute(_fwda);
82  fftwf_execute(_fwdb);
83  for(i = 0; i < _npts; ++i) {
84  for(j = 0; j < 2; ++j) {
85  _c[i][j] *= _d[i][j]/_scale;
86  }
87  }
88  fftwf_execute(_bwd);
89 }

The documentation for this class was generated from the following files: