7017
|
1 ## Copyright (C) 2006, 2007 John W. Eaton |
7016
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
5590
|
19 %% Automatically generated from DejaGNU files |
|
20 |
|
21 %% test/octave.test/signal/fft-1.m |
|
22 %% fft-1.m |
|
23 %% |
|
24 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
25 %% Comalco Research and Technology |
|
26 %% 02 May 2000 |
|
27 %!test |
|
28 %! N=64; |
|
29 %! n=4; |
|
30 %! t = 2*pi*(0:1:N-1)/N; |
|
31 %! s = cos(n*t); |
|
32 %! S = fft(s); |
|
33 %! |
|
34 %! answer = 0*t; |
|
35 %! answer(n+1) = N/2; |
|
36 %! answer(N-n+1) = N/2; |
|
37 %! |
|
38 %! assert(all( abs(S-answer) < 4*N*eps )); |
|
39 |
|
40 %% test/octave.test/signal/ifft-1.m |
|
41 %% ifft-1.m |
|
42 %% |
|
43 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
44 %% Comalco Research and Technology |
|
45 %% 02 May 2000 |
|
46 %!test |
|
47 %! N=64; |
|
48 %! n=7; |
|
49 %! t = 2*pi*(0:1:N-1)/N; |
|
50 %! s = cos(n*t); |
|
51 %! |
|
52 %! S = 0*t; |
|
53 %! S(n+1) = N/2; |
|
54 %! S(N-n+1) = N/2; |
|
55 %! |
|
56 %! assert(all( abs(ifft(S)-s) < 4*N*eps )); |
|
57 |
|
58 %% test/octave.test/signal/fft2-1.m |
|
59 %% fft2-1.m |
|
60 %% |
|
61 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
62 %% Comalco Research and Technology |
|
63 %% 02 May 2000 |
|
64 %!test |
|
65 %! M=16; |
|
66 %! N=8; |
|
67 %! |
|
68 %! m=5; |
|
69 %! n=3; |
|
70 %! |
|
71 %! x = 2*pi*(0:1:M-1)/M; |
|
72 %! y = 2*pi*(0:1:N-1)/N; |
|
73 %! sx = cos(m*x); |
|
74 %! sy = sin(n*y); |
|
75 %! s=kron(sx',sy); |
|
76 %! S = fft2(s); |
|
77 %! answer = kron(fft(sx)',fft(sy)); |
|
78 %! assert(all( all( abs(S-answer) < 4*M*N*eps ) )); |
|
79 |
|
80 %% test/octave.test/signal/ifft2-1.m |
|
81 %% ifft2-1.m |
|
82 %% |
|
83 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
84 %% Comalco Research and Technology |
|
85 %% 02 May 2000 |
|
86 %!test |
|
87 %! M=12; |
|
88 %! N=7; |
|
89 %! |
|
90 %! m=3; |
|
91 %! n=2; |
|
92 %! |
|
93 %! x = 2*pi*(0:1:M-1)/M; |
|
94 %! y = 2*pi*(0:1:N-1)/N; |
|
95 %! |
|
96 %! sx = cos(m*x); |
|
97 %! sy = cos(n*y); |
|
98 %! |
|
99 %! S = kron(fft(sx)',fft(sy)); |
|
100 %! answer=kron(sx',sy); |
|
101 %! s = ifft2(S); |
|
102 %! |
|
103 %! assert(all( all( abs(s-answer) < 30*eps ) )); |
|
104 |
|
105 %% test/octave.test/signal/unwrap-1.m |
6699
|
106 %!function t = xassert(a,b,tol) |
5590
|
107 %! if (nargin == 1) |
|
108 %! t = all(a(:)); |
|
109 %! else |
|
110 %! if (nargin == 2) |
|
111 %! tol = 0; |
|
112 %! endif |
|
113 %! if (any (size(a) != size(b))) |
|
114 %! t = 0; |
|
115 %! elseif (any (abs(a(:) - b(:)) > tol)) |
|
116 %! t = 0; |
|
117 %! else |
|
118 %! t = 1; |
|
119 %! endif |
|
120 %! endif |
|
121 %! |
|
122 %!test |
|
123 %! |
|
124 %! i = 0; |
|
125 %! t = []; |
|
126 %! |
|
127 %! r = [0:100]; # original vector |
|
128 %! w = r - 2*pi*floor((r+pi)/(2*pi)); # wrapped into [-pi,pi] |
|
129 %! tol = 1e3*eps; # maximum expected deviation |
|
130 %! |
6699
|
131 %! t(++i) = xassert(r, unwrap(w), tol); #unwrap single row |
|
132 %! t(++i) = xassert(r', unwrap(w'), tol); #unwrap single column |
|
133 %! t(++i) = xassert([r',r'], unwrap([w',w']), tol); #unwrap 2 columns |
|
134 %! t(++i) = xassert([r;r], unwrap([w;w],[],2), tol); #verify that dim works |
|
135 %! t(++i) = xassert(r+10, unwrap(10+w), tol); #verify that r(1)>pi works |
5590
|
136 %! |
6699
|
137 %! t(++i) = xassert(w', unwrap(w',[],2)); #unwrap col by rows should not change it |
|
138 %! t(++i) = xassert(w, unwrap(w,[],1)); #unwrap row by cols should not change it |
|
139 %! t(++i) = xassert([w;w], unwrap([w;w])); #unwrap 2 rows by cols should not change them |
5590
|
140 %! |
|
141 %! ## verify that setting tolerance too low will cause bad results. |
6699
|
142 %! t(++i) = xassert(any(abs(r - unwrap(w,0.8)) > 100)); |
5590
|
143 %! |
|
144 %! assert(all(t)); |
|
145 |