Add ifft_symmetric and its unit test.
This commit is contained in:
@@ -685,6 +685,28 @@ Matrix Aurora::ifft(const Matrix &aMatrix) {
|
||||
return Matrix();
|
||||
}
|
||||
|
||||
Matrix Aurora::ifft_symmetric(const Matrix &aMatrix,long length)
|
||||
{
|
||||
if(!aMatrix.isVector()){
|
||||
std::cerr<<"ifft_symmetric only support vector!"<<std::endl;
|
||||
return Matrix();
|
||||
}
|
||||
int matrixLength = aMatrix.getDataSize();
|
||||
int resultHalfLength = (int)std::ceil(((double)length*0.5));
|
||||
int copyLength = resultHalfLength<matrixLength?resultHalfLength:matrixLength;
|
||||
double* calcData = malloc(length,true);
|
||||
double zero = 0.0;
|
||||
//所有数据统一置0
|
||||
cblas_dcopy(length*2,&zero,0,calcData,1);
|
||||
//copy前半段数据
|
||||
cblas_zcopy(copyLength,aMatrix.getData(),1,calcData,1);
|
||||
//copy后半段数据,跳过index 0的值,并设置虚部共轭
|
||||
vdAddI(copyLength-1,&zero,0,(aMatrix.getData()+2),2,(calcData+(length-1)*2),-2);
|
||||
vdSubI(copyLength-1,&zero,0,(aMatrix.getData()+2+1),2,(calcData+(length-1)*2+1),-2);
|
||||
|
||||
return real(ifft(Matrix::New(calcData,length,1,1,Complex)));
|
||||
}
|
||||
|
||||
Matrix Aurora::hilbert(const Matrix &aMatrix) {
|
||||
auto x = fft(aMatrix);
|
||||
auto h = malloc(aMatrix.getDimSize(0));
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
#include "Matrix.h"
|
||||
#include "Function1D.h"
|
||||
|
||||
|
||||
namespace Aurora {
|
||||
enum FunctionDirection{
|
||||
namespace Aurora
|
||||
{
|
||||
enum FunctionDirection
|
||||
{
|
||||
Column,
|
||||
Row,
|
||||
All
|
||||
@@ -114,6 +115,13 @@ namespace Aurora {
|
||||
*/
|
||||
Matrix ifft(const Matrix &aMatrix);
|
||||
|
||||
/**
|
||||
* Symmetric逆fft,支持到2维,输入必须是复数,输出必是实数
|
||||
* @param aMatrix
|
||||
* @return ifft后的实数矩阵
|
||||
*/
|
||||
Matrix ifft_symmetric(const Matrix &aMatrix,long length);
|
||||
|
||||
/**
|
||||
* hilbert,支持到2维,输入必须是复数,输出必是复数
|
||||
* @param aMatrix
|
||||
@@ -131,5 +139,4 @@ namespace Aurora {
|
||||
Matrix dot(const Matrix &aMatrix, const Matrix &aOther, FunctionDirection direction = Column);
|
||||
};
|
||||
|
||||
|
||||
#endif // AURORA_FUNCTION2D_H
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace Aurora {
|
||||
|
||||
bool Matrix::isVector() const{
|
||||
if (getDimSize(2)>1) return false;
|
||||
if (isScalar) return false;
|
||||
if (isScalar()) return false;
|
||||
return getDimSize(0) == 1 ||
|
||||
getDimSize(1) == 1;
|
||||
}
|
||||
|
||||
@@ -363,6 +363,17 @@ TEST_F(Function2D_Test, hilbert) {
|
||||
EXPECT_DOUBLE_EQ(fourDecimalRound(result[11].imag()),0.3249);
|
||||
}
|
||||
|
||||
TEST_F(Function2D_Test, ifft_symmetric) {
|
||||
double *input = new double[18]{10,2,1,3,4,4,16,3,1,2,15,-2,1,-3,4,-4,1,-3};
|
||||
auto ma = Aurora::Matrix::fromRawData(input,9,1,1,Aurora::Complex);
|
||||
auto ret = Aurora::ifft_symmetric(ma,18);
|
||||
auto result = ret.getData();
|
||||
EXPECT_DOUBLE_EQ(fourDecimalRound(result[0]),5.3333);
|
||||
EXPECT_DOUBLE_EQ(fourDecimalRound(result[1]),1.1188);
|
||||
EXPECT_DOUBLE_EQ(fourDecimalRound(result[11]),2.8506);
|
||||
EXPECT_DOUBLE_EQ(fourDecimalRound(result[17]),1.1188);
|
||||
}
|
||||
|
||||
TEST_F(Function2D_Test, prod) {
|
||||
double *dataB = new double[20]{1.1, 2.6, 3.8, 6.2,
|
||||
4.3, 5.7, 6.9, 10.6,
|
||||
|
||||
Reference in New Issue
Block a user