[37] | 1 | % Test code for the fast quaternion Fourier transform. |
---|
| 2 | % This code tests the following functions: |
---|
| 3 | % |
---|
| 4 | % fft fft2 |
---|
| 5 | % ifft ifft2 |
---|
| 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 the 1D and 2D functions separately because they do not |
---|
| 11 | % call each other. In addition, we need to verify the results of the FFTs |
---|
| 12 | % against the DFT code in the corresponding qdft functions. |
---|
| 13 | |
---|
| 14 | % Test 1. Real data, and therefore real axis, 1D and 2D. |
---|
| 15 | % Check that the transform inverts correctly and then that it agrees with |
---|
| 16 | % the DFT code. |
---|
| 17 | |
---|
| 18 | T = 1e-12; |
---|
| 19 | |
---|
| 20 | q = quaternion(randn(10,10), randn(10,10), randn(10,10), randn(10,10)); |
---|
| 21 | |
---|
| 22 | RA = unit(quaternion(1,1,1)); % Real axis. |
---|
| 23 | |
---|
| 24 | compare(q, ifft(fft(q)), T, 'fft/ifft failed test 1.'); |
---|
| 25 | compare(q, iqdft(fft(q), RA, 'L'), T, 'fft/iqdft failed test 1.'); |
---|
| 26 | compare(q, ifft2(fft2(q)), T, 'fft2/ifft2 failed test 1.'); |
---|
| 27 | compare(q, iqdft2(fft2(q), RA, 'L'), T, 'fft2/iqfft2 failed test 1.'); |
---|
| 28 | |
---|
| 29 | clear q RA |
---|
| 30 | |
---|
| 31 | % Test 2. Complex data, and therefore complex axis, 1D and 2D. |
---|
| 32 | % Check that the transform inverts correctly and then that it agrees with |
---|
| 33 | % the DFT code. |
---|
| 34 | |
---|
| 35 | b = quaternion(complex(randn(10,10),randn(10,10)),... |
---|
| 36 | complex(randn(10,10),randn(10,10)),... |
---|
| 37 | complex(randn(10,10),randn(10,10)),... |
---|
| 38 | complex(randn(10,10),randn(10,10))); |
---|
| 39 | |
---|
| 40 | CA = quaternion(1,1,1) + quaternion(0,1,-1).*i; % Complex axis. |
---|
| 41 | |
---|
| 42 | compare(b, ifft(fft(b)), T, 'fft/ifft failed test 2.'); |
---|
| 43 | compare(b, iqdft(fft(b), CA, 'L'), T, 'fft/iqdft failed test 2.'); |
---|
| 44 | compare(b, ifft2(fft2(b)), T, 'fft2/ifft2 failed test 2.'); |
---|
| 45 | compare(b, iqdft2(fft2(b), CA, 'L'), T, 'fft2/iqfft2 failed test 2.'); |
---|
| 46 | |
---|
| 47 | clear CA b T |
---|