changeset 3916:53acb394c728

[project @ 2002-04-30 03:18:59 by jwe]
author jwe
date Tue, 30 Apr 2002 03:18:59 +0000
parents 2f341412622f
children 5e8e63b22c76
files test/octave.test/signal/detrend-1.m test/octave.test/signal/detrend-2.m test/octave.test/signal/detrend-3.m test/octave.test/signal/fft-1.m test/octave.test/signal/fft2-1.m test/octave.test/signal/ifft-1.m test/octave.test/signal/ifft2-1.m test/octave.test/signal/unwrap-1.m
diffstat 8 files changed, 142 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/detrend-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,9 @@
+## detrend-1.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+N=32;
+x = (0:1:N-1)/N + 2;
+y = detrend(x);
+all (all (abs (y) < 10*eps))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/detrend-2.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,10 @@
+## detrend-2.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+N=32;
+t = (0:1:N-1)/N;
+x = t .* t + 2;
+y = detrend(x,2);
+all (all (abs (y) < 30*eps))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/detrend-3.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,10 @@
+## detrend-3.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+N=32;
+t = (0:1:N-1)/N;
+x = [t;4*t-3]';
+y = detrend(x);
+all (all (abs (y) < 10*eps))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/fft-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,16 @@
+## fft-1.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+N=64;
+n=4;
+t = 2*pi*(0:1:N-1)/N;
+s = cos(n*t);
+S = fft(s);
+
+answer = 0*t;
+answer(n+1) = N/2;
+answer(N-n+1) = N/2;
+
+all( abs(S-answer) < 4*N*eps )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/fft2-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,19 @@
+## fft2-1.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+M=16;
+N=8;
+
+m=5;
+n=3;
+
+x = 2*pi*(0:1:M-1)/M;
+y = 2*pi*(0:1:N-1)/N;
+sx = cos(m*x);
+sy = sin(n*y);
+s=kron(sx',sy);
+S = fft2(s);
+answer = kron(fft(sx)',fft(sy));
+all( all( abs(S-answer) < 4*M*N*eps ) )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/ifft-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,15 @@
+## ifft-1.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+N=64;
+n=7;
+t = 2*pi*(0:1:N-1)/N;
+s = cos(n*t);
+
+S = 0*t;
+S(n+1) = N/2;
+S(N-n+1) = N/2;
+
+all( abs(ifft(S)-s) < 4*N*eps )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/ifft2-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,22 @@
+## ifft2-1.m
+##
+## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
+##         Comalco Research and Technology
+##         02 May 2000
+M=12;
+N=7;
+
+m=3;
+n=2;
+
+x = 2*pi*(0:1:M-1)/M;
+y = 2*pi*(0:1:N-1)/N;
+
+sx = cos(m*x);
+sy = cos(n*y);
+
+S = kron(fft(sx)',fft(sy));
+answer=kron(sx',sy);
+s = ifft2(S);
+
+all( all( abs(s-answer) < 30*eps ) )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/octave.test/signal/unwrap-1.m	Tue Apr 30 03:18:59 2002 +0000
@@ -0,0 +1,41 @@
+1;
+
+function t = assert(a,b,tol)
+  if (nargin == 1)
+    t = all(a(:));
+  else
+    if (nargin == 2)
+      tol = 0;
+    endif
+    if (any (size(a) != size(b)))
+      t = 0;
+    elseif (any (abs(a(:) - b(:)) > tol))
+      t = 0;
+    else
+      t = 1;
+    endif
+  endif
+
+endfunction
+
+i = 0;
+t = [];
+
+r = [0:100];                        # original vector
+w = r - 2*pi*floor((r+pi)/(2*pi));  # wrapped into [-pi,pi]
+tol = 1e3*eps;                      # maximum expected deviation
+
+t(++i) = assert(r, unwrap(w), tol);               #unwrap single row
+t(++i) = assert(r', unwrap(w'), tol);             #unwrap single column
+t(++i) = assert([r',r'], unwrap([w',w']), tol);   #unwrap 2 columns
+t(++i) = assert([r;r], unwrap([w;w],[],1), tol);  #verify that dim works
+t(++i) = assert(r+10, unwrap(10+w), tol);         #verify that r(1)>pi works
+
+t(++i) = assert(w', unwrap(w',[],1));  #unwrap col by rows should not change it
+t(++i) = assert(w, unwrap(w,[],2));    #unwrap row by cols should not change it
+t(++i) = assert([w;w], unwrap([w;w])); #unwrap 2 rows by cols should not change them
+
+## verify that setting tolerance too low will cause bad results.
+t(++i) = assert(any(abs(r - unwrap(w,0.8)) > 100));
+
+all(t)