[37] | 1 | % Test code for the fast quaternion Fourier transform. |
---|
| 2 | % This code tests the following functions: |
---|
| 3 | % |
---|
| 4 | % qfft qfft2 |
---|
| 5 | % iqfft iqfft2 |
---|
| 6 | |
---|
| 7 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 8 | % See the file : Copyright.m for further details. |
---|
| 9 | |
---|
| 10 | % We have to test all of the above functions separately, since they do not |
---|
| 11 | % call each other, as is the case with the corresponding dqft functions. In |
---|
| 12 | % addition, we need to verify the results of the FFTs against the DFT code |
---|
| 13 | % in the corresponding qdft functions, e.g. for qfft2, this is qdft2. For |
---|
| 14 | % each transform we need to verify that it inverts correctly for all four |
---|
| 15 | % combinations of real/complex data and real/complex axis, and for left and |
---|
| 16 | % right exponentials, and we need to verify each against the corresponding |
---|
| 17 | % DFT code. |
---|
| 18 | |
---|
| 19 | % Define one real and one complex quaternion array. |
---|
| 20 | |
---|
| 21 | q = quaternion(randn(10,10), randn(10,10), randn(10,10), randn(10,10)); |
---|
| 22 | b = quaternion(complex(randn(10,10)),complex(randn(10,10)),... |
---|
| 23 | complex(randn(10,10)),complex(randn(10,10))); |
---|
| 24 | T = 1e-12; |
---|
| 25 | |
---|
| 26 | RA = unit(quaternion(1,1,1)); % Real axis. |
---|
| 27 | CA = complex(quaternion(1,1,1), quaternion(0,1,-1)); % Complex axis. |
---|
| 28 | |
---|
| 29 | if isreal(CA) error('Complex axis is not complex.'); end |
---|
| 30 | if ~isreal(RA) error('Real axis is complex.'); end |
---|
| 31 | |
---|
| 32 | % 1D FFT code against its own inverse .... |
---|
| 33 | |
---|
| 34 | % Test 1. Verify correct transform and inverse for a real quaternion |
---|
| 35 | % array with a real quaternion axis. |
---|
| 36 | |
---|
| 37 | compare(q, iqfft(qfft(q, RA, 'L'), RA, 'L'), T, 'qfft failed test 1L.'); |
---|
| 38 | compare(q, iqfft(qfft(q, RA, 'R'), RA, 'R'), T, 'qfft failed test 1R.'); |
---|
| 39 | |
---|
| 40 | % Test 2. Verify correct transform and inverse for a real quaternion |
---|
| 41 | % array with a complex axis. |
---|
| 42 | |
---|
| 43 | compare(q, iqfft(qfft(q, CA, 'L'), CA, 'L'), T, 'qfft failed test 2L.'); |
---|
| 44 | compare(q, iqfft(qfft(q, CA, 'R'), CA, 'R'), T, 'qfft failed test 2R.'); |
---|
| 45 | |
---|
| 46 | % Test 3. Verify correct transform and inverse for a complex quaternion |
---|
| 47 | % array with a complex axis. |
---|
| 48 | |
---|
| 49 | compare(b, iqfft(qfft(b, CA, 'L'), CA, 'L'), T, 'qfft failed test 3L.'); |
---|
| 50 | compare(b, iqfft(qfft(b, CA, 'R'), CA, 'R'), T, 'qfft failed test 3R.'); |
---|
| 51 | |
---|
| 52 | % Test 4. Verify correct transform and inverse for a complex quaternion |
---|
| 53 | % array with a real axis. |
---|
| 54 | |
---|
| 55 | compare(b, iqfft(qfft(b, RA, 'L'), RA, 'L'), T, 'qfft failed test 4L.'); |
---|
| 56 | compare(b, iqfft(qfft(b, RA, 'R'), RA, 'R'), T, 'qfft failed test 4R.'); |
---|
| 57 | |
---|
| 58 | % 2D FFT code against its own inverse .... |
---|
| 59 | |
---|
| 60 | % Test 1. Verify correct transform and inverse for a real quaternion |
---|
| 61 | % array with a real quaternion axis. |
---|
| 62 | |
---|
| 63 | compare(q, iqfft2(qfft2(q, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 1L.'); |
---|
| 64 | compare(q, iqfft2(qfft2(q, RA, 'R'), RA, 'R'), T, 'qfft2 failed test 1R.'); |
---|
| 65 | |
---|
| 66 | % Test 2. Verify correct transform and inverse for a real quaternion |
---|
| 67 | % array with a complex axis. |
---|
| 68 | |
---|
| 69 | compare(q, iqfft2(qfft2(q, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 2L.'); |
---|
| 70 | compare(q, iqfft2(qfft2(q, CA, 'R'), CA, 'R'), T, 'qfft2 failed test 2R.'); |
---|
| 71 | |
---|
| 72 | % Test 3. Verify correct transform and inverse for a complex quaternion |
---|
| 73 | % array with a complex axis. |
---|
| 74 | |
---|
| 75 | compare(b, iqfft2(qfft2(b, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 3L.'); |
---|
| 76 | compare(b, iqfft2(qfft2(b, CA, 'R'), CA, 'R'), T, 'qfft2 failed test 3R.'); |
---|
| 77 | |
---|
| 78 | % Test 4. Verify correct transform and inverse for a complex quaternion |
---|
| 79 | % array with a real axis. |
---|
| 80 | |
---|
| 81 | compare(b, iqfft2(qfft2(b, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 4L.'); |
---|
| 82 | compare(b, iqfft2(qfft2(b, RA, 'R'), RA, 'R'), T, 'qfft2 failed test 4R.'); |
---|
| 83 | |
---|
| 84 | % 1D FFT code against DFT inverse .... |
---|
| 85 | |
---|
| 86 | % Test 5. Verify correct transform and inverse for a real quaternion |
---|
| 87 | % array with a real quaternion axis. |
---|
| 88 | |
---|
| 89 | compare(q, iqdft(qfft(q, RA, 'L'), RA, 'L'), T, 'qfft failed test 5L.'); |
---|
| 90 | compare(q, iqdft(qfft(q, RA, 'R'), RA, 'R'), T, 'qfft failed test 5R.'); |
---|
| 91 | |
---|
| 92 | % Test 6. Verify correct transform and inverse for a real quaternion |
---|
| 93 | % array with a complex axis. |
---|
| 94 | |
---|
| 95 | compare(q, iqdft(qfft(q, CA, 'L'), CA, 'L'), T, 'qfft failed test 6L.'); |
---|
| 96 | compare(q, iqdft(qfft(q, CA, 'R'), CA, 'R'), T, 'qfft failed test 6R.'); |
---|
| 97 | |
---|
| 98 | % Test 7. Verify correct transform and inverse for a complex quaternion |
---|
| 99 | % array with a complex axis. |
---|
| 100 | |
---|
| 101 | compare(b, iqdft(qfft(b, CA, 'L'), CA, 'L'), T, 'qfft failed test 7L.'); |
---|
| 102 | compare(b, iqdft(qfft(b, CA, 'R'), CA, 'R'), T, 'qfft failed test 7R.'); |
---|
| 103 | |
---|
| 104 | % Test 9. Verify correct transform and inverse for a complex quaternion |
---|
| 105 | % array with a real axis. |
---|
| 106 | |
---|
| 107 | compare(b, iqdft(qfft(b, RA, 'L'), RA, 'L'), T, 'qfft failed test 8L.'); |
---|
| 108 | compare(b, iqdft(qfft(b, RA, 'R'), RA, 'R'), T, 'qfft failed test 8R.'); |
---|
| 109 | |
---|
| 110 | % 2D FFT code against DFT inverse .... |
---|
| 111 | |
---|
| 112 | % Test 5. Verify correct transform and inverse for a real quaternion |
---|
| 113 | % array with a real quaternion axis. |
---|
| 114 | |
---|
| 115 | compare(q, iqdft2(qfft2(q, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 5L.'); |
---|
| 116 | compare(q, iqdft2(qfft2(q, RA, 'R'), RA, 'R'), T, 'qfft2 failed test 5R.'); |
---|
| 117 | |
---|
| 118 | % Test 6. Verify correct transform and inverse for a real quaternion |
---|
| 119 | % array with a complex axis. |
---|
| 120 | |
---|
| 121 | compare(q, iqdft2(qfft2(q, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 6L.'); |
---|
| 122 | compare(q, iqdft2(qfft2(q, CA, 'R'), CA, 'R'), T, 'qfft2 failed test 6R.'); |
---|
| 123 | |
---|
| 124 | % Test 7. Verify correct transform and inverse for a complex quaternion |
---|
| 125 | % array with a complex axis. |
---|
| 126 | |
---|
| 127 | compare(b, iqdft2(qfft2(b, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 7L.'); |
---|
| 128 | compare(b, iqdft2(qfft2(b, CA, 'R'), CA, 'R'), T, 'qfft2 failed test 7R.'); |
---|
| 129 | |
---|
| 130 | % Test 8. Verify correct transform and inverse for a complex quaternion |
---|
| 131 | % array with a real axis. |
---|
| 132 | |
---|
| 133 | compare(b, iqdft2(qfft2(b, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 8L.'); |
---|
| 134 | compare(b, iqdft2(qfft2(b, RA, 'R'), RA, 'R'), T, 'qfft2 failed test 8R.'); |
---|
| 135 | |
---|
| 136 | clear q b T RA CA |
---|