1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2013 - Samuel GOUGEON
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="unwrap" xml:lang="en">
18 <refname>unwrap</refname>
19 <refpurpose>unwrap a Y(x) profile or a Z(x,y) surface. Unfold a Y(x) profile</refpurpose>
22 <title>Syntaxes</title>
23 <synopsis>unwrap() // runs some examples
24 [U, breakPoints] = unwrap(Y)
25 [U, breakPoints] = unwrap(Y, z_jump)
26 [U, cuspPoints] = unwrap(Y, "unfold")
29 U = unwrap(Z, z_jump, dir)
33 <title>Arguments</title>
38 <para>Vector of real numbers: the profile to unwrap or unfold. Implicit abscissae X are assumed to be equispaced.</para>
44 <para>Matrix of real numbers: the surface to unwrap. Implicit abscissae (X,Y) are assumed to be cartesian and equispaced (constant steps may be different along X versus along Y).</para>
51 Scalar real positive number used in unwrapping mode: the jump's height applied at breakpoints, performing the unwrapping. Only its absolute value is considered. The jump actually applied has the sign of the slope on both sides of each breakpoint. The default value is <literal>z_jump = 2*%pi</literal>. The special value <literal>z_jump = 0</literal> applies jumps equal to the average slope around each breakpoint, restoring a continuous slope over the whole profile or surface.
58 <para>"c" | "r" | "" (default): direction along which unwrapping is performed. "c" unwraps along columns, "r" unwraps along rows, "" unwraps in both directions.</para>
64 <para>Provide this switch to unfold the given curve if it is folded, instead of unwrapping it.</para>
71 Unwrapped profile or surface, or unfolded profile. <varname>U</varname> has the same sizes as <varname>Y</varname> or <varname>Z</varname>.
76 <term>breakPoints, cuspPoints</term>
79 Vector of indices of points in <varname>Y</varname> where wrapping or folding has been detected and processed.
86 <title>Description</title>
87 <para>UNWRAPPING</para>
89 <function>unwrap()</function> will be useful to process profiles or even surfaces wrapped for instance by a periodic and monotonic function such as
90 <literal>Y = modulo(X,w)</literal> or <literal>Y = atan(tan(X))</literal>. It aims to somewhat invert these functions, recovering the input <literal>X</literal> over it full range instead of the limited <literal>w</literal> or <literal>[-%pi/2, %pi/2]</literal> one.
92 <para>A breakpoint of a wrapped profile is detected as a point where slopes on both neighbouring sides of the point are almost equal but much smaller (in absolute value) from and opposite to the slope at the considered point: at the point, there is a jump breaking and opposed to the neighbouring slope.
94 <para>This detection strategy avoids considering any particular level as a wrapping one. It allows to process wrapped profiles to which a constant (or even a trend) has been added afterwards.
97 Unwrapping consists in reducing every detected jump and somewhat restoring a continuous slope (initially assumed to be so). At each point, it is performed by applying a Y-shift on a whole side of the profile, with respect to the other. The Y-shift may be the same for all breakpoints, as provided by the user. If the user specifies a null Y-shift, <function>unwrap()</function> applies a jump equal to the average neighbouring slope, depending on each breakpoint.
99 <warning>An unwrapped profile is always defined but for a constant.</warning>
101 Unless <varname>dir</varname> is used, <function>unwrap()</function> applied to a surface unwraps its first column. Each point of this one is then taken as reference level for unwrapping each line starting with it.
104 <para>UNFOLDING</para>
106 If the <varname>"unfold"</varname> keyword is used and a profile -- not a surface -- is provided, the profile is assumed to be folded instead of being wrapped.
108 <para>At a folding point -- or "cusp point" --, the profile is continuous, but its slope is broken: the slope has almost the same absolute value on both sides of the point, but is somewhat opposed from one side to the other.
111 Folding may occur for instance when a non-monotonic periodic function and its inverse are applied to a profile X, like with <varname>Y= acos(cos(X))</varname>. Recovering X from Y is quite more difficult than if it was wrapped. Indeed, some ambiguous situations may exist, like when the profile is tangentially folded on one of its quasi-horizontal sections (if any).
113 <para>When a cusp point is detected, a) one side of the profile starting from it is opposed (upside down), and b) the continuity of the profile and of its slope are preserved and retrieved at the considered point (this may need adding a small jump by the local slope).</para>
114 <warning>The slope on the left edge of the input profile is used as starting reference. The unfolded profile may be upside down with respect to the original true one. In addition, as for unwrapping, it is defined but for a constant.
116 <para>Known limitations: presently, folded surfaces can't be processed.</para>
119 <title>Examples</title>
120 <para>Unwrapping or unfolding 1D profiles:</para>
121 <programlisting role="example"><![CDATA[
125 f.figure_size = [800 1000];
126 f.figure_position(2) = 0;
127 f.figure_name = "unwrap() & ""unfold""" + _(": 1-D examples ");
129 ax.y_label.font_size=2;
132 // Original 1D profile
133 t = linspace(-4,4.2,800);
136 titlepage("unwrap(): unwrap | unfold")
139 t2 = "$\text{Original profile: } \alpha=t^2+t-1$";
141 ax.tight_limits = "on";
142 yT = max(alpha) - strange(alpha)*0.1;
145 e.text_box_mode = "centered";
152 // Wrapping by atan(tan())
153 ralpha = atan(tan(alpha)); // Raw recovered alpha [pi]
154 ylabel("$atan(tan(\alpha))$")
155 [u, K] = unwrap(ralpha, %pi); // arctan
156 t2 = "$\text{unwrap(Y, \%pi)}$";
158 // Wrapping by modulo() + Y-shift
159 c = (rand(1,1)-0.5)*4;
160 ralpha = pmodulo(alpha, 5) + c;
161 ylabel("$modulo(\alpha,\ 5)"+msprintf("%+5.2f",c)+"$")
162 [u, K] = unwrap(ralpha, 0);
163 t2 = "$\text{unwrap(Y, 0)}$";
165 // Folding by asin(sin()) + Y-shift
166 ralpha = 1+asin(sin(alpha)); // Raw recovered alpha [2.pi]
167 ylabel("$1+asin(sin(\alpha))$")
168 [u, K] = unwrap(ralpha, "unfold");
169 t2 = "$\text{unwrap(Y,""unfold"")}$";
171 // Folding by acos(cos()) + a trend
172 ralpha = 1+alpha/10+acos(cos(alpha)); // Raw recovered alpha [2.pi]
173 ylabel("$1+\frac{\alpha}{10}+acos(cos(\alpha))$")
174 [u, K] = unwrap(ralpha, "unfold");
175 t2 = "$\text{unwrap(Y,""unfold"")}$";
177 // Plotting the profile to be processed
179 // Staring the breakpoints or the cusp points on the curve:
181 plot(t(K), ralpha(K),"*")
183 // Plotting the processed (unwrapped/unfolded) profile:
187 ax.tight_limits = "on";
189 yT = max(u) - strange(u)*0.2;
192 e.text_box_mode = "centered";
201 <para>Unwrapping 2-D surfaces:</para>
202 <programlisting role="example"><![CDATA[
206 ax.title.font_size = 2;
208 f.color_map = hotcolormap(100);
209 f.axes_size = [900 450];
210 f.figure_position(2) = 0;
211 f.figure_name = "unwrap()" + _(": 2-D examples");
217 x = linspace(-rmax/2, rmax/2, nx)-1;
218 y = linspace(-rmax/2, rmax/2, ny)+1;
219 [X, Y] = meshgrid(x,y);
220 for ex=0:1 // examples
222 // Generating the surface
226 z = sqrt(0.3+sinc(sqrt(z)*3))*17-7;
231 title("Original profile Z")
233 e.thickness = 0; // removes the mesh
234 e.parent.tight_limits = "on";
236 // Wrapped surface (flat)
238 zw = pmodulo(z, m); // wraps it
241 title(msprintf("Zw = pmodulo(Z, %g) (flat)",m))
243 ax0.tight_limits = "on";
245 // Unwrapped surfaces (flat):
246 // in both directions:
250 title(msprintf("unwrap(Zw, %g) (flat)", 0))
252 ax3.tight_limits = "on";
259 // Along a single direction:
260 u = unwrap(zw, m, direc);
263 title(msprintf("unwrap(Zw, %g, ""%s"") (flat)",m,direc))
265 ax1.tight_limits = "on";
273 <imagedata fileref="../../images/unwrap_2D.png"/>
277 <refsection role="see also">
278 <title>See also</title>
279 <simplelist type="inline">
281 <link linkend="atan">atan</link>
284 <link linkend="modulo">modulo</link>
288 <refsection role="bibliography">
289 <title>Bibliography</title>
291 <ulink url="http://siptoolbox.sourceforge.net/doc/sip-0.7.0-reference/unwrapl.html">SIP toolbox: unwrap linear</ulink>
294 <ulink url="http://siptoolbox.sourceforge.net/doc/sip-0.7.0-reference/unwrapp.html">SIP toolbox: unwrap along path</ulink>
297 <refsection role="history tag">
298 <title>History</title>
301 <revnumber>5.5.0</revnumber>
302 <revdescription>unwrap() function introduced</revdescription>