Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
sigproc
test
test_zero_padding.cxx
Go to the documentation of this file.
1
// Example for FFT resampling with zero-padding tricks
2
#include "
WireCellUtil/Waveform.h
"
3
4
#include <algorithm>
5
6
// for FFT
7
#include <Eigen/Core>
8
#include <unsupported/Eigen/FFT>
9
10
#include <complex>
11
#include <iostream>
12
13
using namespace
WireCell
;
14
15
int
main
(){
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
;
23
auto
mag
=
WireCell::Waveform::magnitude
(tran);
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
}
mag
WireCell::Waveform::dft
compseq_t dft(realseq_t seq)
Definition:
Waveform.cxx:141
Waveform.h
a
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition:
pointer.h:1124
WireCell
Definition:
Main.h:22
WireCell::Waveform::scale
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition:
Waveform.h:146
WireCell::Waveform::idft
realseq_t idft(compseq_t spec)
Definition:
Waveform.cxx:149
WireCell::Waveform::magnitude
realseq_t magnitude(const compseq_t &seq)
Return the magnitude or absolute value of the sequence.
Definition:
Waveform.cxx:65
b
static bool * b
Definition:
config.cpp:1043
train.x
list x
Definition:
train.py:276
main
int main()
Definition:
test_zero_padding.cxx:15
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11