Mercurial > octave-nkf
diff scripts/signal/unwrap.m @ 7411:83a8781b529d
[project @ 2008-01-22 21:52:25 by jwe]
author | jwe |
---|---|
date | Tue, 22 Jan 2008 21:52:26 +0000 |
parents | a730e47fda4d |
children | eb63fbe60fab |
line wrap: on
line diff
--- a/scripts/signal/unwrap.m Tue Jan 22 21:34:24 2008 +0000 +++ b/scripts/signal/unwrap.m Tue Jan 22 21:52:26 2008 +0000 @@ -93,3 +93,44 @@ retval = a + r; endfunction + +%!function t = xassert(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 +%! +%!test +%! +%! 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) = xassert(r, unwrap(w), tol); #unwrap single row +%! t(++i) = xassert(r', unwrap(w'), tol); #unwrap single column +%! t(++i) = xassert([r',r'], unwrap([w',w']), tol); #unwrap 2 columns +%! t(++i) = xassert([r;r], unwrap([w;w],[],2), tol); #verify that dim works +%! t(++i) = xassert(r+10, unwrap(10+w), tol); #verify that r(1)>pi works +%! +%! t(++i) = xassert(w', unwrap(w',[],2)); #unwrap col by rows should not change it +%! t(++i) = xassert(w, unwrap(w,[],1)); #unwrap row by cols should not change it +%! t(++i) = xassert([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) = xassert(any(abs(r - unwrap(w,0.8)) > 100)); +%! +%! assert(all(t)); +