From 341e020c885202a543feb2f5d0fa75ac566ea0e9 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 28 Nov 2016 19:17:54 +0100 Subject: Fix Fourier test --- tests/test_Fourier.cpp | 147 ++++--------------------------------------------- 1 file changed, 12 insertions(+), 135 deletions(-) (limited to 'tests/test_Fourier.cpp') diff --git a/tests/test_Fourier.cpp b/tests/test_Fourier.cpp index 611bd56..cf05991 100644 --- a/tests/test_Fourier.cpp +++ b/tests/test_Fourier.cpp @@ -34,148 +34,25 @@ along with the ASTRA Toolbox. If not, see . #include "astra/Fourier.h" -BOOST_AUTO_TEST_CASE( testFourier_DFT_1D_1 ) -{ - astra::float32 inR[5] = { 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }; - astra::float32 inI[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - astra::float32 outR[5]; - astra::float32 outI[5]; - - astra::discreteFourierTransform1D(5, inR, inI, outR, outI, 1, 1, false); - - astra::float32 expected1R[5] = { 3.0f, 1.618034f, -0.618034f, -0.618034f, 1.618034f }; - for (unsigned int i = 0; i < 5; ++i) { - BOOST_CHECK_SMALL(outR[i] - expected1R[i], 0.00001f); - BOOST_CHECK_SMALL(outI[i], 0.00001f); - } - - astra::discreteFourierTransform1D(5, outR, outI, inR, inI, 1, 1, true); - astra::float32 expected2R[5] = { 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }; - for (unsigned int i = 0; i < 5; ++i) { - BOOST_CHECK_SMALL(inR[i] - expected2R[i], 0.00001f); - BOOST_CHECK_SMALL(inI[i], 0.00001f); - } -} - -BOOST_AUTO_TEST_CASE( testFourier_DFT_2D_1 ) -{ - astra::float32 inR[25] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }; - astra::float32 inI[25] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - astra::float32 outR[25]; - astra::float32 outI[25]; - - astra::discreteFourierTransform2D(5, 5, inR, inI, outR, outI, false); - - astra::float32 expected1R[25] = - { 13.0f , 5.236068f, 0.763932f, 0.763932f, 5.236068f, - 5.236068f,-0.618034f,-2.0f ,-2.0f ,-0.618034f, - 0.763932f,-2.0f , 1.618034f, 1.618034f,-2.0f , - 0.763932f,-2.0f , 1.618034f, 1.618034f,-2.0f , - 5.236068f,-0.618034f,-2.0f ,-2.0f ,-0.618034f }; - for (unsigned int i = 0; i < 25; ++i) { - BOOST_CHECK_SMALL(outR[i] - expected1R[i], 0.00001f); - BOOST_CHECK_SMALL(outI[i], 0.00001f); - } - - astra::discreteFourierTransform2D(5, 5, outR, outI, inR, inI, true); - astra::float32 expected2R[25] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }; - for (unsigned int i = 0; i < 25; ++i) { - BOOST_CHECK_SMALL(inR[i] - expected2R[i], 0.00001f); - BOOST_CHECK_SMALL(inI[i], 0.00001f); - } - - -} - - BOOST_AUTO_TEST_CASE( testFourier_FFT_1D_1 ) { - astra::float32 inR[8] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f }; - astra::float32 inI[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - astra::float32 outR[8]; - astra::float32 outI[8]; + astra::float32 data[16] = { 1.0f,0.0f, 1.0f,0.0f, 1.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 1.0f,0.0f, 1.0f,0.0f }; + int ip[6]; + astra::float32 w[8]; + ip[0] = 0; - astra::fastTwoPowerFourierTransform1D(8, inR, inI, outR, outI, 1, 1, false); + astra::cdft(16, -1, data, ip, w); - astra::float32 expected1R[8] = { 5.0f, 2.414214f, -1.0f, -0.414214f, 1.0f, -0.414214f, -1.0f, 2.414214f }; - for (unsigned int i = 0; i < 8; ++i) { - BOOST_CHECK_SMALL(outR[i] - expected1R[i], 0.00001f); - BOOST_CHECK_SMALL(outI[i], 0.00001f); + astra::float32 expected1[16] = { 5.0f,0.0f, 2.414214f,0.0f, -1.0f,0.0f, -0.414214f,0.0f, 1.0f,0.0f, -0.414214f,0.0f, -1.0f,0.0f, 2.414214f,0.0f }; + for (unsigned int i = 0; i < 16; ++i) { + BOOST_CHECK_SMALL(data[i] - expected1[i], 0.00001f); } - astra::fastTwoPowerFourierTransform1D(8, outR, outI, inR, inI, 1, 1, true); - astra::float32 expected2R[8] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f }; - for (unsigned int i = 0; i < 8; ++i) { - BOOST_CHECK_SMALL(inR[i] - expected2R[i], 0.00001f); - BOOST_CHECK_SMALL(inI[i], 0.00001f); + astra::cdft(16, 1, data, ip, w); + astra::float32 expected2[16] = { 8.0f,0.0f, 8.0f,0.0f, 8.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 8.0f,0.0f, 8.0f,0.0f }; + for (unsigned int i = 0; i < 16; ++i) { + BOOST_CHECK_SMALL(data[i] - expected2[i], 0.00001f); } } -BOOST_AUTO_TEST_CASE( testFourier_FFT_2D_1 ) -{ - astra::float32 inR[64] = { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f }; - astra::float32 inI[64] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; - astra::float32 outR[64]; - astra::float32 outI[64]; - - astra::discreteFourierTransform2D(8, 8, inR, inI, outR, outI, false); - - astra::float32 expected1R[64] = - { 25.0f, 12.656854f, 1.0f, 1.343146f, 1.0f, 1.343146f, 1.0f, 12.656854f, - 12.656854f, 3.0f, -3.828427f, -1.0f, -1.0f, -1.0f, -3.828427f, 3.0f, - 1.0f, -3.828427f, -3.0f, 1.828427f, 1.0f, 1.828427f, -3.0f, -3.828427f, - 1.343146f, -1.0f, 1.828427f, 3.0f, -1.0f, 3.0f, 1.828427f, -1.0f, - 1.0f, -1.0f, 1.0f, -1.0f, -7.0f, -1.0f, 1.0f, -1.0f, - 1.343146f, -1.0f, 1.828427f, 3.0f, -1.0f, 3.0f, 1.828427f, -1.0f, - 1.0f, -3.828427f, -3.0f, 1.828427f, 1.0f, 1.828427f, -3.0f, -3.828427f, - 12.656854f, 3.0f, -3.828427f, -1.0f, -1.0f, -1.0f, -3.828427f, 3.0f }; - for (unsigned int i = 0; i < 64; ++i) { - BOOST_CHECK_SMALL(outR[i] - expected1R[i], 0.00002f); - BOOST_CHECK_SMALL(outI[i], 0.00001f); - } - - - astra::discreteFourierTransform2D(8, 8, outR, outI, inR, inI, true); - astra::float32 expected2R[64] = { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f }; - for (unsigned int i = 0; i < 64; ++i) { - BOOST_CHECK_SMALL(inR[i] - expected2R[i], 0.00001f); - BOOST_CHECK_SMALL(inI[i], 0.00001f); - } - - -} - -- cgit v1.2.3