Typedefs | Functions
WireCell::Array Namespace Reference

Typedefs

typedef Eigen::ArrayXf array_xf
 
typedef Eigen::ArrayXcf array_xc
 
typedef Eigen::Array< short, Eigen::Dynamic, Eigen::Dynamic > array_xxs
 A 16 bit short integer 2D array. More...
 
typedef Eigen::Array< int, Eigen::Dynamic, Eigen::Dynamic > array_xxi
 Integer. More...
 
typedef Eigen::Array< long, Eigen::Dynamic, Eigen::Dynamic > array_xxl
 Integer. More...
 
typedef Eigen::ArrayXXf array_xxf
 A real, 2D array. More...
 
typedef Eigen::ArrayXXcf array_xxc
 A complex, 2D array. More...
 

Functions

array_xxc dft (const array_xxf &arr)
 
array_xxf idft (const array_xxc &arr)
 
array_xxc dft_rc (const array_xxf &arr, int dim=0)
 
array_xxc dft_cc (const array_xxc &arr, int dim=1)
 
array_xxc idft_cc (const array_xxc &arr, int dim=1)
 
array_xxf idft_cr (const array_xxc &arr, int dim=0)
 
array_xxf deconv (const array_xxf &arr, const array_xxc &filter)
 

Typedef Documentation

typedef Eigen::ArrayXcf WireCell::Array::array_xc

Definition at line 42 of file Array.h.

typedef Eigen::ArrayXf WireCell::Array::array_xf

Definition at line 41 of file Array.h.

typedef Eigen::ArrayXXcf WireCell::Array::array_xxc

A complex, 2D array.

Definition at line 57 of file Array.h.

typedef Eigen::ArrayXXf WireCell::Array::array_xxf

A real, 2D array.

Definition at line 54 of file Array.h.

typedef Eigen::Array<int, Eigen::Dynamic, Eigen::Dynamic> WireCell::Array::array_xxi

Integer.

Definition at line 48 of file Array.h.

typedef Eigen::Array<long, Eigen::Dynamic, Eigen::Dynamic> WireCell::Array::array_xxl

Integer.

Definition at line 51 of file Array.h.

typedef Eigen::Array<short, Eigen::Dynamic, Eigen::Dynamic> WireCell::Array::array_xxs

A 16 bit short integer 2D array.

Definition at line 45 of file Array.h.

Function Documentation

WireCell::Array::array_xxf WireCell::Array::deconv ( const array_xxf arr,
const array_xxc filter 
)

Perform 2D deconvolution.

This will perform a 2D forward DFT, do an element-by-element multiplication of that periodicity/frequency space matrix by the filter and then perform an 2D inverse DFT.

Definition at line 187 of file Array.cxx.

189 {
190  const int nrows = arr.rows();
191  const int ncols = arr.cols();
192 
193  Eigen::FFT< float > fft;
194 
195  Eigen::MatrixXcf matc(nrows, ncols);
196  for (int irow = 0; irow < nrows; ++irow) {
197  Eigen::VectorXcf fspec(ncols); // frequency spectrum
198  // fft wants vectors, also input arr is const
199  Eigen::VectorXf tmp = arr.row(irow);
200  fft.fwd(fspec, tmp);
201  matc.row(irow) = fspec;
202  }
203 
204  for (int icol = 0; icol < ncols; ++icol) {
205  Eigen::VectorXcf pspec(nrows); // periodicity spectrum
206  fft.fwd(pspec, matc.col(icol));
207  matc.col(icol) = pspec;
208  }
209 
210  // deconvolution via multiplication in frequency space
211  Eigen::MatrixXcf filt = matc.array() * filter;
212 
213  for (int icol = 0; icol < ncols; ++icol) {
214  Eigen::VectorXcf pspec(nrows); // wire spectrum
215  fft.inv(pspec, filt.col(icol));
216  filt.col(icol) = pspec;
217  }
218 
219  array_xxf ret(nrows, ncols);
220 
221  for (int irow = 0; irow < nrows; ++irow) {
222  Eigen::VectorXf wave(ncols); // back to real-valued time series
223  fft.inv(wave, filt.row(irow));
224  ret.row(irow) = wave;
225  }
226 
227  return ret;
228 }
string tmp
Definition: languages.py:63
static unsigned filter(unsigned char *out, const unsigned char *in, unsigned w, unsigned h, const LodePNG_InfoColor *info)
Definition: lodepng.cpp:3576
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54
WireCell::Array::array_xxc WireCell::Array::dft ( const array_xxf arr)

Perform full, 2D discrete Fourier transform on a real 2D array.

The full 2D DFT first performs a 1D DFT (real->complex) on each individual row and then a 1D DFT (complex->complex) on each resulting column.

const_shared_array_xxf arr = ...; const_shared_array_xxc spec = dft(*arr);

...

        const_shared_array_xxf arr2 = idft(*spec);

Definition at line 15 of file Array.cxx.

16 {
17  const int nrows = arr.rows();
18  const int ncols = arr.cols();
19 
20  Eigen::FFT< float > fft;
21  Eigen::MatrixXcf matc(nrows, ncols);
22 
23  for (int irow = 0; irow < nrows; ++irow) {
24  Eigen::VectorXcf fspec(ncols); // frequency spectrum
25  // fft wants vectors, also input arr is const
26  Eigen::VectorXf tmp = arr.row(irow);
27  fft.fwd(fspec, tmp);
28  matc.row(irow) = fspec;
29  }
30 
31  for (int icol = 0; icol < ncols; ++icol) {
32  Eigen::VectorXcf pspec(nrows); // periodicity spectrum
33  fft.fwd(pspec, matc.col(icol));
34  matc.col(icol) = pspec;
35  }
36 
37  return matc;
38 }
string tmp
Definition: languages.py:63
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
WireCell::Array::array_xxc WireCell::Array::dft_cc ( const array_xxc arr,
int  dim = 1 
)

Definition at line 67 of file Array.cxx.

68 {
69  const int nrows = arr.rows();
70  const int ncols = arr.cols();
71 
72  Eigen::FFT< float > fft;
73  Eigen::MatrixXcf matc(nrows, ncols);
74 
75  matc = arr.matrix();
76 
77  if (dim == 0) {
78  for (int irow = 0; irow < nrows; ++irow) {
79  Eigen::VectorXcf pspec(ncols);
80  fft.fwd(pspec,matc.row(irow));
81  matc.row(irow) = pspec;
82  }
83  }
84  else {
85  for (int icol = 0; icol < ncols; ++icol) {
86  Eigen::VectorXcf pspec(nrows);
87  fft.fwd(pspec, matc.col(icol));
88  matc.col(icol) = pspec;
89  }
90  }
91  return matc;
92 }
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
WireCell::Array::array_xxc WireCell::Array::dft_rc ( const array_xxf arr,
int  dim = 0 
)

Partial, 1D DFT and inverse DFT along one dimension of an array. Each row is transformed if dim=0, each column if dim=1. The transfer is either real->complex (rc), complex->complex(cc) or complex->real(cr).

The full 2D DFT should be used unless an intermediate filter is required as it will avoid producing some temporaries.

Conceptually:

auto xxc = dft(xxf);

is equivalent to

auto tmp = dft_rc(xxf, 0); auto xxc = dft_cc(tmp, 1);

and:

auto xxf = idft(xxc)

is equivalent to:

auto tmp = idft_cc(xxc, 1);
auto xxf = idft_rc(tmp, 0);

Definition at line 40 of file Array.cxx.

41 {
42  const int nrows = arr.rows();
43  const int ncols = arr.cols();
44 
45  Eigen::FFT< float > fft;
46  Eigen::MatrixXcf matc(nrows, ncols);
47 
48  if (dim == 0) {
49  for (int irow = 0; irow < nrows; ++irow) {
50  Eigen::VectorXcf fspec(ncols);
51  Eigen::VectorXf tmp = arr.row(irow);
52  fft.fwd(fspec, tmp);
53  matc.row(irow) = fspec;
54  }
55  }
56  else if (dim == 1) {
57  for (int icol = 0; icol < ncols; ++icol) {
58  Eigen::VectorXcf fspec(nrows);
59  Eigen::VectorXf tmp = arr.col(icol);
60  fft.fwd(fspec, tmp);
61  matc.col(icol) = fspec;
62  }
63  }
64  return matc;
65 }
string tmp
Definition: languages.py:63
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
WireCell::Array::array_xxf WireCell::Array::idft ( const array_xxc arr)

Definition at line 96 of file Array.cxx.

97 {
98  const int nrows = arr.rows();
99  const int ncols = arr.cols();
100 
101  // fft works on matrices, not arrays, also don't step on const input
102  Eigen::MatrixXcf partial(nrows, ncols);
103  partial = arr.matrix();
104 
105  Eigen::FFT< float > fft;
106 
107  for (int icol = 0; icol < ncols; ++icol) {
108  Eigen::VectorXcf pspec(nrows); // wire spectrum
109  fft.inv(pspec, partial.col(icol));
110  partial.col(icol) = pspec;
111  }
112 
113  //shared_array_xxf ret = std::make_shared<array_xxf> (nrows, ncols);
114  array_xxf ret(nrows, ncols);
115 
116  for (int irow = 0; irow < nrows; ++irow) {
117  Eigen::VectorXf wave(ncols); // back to real-valued time series
118  fft.inv(wave, partial.row(irow));
119  ret.row(irow) = wave;
120  }
121 
122  return ret;
123 }
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54
WireCell::Array::array_xxc WireCell::Array::idft_cc ( const array_xxc arr,
int  dim = 1 
)

Definition at line 125 of file Array.cxx.

126 {
127  const int nrows = arr.rows();
128  const int ncols = arr.cols();
129 
130  // fft works on matrices, not arrays, also don't step on const input
131  Eigen::MatrixXcf ret(nrows, ncols);
132  ret = arr.matrix();
133 
134  Eigen::FFT< float > fft;
135 
136  if (dim == 1) {
137  for (int icol = 0; icol < ncols; ++icol) {
138  Eigen::VectorXcf pspec(nrows);
139  fft.inv(pspec, ret.col(icol));
140  ret.col(icol) = pspec;
141  }
142  }
143  else if (dim == 0) {
144  for (int irow = 0; irow < nrows; ++irow) {
145  Eigen::VectorXcf pspec(ncols);
146  fft.inv(pspec, ret.row(irow));
147  ret.row(irow) = pspec;
148  }
149  }
150  return ret;
151 }
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
WireCell::Array::array_xxf WireCell::Array::idft_cr ( const array_xxc arr,
int  dim = 0 
)

Definition at line 153 of file Array.cxx.

154 {
155  const int nrows = arr.rows();
156  const int ncols = arr.cols();
157 
158  // fft works on matrices, not arrays, also don't step on const input
159  Eigen::MatrixXcf partial(nrows, ncols);
160  partial = arr.matrix();
161 
162  Eigen::FFT< float > fft;
163 
164  array_xxf ret(nrows, ncols);
165 
166  if (dim == 0) {
167  for (int irow = 0; irow < nrows; ++irow) {
168  Eigen::VectorXf wave(ncols); // back to real-valued time series
169  fft.inv(wave, partial.row(irow));
170  ret.row(irow) = wave;
171  }
172  }
173  else if (dim == 1) {
174  for (int icol = 0; icol < ncols; ++icol) {
175  Eigen::VectorXf wave(nrows);
176  fft.inv(wave, partial.col(icol));
177  ret.col(icol) = wave;
178  }
179  }
180  return ret;
181 }
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:84
Eigen::ArrayXXf array_xxf
A real, 2D array.
Definition: Array.h:54