annotate scripts/signal/unwrap.m @ 28886:d8318c12d903

test: remove unnecessary BIST tests in m-files checking for excessive number of inputs. Remove BIST tests now that interpreter enforces calling function with no more than the number of arguments defined in the function prototype. * makeUniqueStrings.m, makeValidName.m, base64decode.m, base64encode.m, record.m, sound.m, soundsc.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atan2d.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumdim.m, bincoeff.m, bitget.m, bitset.m, cell2mat.m, circshift.m, cplxpair.m, cumtrapz.m, deg2rad.m, flip.m, fliplr.m, flipud.m, int2str.m, interpft.m, logspace.m, num2str.m, postpad.m, prepad.m, rad2deg.m, rot90.m, rotdim.m, shift.m, subsindex.m, trapz.m, rotx.m, roty.m, rotz.m, getappdata.m, getpixelposition.m, guidata.m, isappdata.m, waitforbuttonpress.m, __gripe_missing_component__.m, bessel.m, hsv2rgb.m, ind2gray.m, rgb2gray.m, rgb2hsv.m, rgbplot.m, fileread.m, javachk.m, usejava.m, findstr.m, genvarname.m, isdir.m, vectorize.m, cond.m, cross.m, duplication_matrix.m, expm.m, isbanded.m, isdefinite.m, isdiag.m, ishermitian.m, issymmetric.m, istril.m, istriu.m, trace.m, vech.m, vecnorm.m, cast.m, citation.m, compare_versions.m, grabcode.m, inputname.m, isfile.m, isfolder.m, ismac.m, ispc.m, isunix.m, list_primes.m, methods.m, news.m, open.m, run.m, swapbytes.m, tar.m, verLessThan.m, zip.m, odeget.m, optimget.m, stemleaf.m, allchild.m, ancestor.m, close.m, groot.m, hgsave.m, isaxes.m, isfigure.m, isgraphics.m, ishandle.m, isprop.m, linkaxes.m, rotate.m, saveas.m, conv.m, poly.m, polyint.m, polyreduce.m, ppval.m, roots.m, addpref.m, getpref.m, ispref.m, rmpref.m, setpref.m, profile.m, profshow.m, powerset.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, hamming.m, hanning.m, ifftshift.m, sinewave.m, spectral_adf.m, spectral_xdf.m, unwrap.m, nonzeros.m, spconvert.m, sprand.m, sprandn.m, beta.m, betainc.m, betaln.m, cosint.m, expint.m, factorial.m, legendre.m, nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m, realsqrt.m, sinint.m, hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, toeplitz.m, vander.m, wilkinson.m, center.m, corr.m, cov.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, empirical_cdf.m, empirical_inv.m, empirical_pdf.m, iqr.m, kendall.m, kurtosis.m, mad.m, meansq.m, median.m, moment.m, prctile.m, quantile.m, range.m, run_count.m, skewness.m, spearman.m, statistics.m, std.m, var.m, base2dec.m, bin2dec.m, blanks.m, dec2base.m, dec2bin.m, dec2hex.m, endsWith.m, erase.m, hex2dec.m, index.m, isletter.m, isstring.m, isstrprop.m, mat2str.m, ostrsplit.m, rindex.m, startsWith.m, strtrunc.m, substr.m, fail.m, addtodate.m, asctime.m, ctime.m, date.m, datestr.m, eomday.m, etime.m, is_leap_year.m, now.m: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
author Rik <rik@octave.org>
date Fri, 09 Oct 2020 13:28:53 -0700
parents 28de41192f3c
children 7854d5752dd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2000-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
7 ##
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
14 ##
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
19 ##
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
25
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
27 ## @deftypefn {} {@var{b} =} unwrap (@var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
28 ## @deftypefnx {} {@var{b} =} unwrap (@var{x}, @var{tol})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
29 ## @deftypefnx {} {@var{b} =} unwrap (@var{x}, @var{tol}, @var{dim})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ##
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
31 ## Unwrap radian phases by adding or subtracting multiples of 2*pi as
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
32 ## appropriate to remove jumps greater than @var{tol}.
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ##
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ## @var{tol} defaults to pi.
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
35 ##
10711
fbd7843974fa Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents: 10690
diff changeset
36 ## Unwrap will work along the dimension @var{dim}. If @var{dim}
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
37 ## is unspecified it defaults to the first non-singleton dimension.
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
38 ## @end deftypefn
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
39
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
40 function retval = unwrap (x, tol, dim)
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
41
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27978
diff changeset
42 if (nargin < 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
43 print_usage ();
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
44 endif
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
45
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
46 if (! isnumeric (x))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11471
diff changeset
47 error ("unwrap: X must be a numeric matrix or vector");
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
48 endif
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
49
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4826
diff changeset
50 if (nargin < 2 || isempty (tol))
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
51 tol = pi;
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
52 endif
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
53
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
54 ## Don't let anyone use a negative value for TOL.
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
55 tol = abs (tol);
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
56
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
57 nd = ndims (x);
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
58 sz = size (x);
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
59 if (nargin == 3)
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 10711
diff changeset
60 if (!(isscalar (dim) && dim == fix (dim))
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 10711
diff changeset
61 || !(1 <= dim && dim <= nd))
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
62 error ("unwrap: DIM must be an integer and a valid dimension");
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
63 endif
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
64 else
12674
9493880928c8 Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
65 ## Find the first non-singleton dimension.
9493880928c8 Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
66 (dim = find (sz > 1, 1)) || (dim = 1);
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
67 endif
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
68
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
69 rng = 2*pi;
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
70 m = sz(dim);
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
71
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
72 ## Handle case where we are trying to unwrap a scalar, or only have
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
73 ## one sample in the specified dimension.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
74 if (m == 1)
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
75 retval = x;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
76 return;
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
77 endif
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
78
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
79 ## Take first order difference to see so that wraps will show up
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
80 ## as large values, and the sign will show direction.
12676
2783fa95cab7 Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents: 12674
diff changeset
81 idx = repmat ({':'}, nd, 1);
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
82 idx{dim} = [1,1:m-1];
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
83 d = x(idx{:}) - x;
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
84
12904
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
85 ## Find only the peaks, and multiply them by the appropriate amount
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
86 ## of ranges so that there are kronecker deltas at each wrap point
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
87 ## multiplied by the appropriate amount of range values.
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
88 p = round (abs (d)./rng) .* rng .* (((d > tol) > 0) - ((d < -tol) > 0));
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
89
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
90 ## Now need to "integrate" this so that the deltas become steps.
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4826
diff changeset
91 r = cumsum (p, dim);
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
92
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
93 ## Now add the "steps" to the original data and put output in the
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
94 ## same shape as originally.
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
95 retval = x + r;
3942
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
96
2ca2d23a49a7 [project @ 2002-05-16 20:27:59 by jwe]
jwe
parents:
diff changeset
97 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7208
diff changeset
98
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
100 %!shared i, t, r, w, tol
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7208
diff changeset
101 %! i = 0;
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7208
diff changeset
102 %! t = [];
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
103 %! r = [0:100]; ## original vector
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
104 %! w = r - 2*pi*floor ((r+pi)/(2*pi)); ## wrapped into [-pi,pi]
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
105 %! tol = 1e3*eps;
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
106
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
107 %!assert (r, unwrap (w), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
108 %!assert (r', unwrap (w'), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
109 %!assert ([r',r'], unwrap ([w',w']), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
110 %!assert ([r; r ], unwrap ([w; w ], [], 2), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
111 %!assert (r + 10, unwrap (10 + w), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
112
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
113 %!assert (w', unwrap (w', [], 2))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
114 %!assert (w, unwrap (w, [], 1))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
115 %!assert ([w; w], unwrap ([w; w]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
116
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
117 ## Test that small values of tol have the same effect as tol = pi
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
118 %!assert (r, unwrap (w, 0.1), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
119 %!assert (r, unwrap (w, eps), tol)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
120
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
121 ## Test that phase changes larger than 2*pi unwrap properly
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
122 %!assert ([0; 1], unwrap ([0; 1]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
123 %!assert ([0; 4 - 2*pi], unwrap ([0; 4]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
124 %!assert ([0; 7 - 2*pi], unwrap ([0; 7]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
125 %!assert ([0; 10 - 4*pi], unwrap ([0; 10]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
126 %!assert ([0; 13 - 4*pi], unwrap ([0; 13]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
127 %!assert ([0; 16 - 6*pi], unwrap ([0; 16]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
128 %!assert ([0; 19 - 6*pi], unwrap ([0; 19]))
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
129 %!assert (max (abs (diff (unwrap (100*pi * rand (1000, 1))))) < pi)
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
130
12904
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
131 %!test
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
132 %! A = [pi*(-4), pi*(-2+1/6), pi/4, pi*(2+1/3), pi*(4+1/2), pi*(8+2/3), pi*(16+1), pi*(32+3/2), pi*64];
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
133 %! assert (unwrap (A), unwrap (A, pi));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
134 %! assert (unwrap (A, pi), unwrap (A, pi, 2));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
135 %! assert (unwrap (A', pi), unwrap (A', pi, 1));
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
136
12904
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
137 %!test
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
138 %! A = [pi*(-4); pi*(2+1/3); pi*(16+1)];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
139 %! B = [pi*(-2+1/6); pi*(4+1/2); pi*(32+3/2)];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
140 %! C = [pi/4; pi*(8+2/3); pi*64];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
141 %! D = [pi*(-2+1/6); pi*(2+1/3); pi*(8+2/3)];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
142 %! E(:, :, 1) = [A, B, C, D];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
143 %! E(:, :, 2) = [A+B, B+C, C+D, D+A];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
144 %! F(:, :, 1) = [unwrap(A), unwrap(B), unwrap(C), unwrap(D)];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
145 %! F(:, :, 2) = [unwrap(A+B), unwrap(B+C), unwrap(C+D), unwrap(D+A)];
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
146 %! assert (unwrap (E), F);
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
147
12904
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
148 %!test
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
149 %! A = [0, 2*pi, 4*pi, 8*pi, 16*pi, 65536*pi];
7cdf39348879 unwrap.m: Fix incorrect behavior when unwrapping gaps larger then 2*pi with tests for it (Bug #33883)
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents: 12676
diff changeset
150 %! B = [pi*(-2+1/6), pi/4, pi*(2+1/3), pi*(4+1/2), pi*(8+2/3), pi*(16+1), pi*(32+3/2), pi*64];
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
151 %! assert (unwrap (A), zeros (1, length (A)));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21386
diff changeset
152 %! assert (diff (unwrap (B), 1) < 2*pi, true (1, length (B)-1));
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
153
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
154 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
155 %!error <Invalid call> unwrap ()
21386
23e8130ed024 unwrap.m: Fix overcompensation for large phase changes (bug #47279)
Mike Miller <mtmiller@octave.org>
parents: 20852
diff changeset
156 %!error unwrap ("foo")