[37] | 1 | % Test code for the discrete quaternion Fourier transform. |
---|
| 2 | % This code tests the following functions: |
---|
| 3 | % |
---|
| 4 | % qdft qdft2 |
---|
| 5 | % iqdft iqdft2 |
---|
| 6 | % |
---|
| 7 | % It also verifies indirectly many of the basic quaternion operations |
---|
| 8 | % since the qdft depends on them. |
---|
| 9 | |
---|
| 10 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 11 | % See the file : Copyright.m for further details. |
---|
| 12 | |
---|
| 13 | % Since the two-dimensional qdft code calls the one-dimensional |
---|
| 14 | % code, we need only to test the two dimensionsal code in what |
---|
| 15 | % follows. |
---|
| 16 | |
---|
| 17 | % Define one real and one complex quaternion array. |
---|
| 18 | |
---|
| 19 | q = quaternion(randn(10,10), randn(10,10), randn(10,10), randn(10,10)); |
---|
| 20 | b = quaternion(complex(randn(10,10)),complex(randn(10,10)),... |
---|
| 21 | complex(randn(10,10)),complex(randn(10,10))); |
---|
| 22 | T = 1e-12; |
---|
| 23 | |
---|
| 24 | RA = unit(quaternion(1,1,1)); % Real axis. |
---|
| 25 | CA = complex(RA, quaternion(1,0,-1)); % Complex axis. |
---|
| 26 | |
---|
| 27 | if isreal(CA) error('Complex axis is not complex.'); end |
---|
| 28 | if ~isreal(RA) error('Real axis is complex.'); end |
---|
| 29 | |
---|
| 30 | % Test 1. Verify correct transform and inverse for a real quaternion |
---|
| 31 | % array with a real quaternion axis. |
---|
| 32 | |
---|
| 33 | compare(q, iqdft2(qdft2(q, RA, 'L'), RA, 'L'), T, 'qdft failed test 1L.'); |
---|
| 34 | compare(q, iqdft2(qdft2(q, RA, 'R'), RA, 'R'), T, 'qdft failed test 1R.'); |
---|
| 35 | |
---|
| 36 | % Test 2. Verify correct transform and inverse for a real quaternion |
---|
| 37 | % array with a complex axis. |
---|
| 38 | |
---|
| 39 | compare(q, iqdft2(qdft2(q, CA, 'L'), CA, 'L'), T, 'qdft failed test 2L.'); |
---|
| 40 | compare(q, iqdft2(qdft2(q, CA, 'R'), CA, 'R'), T, 'qdft failed test 2R.'); |
---|
| 41 | |
---|
| 42 | % Test 3. Verify correct transform and inverse for a complex quaternion |
---|
| 43 | % array with a complex axis. |
---|
| 44 | |
---|
| 45 | compare(b, iqdft2(qdft2(b, CA, 'L'), CA, 'L'), T, 'qdft failed test 3L.'); |
---|
| 46 | compare(b, iqdft2(qdft2(b, CA, 'R'), CA, 'R'), T, 'qdft failed test 3R.'); |
---|
| 47 | |
---|
| 48 | % Test 4. Verify correct transform and inverse for a complex quaternion |
---|
| 49 | % array with a real axis. |
---|
| 50 | |
---|
| 51 | compare(b, iqdft2(qdft2(b, RA, 'L'), RA, 'L'), T, 'qdft failed test 4L.'); |
---|
| 52 | compare(b, iqdft2(qdft2(b, RA, 'R'), RA, 'R'), T, 'qdft failed test 4R.'); |
---|
| 53 | |
---|
| 54 | clear q b T RA CA |
---|