Functions
test_zero_padding.cxx File Reference
#include "WireCellUtil/Waveform.h"
#include <algorithm>
#include <Eigen/Core>
#include <unsupported/Eigen/FFT>
#include <complex>
#include <iostream>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

int main ( void  )

Definition at line 15 of file test_zero_padding.cxx.

15  {
16  std::vector<float> a = {1,2,3,2,1};
17  // can be sampled to 10 ticks: 1 , 1.35279 , 2 , 2.69443 , 3 , 2.69443 , 2 , 1.35279 , 1 , 0.905573
18 
19  auto tran = WireCell::Waveform::dft(a);
20 
21  std::cout << " tran = " << std::endl;
22  std::cout << tran.size() << std::endl;
24  for(auto x: mag){
25  std::cout << x << " ";
26  }
27  std::cout << std::endl;
28 
29  // zero-padding
30  int inSmps = tran.size();
31  tran.resize(inSmps*2);
32  if(inSmps%2==0){
33  // even number of samples, eg, inSmps=6, 012345 -(zero-padding)-> 012345,000000 -> 012000,000345
34  std::rotate(tran.begin()+inSmps/2, tran.begin()+inSmps, tran.end());
35  }
36  else{
37  // odd number, eg, inSmps=5, 01234,00000 -> 01200,00034
38  std::rotate(tran.begin()+(inSmps+1)/2, tran.begin()+inSmps, tran.end());
39  }
40 
41  //
42  std::cout << " tran = " << std::endl;
43  std::cout << tran.size() << std::endl;
44  for(auto x: tran){
45  std::cout << x.real() << " ";
46  }
47  std::cout << std::endl;
48 
49  // inverse FFT
50  auto b = WireCell::Waveform::idft(tran);
51  float scale = tran.size() / inSmps;
52  //
53  std::cout << " b = " << std::endl;
54  std::cout << b.size() << std::endl;
55  for(auto x: b){
56  std::cout << x * scale << " ";
57  }
58  std::cout << std::endl;
59 
60 
61  return 0;
62 }
compseq_t dft(realseq_t seq)
Definition: Waveform.cxx:141
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
realseq_t idft(compseq_t spec)
Definition: Waveform.cxx:149
realseq_t magnitude(const compseq_t &seq)
Return the magnitude or absolute value of the sequence.
Definition: Waveform.cxx:65
static bool * b
Definition: config.cpp:1043
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)