本征中的十进制矢量

Decimate vector in eigen

本文关键字:十进制      更新时间:2023-10-16

我有一个浮点数组Eigen::ArrayXf,我需要对其进行抽取(即从f.I.8个样本中挑选1个)。

Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0, Eigen::InnerStride<8> >(signal.data(), length, 1).eval();

这是有效的,但需要注意:我需要知道长度有多长,而且它可能被指定得太长,从而导致运行时错误。

Q: 有没有一种方法可以抽取所有可能的值,使结果长度为==signal.size()/8?

两件事。您正在使用c'tor来映射矩阵:

Map(PointerArgType数据Ptr,索引nbRows,索引nbCols,const StrideType&a_sarde=跨步类型())

动态大小矩阵情况下的构造函数。

参数

dataPtr  pointer to the array to map
nbRows    the number of rows of the matrix expression
nbCols    the number of columns of the matrix expression
a_stride  optional Stride object, passing the strides. 

我想你想要向量的c'tor:

映射(PointerArgType dataPtr,索引a_size,const StrideType&a_sarde=跨步类型())

构造函数。

参数

dataPtr  pointer to the array to map
a_size    the size of the vector expression
a_stride  optional Stride object, passing the strides. 

第二件事是您想要length == signal.size())/8。这总是一个整数吗?还是你在四舍五入?如果数据长度为16,并且您想要位置[0][8],则使用1+(signal.size()-1)/8作为长度参数:

Eigen::ArrayXf decimatedSignal = Eigen::Map<Eigen::ArrayXf, 0, Eigen::InnerStride<8> >(signal.data(), 1+((signal.size()-1)/8) ).eval();

例如:

#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;
}

输出

原始信号:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 20 21 23 24 25 26 28 29 30 32 33 34 35 36 37 39 41 43 44 46 47 48 49 50 51 52 53 54 56 57 58 60 61 62 63

小数:0 8 16 24 32 40 48 56

我认为这正是你想要的。