c++ - Decimate vector in eigen -


i have float array eigen::arrayxf need decimate (i.e. pick 1 out of f.i. 8 samples).

eigen::arrayxf decimatedsignal = eigen::map<eigen::arrayxf, 0, eigen::innerstride<8> >(signal.data(), length, 1).eval(); 

which works, caveat: need know how long length is, , can specified long, leading runtime errors.

q: there way decimate possible, resultant length == signal.size() / 8 ?

two things. using c'tor mapping matrix:

map ( pointerargtype dataptr, index nbrows, index nbcols, const stridetype & a_stride = stridetype() )

constructor in dynamic-size matrix case.

parameters

dataptr  pointer array map nbrows    number of rows of matrix expression nbcols    number of columns of matrix expression a_stride  optional stride object, passing strides.  

i think want c'tor vector:

map ( pointerargtype dataptr, index a_size, const stridetype & a_stride = stridetype() )

constructor in dynamic-size vector case.

parameters

dataptr  pointer array map a_size    size of vector expression a_stride  optional stride object, passing strides.  

the second thing want length == signal.size())/8. whole integer, or rounding up? if data 16 in length , want positions [0] , [8], use 1+(signal.size()-1)/8 length parameter:

eigen::arrayxf decimatedsignal = eigen::map<eigen::arrayxf, 0, eigen::innerstride<8> >(signal.data(), 1+((signal.size()-1)/8) ).eval(); 

for example:

#include <eigen/core> #include <iostream>  using std::cout; using std::endl;  int main(int argc, char *argv[]) {     eigen::vectorxf signal;     signal.setlinspaced(64, 0.0, 63.);     cout << "original signal:" << endl << signal.transpose() << endl;      eigen::arrayxf decimatedsignal = eigen::map<eigen::arrayxf, 0,          eigen::innerstride<8> >(signal.data(), 1+((signal.size()-1)/8)).eval();      cout << endl << "decimated:" << endl << decimatedsignal.transpose() << endl;      return 0; } 

outputs

original signal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

decimated: 0 8 16 24 32 40 48 56

which think want.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -