[37] | 1 | %% Test code for the quaternion conv function. |
---|
| 2 | |
---|
| 3 | % Copyright © 2006 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 4 | % See the file : Copyright.m for further details. |
---|
| 5 | |
---|
| 6 | T = 1e-10; |
---|
| 7 | |
---|
| 8 | %% Test the 1D conv function. |
---|
| 9 | % The method is to construct real vectors and compare the Matlab conv |
---|
| 10 | % function on them with the quaternion conv function operating on |
---|
| 11 | % quaternions with zero vector parts. |
---|
| 12 | |
---|
| 13 | A = randn(1,13); |
---|
| 14 | B = randn(1,5); |
---|
| 15 | C = randn(13,1); |
---|
| 16 | |
---|
| 17 | compare(conv(A, B), s(conv(quaternion(A), quaternion(B))), T, ... |
---|
| 18 | 'quaternion/conv failed test 1') |
---|
| 19 | |
---|
| 20 | compare(conv(B, A), s(conv(quaternion(B), quaternion(A))), T, ... |
---|
| 21 | 'quaternion/conv failed test 2') |
---|
| 22 | |
---|
| 23 | compare(conv(B, C), s(conv(quaternion(B), quaternion(C))), T, ... |
---|
| 24 | 'quaternion/conv failed test 3') |
---|
| 25 | |
---|
| 26 | compare(conv(C, B), s(conv(quaternion(C), quaternion(B))), T, ... |
---|
| 27 | 'quaternion/conv failed test 4') |
---|
| 28 | |
---|
| 29 | compare(conv(A, C), s(conv(quaternion(A), quaternion(C))), T, ... |
---|
| 30 | 'quaternion/conv failed test 5') |
---|
| 31 | |
---|
| 32 | % To test that the right coefficients of quaternion/conv works we supply a |
---|
| 33 | % vector of ones for the first parameter. |
---|
| 34 | |
---|
| 35 | compare(conv(A, B), s(conv({quaternion(ones(size(B))), quaternion(B)}, ... |
---|
| 36 | quaternion(A))), T, 'quaternion/conv failed test 6') |
---|
| 37 | |
---|
| 38 | compare(conv(B, A), s(conv({quaternion(ones(size(A))), quaternion(A)}, ... |
---|
| 39 | quaternion(B))), T, 'quaternion/conv failed test 7') |
---|
| 40 | |
---|
| 41 | compare(conv(B, C), s(conv({quaternion(ones(size(C))), quaternion(C)}, ... |
---|
| 42 | quaternion(B))), T, 'quaternion/conv failed test 8') |
---|
| 43 | |
---|
| 44 | clear A B C |
---|
| 45 | |
---|
| 46 | %% Test the 2D conv function. |
---|
| 47 | % The method is to construct real matrices and compare the Matlab conv |
---|
| 48 | % function on them with the quaternion conv function operating on |
---|
| 49 | % quaternions with zero vector parts. |
---|
| 50 | |
---|
| 51 | A = randn(4,3); |
---|
| 52 | B = randn(6,7); |
---|
| 53 | C = randn(3,4); |
---|
| 54 | |
---|
| 55 | compare(conv2(A, B), s(conv2(quaternion(A), quaternion(B))), T, ... |
---|
| 56 | 'quaternion/conv failed test 9') |
---|
| 57 | |
---|
| 58 | compare(conv2(B, A), s(conv2(quaternion(B), quaternion(A))), T, ... |
---|
| 59 | 'quaternion/conv failed test 10') |
---|
| 60 | |
---|
| 61 | compare(conv2(B, C), s(conv2(quaternion(B), quaternion(C))), T, ... |
---|
| 62 | 'quaternion/conv failed test 11') |
---|
| 63 | |
---|
| 64 | compare(conv2(C, B), s(conv2(quaternion(C), quaternion(B))), T, ... |
---|
| 65 | 'quaternion/conv failed test 12') |
---|
| 66 | |
---|
| 67 | compare(conv2(A, C), s(conv2(quaternion(A), quaternion(C))), T, ... |
---|
| 68 | 'quaternion/conv failed test 13') |
---|
| 69 | |
---|
| 70 | % Test the function with left and right coefficient arrays. |
---|
| 71 | |
---|
| 72 | compare(conv2(A .* C', B), s(conv2({quaternion(A), quaternion(C')}, ... |
---|
| 73 | quaternion(B))), T,... |
---|
| 74 | 'quaternion/conv failed test 14') |
---|
| 75 | |
---|
| 76 | clear A B C T |
---|