summaryrefslogtreecommitdiffstats
path: root/tests/test_Fourier.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2016-11-28 19:17:54 +0100
committerWillem Jan Palenstijn <wjp@usecode.org>2016-11-28 19:17:54 +0100
commit341e020c885202a543feb2f5d0fa75ac566ea0e9 (patch)
tree0a97861cc5f5215c1e2c0cc5ee0dfe4de4082ff3 /tests/test_Fourier.cpp
parentbba67ebac5f05aed001d8e205e0e2220004252d9 (diff)
downloadastra-341e020c885202a543feb2f5d0fa75ac566ea0e9.tar.gz
astra-341e020c885202a543feb2f5d0fa75ac566ea0e9.tar.bz2
astra-341e020c885202a543feb2f5d0fa75ac566ea0e9.tar.xz
astra-341e020c885202a543feb2f5d0fa75ac566ea0e9.zip
Fix Fourier test
Diffstat (limited to 'tests/test_Fourier.cpp')
-rw-r--r--tests/test_Fourier.cpp147
1 files changed, 12 insertions, 135 deletions
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 <http://www.gnu.org/licenses/>.
#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);
- }
-
-
-}
-