source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/qtfm/test/test_qfft.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 5.4 KB
Line 
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
21q = quaternion(randn(10,10), randn(10,10), randn(10,10), randn(10,10));
22b = quaternion(complex(randn(10,10)),complex(randn(10,10)),...
23               complex(randn(10,10)),complex(randn(10,10)));
24T = 1e-12;
25
26RA = unit(quaternion(1,1,1));                        % Real axis.
27CA = complex(quaternion(1,1,1), quaternion(0,1,-1)); % Complex axis.
28
29if  isreal(CA) error('Complex axis is not complex.'); end
30if ~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
37compare(q, iqfft(qfft(q, RA, 'L'), RA, 'L'), T, 'qfft failed test 1L.');
38compare(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
43compare(q, iqfft(qfft(q, CA, 'L'), CA, 'L'), T, 'qfft failed test 2L.');
44compare(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
49compare(b, iqfft(qfft(b, CA, 'L'), CA, 'L'), T, 'qfft failed test 3L.');
50compare(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
55compare(b, iqfft(qfft(b, RA, 'L'), RA, 'L'), T, 'qfft failed test 4L.');
56compare(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
63compare(q, iqfft2(qfft2(q, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 1L.');
64compare(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
69compare(q, iqfft2(qfft2(q, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 2L.');
70compare(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
75compare(b, iqfft2(qfft2(b, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 3L.');
76compare(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
81compare(b, iqfft2(qfft2(b, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 4L.');
82compare(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
89compare(q, iqdft(qfft(q, RA, 'L'), RA, 'L'), T, 'qfft failed test 5L.');
90compare(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
95compare(q, iqdft(qfft(q, CA, 'L'), CA, 'L'), T, 'qfft failed test 6L.');
96compare(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
101compare(b, iqdft(qfft(b, CA, 'L'), CA, 'L'), T, 'qfft failed test 7L.');
102compare(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
107compare(b, iqdft(qfft(b, RA, 'L'), RA, 'L'), T, 'qfft failed test 8L.');
108compare(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
115compare(q, iqdft2(qfft2(q, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 5L.');
116compare(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
121compare(q, iqdft2(qfft2(q, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 6L.');
122compare(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
127compare(b, iqdft2(qfft2(b, CA, 'L'), CA, 'L'), T, 'qfft2 failed test 7L.');
128compare(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
133compare(b, iqdft2(qfft2(b, RA, 'L'), RA, 'L'), T, 'qfft2 failed test 8L.');
134compare(b, iqdft2(qfft2(b, RA, 'R'), RA, 'R'), T, 'qfft2 failed test 8R.');
135
136clear q b T RA CA
Note: See TracBrowser for help on using the repository browser.