5590
|
1 %% Automatically generated from DejaGNU files |
|
2 |
|
3 %% test/octave.test/signal/detrend-1.m |
|
4 %% detrend-1.m |
|
5 %% |
|
6 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
7 %% Comalco Research and Technology |
|
8 %% 02 May 2000 |
|
9 %!test |
|
10 %! N=32; |
|
11 %! x = (0:1:N-1)/N + 2; |
|
12 %! y = detrend(x); |
|
13 %! assert(all (all (abs (y) < 10*eps))); |
|
14 |
|
15 %% test/octave.test/signal/detrend-2.m |
|
16 %% detrend-2.m |
|
17 %% |
|
18 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
19 %% Comalco Research and Technology |
|
20 %% 02 May 2000 |
|
21 %!test |
|
22 %! N=32; |
|
23 %! t = (0:1:N-1)/N; |
|
24 %! x = t .* t + 2; |
|
25 %! y = detrend(x,2); |
|
26 %! assert(all (all (abs (y) < 30*eps))); |
|
27 |
|
28 %% test/octave.test/signal/detrend-3.m |
|
29 %% detrend-3.m |
|
30 %% |
|
31 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
32 %% Comalco Research and Technology |
|
33 %% 02 May 2000 |
|
34 %!test |
|
35 %! N=32; |
|
36 %! t = (0:1:N-1)/N; |
|
37 %! x = [t;4*t-3]'; |
|
38 %! y = detrend(x); |
|
39 %! assert(all (all (abs (y) < 20*eps))); |
|
40 |
|
41 %% test/octave.test/signal/fft-1.m |
|
42 %% fft-1.m |
|
43 %% |
|
44 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
45 %% Comalco Research and Technology |
|
46 %% 02 May 2000 |
|
47 %!test |
|
48 %! N=64; |
|
49 %! n=4; |
|
50 %! t = 2*pi*(0:1:N-1)/N; |
|
51 %! s = cos(n*t); |
|
52 %! S = fft(s); |
|
53 %! |
|
54 %! answer = 0*t; |
|
55 %! answer(n+1) = N/2; |
|
56 %! answer(N-n+1) = N/2; |
|
57 %! |
|
58 %! assert(all( abs(S-answer) < 4*N*eps )); |
|
59 |
|
60 %% test/octave.test/signal/ifft-1.m |
|
61 %% ifft-1.m |
|
62 %% |
|
63 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
64 %% Comalco Research and Technology |
|
65 %% 02 May 2000 |
|
66 %!test |
|
67 %! N=64; |
|
68 %! n=7; |
|
69 %! t = 2*pi*(0:1:N-1)/N; |
|
70 %! s = cos(n*t); |
|
71 %! |
|
72 %! S = 0*t; |
|
73 %! S(n+1) = N/2; |
|
74 %! S(N-n+1) = N/2; |
|
75 %! |
|
76 %! assert(all( abs(ifft(S)-s) < 4*N*eps )); |
|
77 |
|
78 %% test/octave.test/signal/fft2-1.m |
|
79 %% fft2-1.m |
|
80 %% |
|
81 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
82 %% Comalco Research and Technology |
|
83 %% 02 May 2000 |
|
84 %!test |
|
85 %! M=16; |
|
86 %! N=8; |
|
87 %! |
|
88 %! m=5; |
|
89 %! n=3; |
|
90 %! |
|
91 %! x = 2*pi*(0:1:M-1)/M; |
|
92 %! y = 2*pi*(0:1:N-1)/N; |
|
93 %! sx = cos(m*x); |
|
94 %! sy = sin(n*y); |
|
95 %! s=kron(sx',sy); |
|
96 %! S = fft2(s); |
|
97 %! answer = kron(fft(sx)',fft(sy)); |
|
98 %! assert(all( all( abs(S-answer) < 4*M*N*eps ) )); |
|
99 |
|
100 %% test/octave.test/signal/ifft2-1.m |
|
101 %% ifft2-1.m |
|
102 %% |
|
103 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
|
104 %% Comalco Research and Technology |
|
105 %% 02 May 2000 |
|
106 %!test |
|
107 %! M=12; |
|
108 %! N=7; |
|
109 %! |
|
110 %! m=3; |
|
111 %! n=2; |
|
112 %! |
|
113 %! x = 2*pi*(0:1:M-1)/M; |
|
114 %! y = 2*pi*(0:1:N-1)/N; |
|
115 %! |
|
116 %! sx = cos(m*x); |
|
117 %! sy = cos(n*y); |
|
118 %! |
|
119 %! S = kron(fft(sx)',fft(sy)); |
|
120 %! answer=kron(sx',sy); |
|
121 %! s = ifft2(S); |
|
122 %! |
|
123 %! assert(all( all( abs(s-answer) < 30*eps ) )); |
|
124 |
|
125 %% test/octave.test/signal/unwrap-1.m |
|
126 %!function t = assert(a,b,tol) |
|
127 %! if (nargin == 1) |
|
128 %! t = all(a(:)); |
|
129 %! else |
|
130 %! if (nargin == 2) |
|
131 %! tol = 0; |
|
132 %! endif |
|
133 %! if (any (size(a) != size(b))) |
|
134 %! t = 0; |
|
135 %! elseif (any (abs(a(:) - b(:)) > tol)) |
|
136 %! t = 0; |
|
137 %! else |
|
138 %! t = 1; |
|
139 %! endif |
|
140 %! endif |
|
141 %! |
|
142 %!test |
|
143 %! |
|
144 %! i = 0; |
|
145 %! t = []; |
|
146 %! |
|
147 %! r = [0:100]; # original vector |
|
148 %! w = r - 2*pi*floor((r+pi)/(2*pi)); # wrapped into [-pi,pi] |
|
149 %! tol = 1e3*eps; # maximum expected deviation |
|
150 %! |
|
151 %! t(++i) = assert(r, unwrap(w), tol); #unwrap single row |
|
152 %! t(++i) = assert(r', unwrap(w'), tol); #unwrap single column |
|
153 %! t(++i) = assert([r',r'], unwrap([w',w']), tol); #unwrap 2 columns |
|
154 %! t(++i) = assert([r;r], unwrap([w;w],[],2), tol); #verify that dim works |
|
155 %! t(++i) = assert(r+10, unwrap(10+w), tol); #verify that r(1)>pi works |
|
156 %! |
|
157 %! t(++i) = assert(w', unwrap(w',[],2)); #unwrap col by rows should not change it |
|
158 %! t(++i) = assert(w, unwrap(w,[],1)); #unwrap row by cols should not change it |
|
159 %! t(++i) = assert([w;w], unwrap([w;w])); #unwrap 2 rows by cols should not change them |
|
160 %! |
|
161 %! ## verify that setting tolerance too low will cause bad results. |
|
162 %! t(++i) = assert(any(abs(r - unwrap(w,0.8)) > 100)); |
|
163 %! |
|
164 %! assert(all(t)); |
|
165 |