File: unwrap-1.m

package info (click to toggle)
octave2.1 1%3A2.1.73-19
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 37,108 kB
  • ctags: 20,884
  • sloc: cpp: 106,508; fortran: 46,978; ansic: 5,720; sh: 4,991; makefile: 3,230; yacc: 3,132; lex: 2,892; lisp: 1,715; perl: 778; awk: 174; exp: 134
file content (41 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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],[],2), 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',[],2));  #unwrap col by rows should not change it
t(++i) = assert(w, unwrap(w,[],1));    #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)