1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) - 2013 - Samuel GOUGEON
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
13 function %_unwrap(typexample)
17 if convstr(typexample)~="2d" then
21 f.figure_size = [800 1000];
22 f.figure_position(2) = 0;
23 f.figure_name = "unwrap() & ""unfold""" + _(": 1-D examples ");
25 ax.y_label.font_size=2;
28 // Original 1-D profile
29 t = linspace(-4,4.2,800);
32 titlepage("unwrap(): unwrap | unfold")
35 t2 = "$\text{Original profile: } \alpha=t^2+t-1$";
37 ax.tight_limits = "on";
38 yT = max(alpha) - strange(alpha)*0.1;
41 e.text_box_mode = "centered";
48 // Wrapping by atan(tan())
49 ralpha = atan(tan(alpha)); // raw recovered alpha [pi]
50 ylabel("$\mbox{Y= }atan(tan(\alpha))$")
51 [u, K] = unwrap(ralpha, %pi); // arctan
52 t2 = "$\text{unwrap(Y, \%pi)}$";
54 // Wrapping by modulo() + Y-shift
55 c = (rand(1,1)-0.5)*4;
56 ralpha = pmodulo(alpha, 5) + c;
57 ylabel("$\mbox{Y= }modulo(\alpha,\ 5)"+sprintf("%+5.2f",c)+"$")
58 [u, K] = unwrap(ralpha, 0);
59 t2 = "$\text{unwrap(Y, 0)}$";
61 // Folding by asin(sin()) + Y-shift
62 ralpha = 1+asin(sin(alpha)); // raw recovered alpha [2.pi]
63 ylabel("$\mbox{Y= }1+asin(sin(\alpha))$")
64 [u, K] = unwrap(ralpha, "unfold");
65 t2 = "$\text{unwrap(Y,""unfold"")}$";
67 // Folding by acos(cos()) + trend
68 ralpha = 1+alpha/10+acos(cos(alpha)); // raw recovered alpha [2.pi]
69 ylabel("$\mbox{Y= }1+\frac{\alpha}{10}+acos(cos(\alpha))$")
70 [u, K] = unwrap(ralpha, "unfold");
71 t2 = "$\text{unwrap(Y,""unfold"")}$";
73 // Plotting the profile to be processed
75 // Staring the breakpoints or the cusp points on the curve:
77 plot(t(K), ralpha(K),"*")
79 // Plotting the processed (unwrapped/unfolded) profile:
83 ax.tight_limits = "on";
85 yT = max(u) - strange(u)*0.2;
88 e.text_box_mode = "centered";
98 ax.title.font_size = 2;
100 f.color_map = hotcolormap(100);
101 f.figure_size = [475 1050];
102 f.figure_position(2) = 0;
103 f.figure_name = "unwrap()" + _(": 2-D examples");
109 x = linspace(-rmax/2, rmax/2, nx)-1;
110 y = linspace(-rmax/2, rmax/2, ny)+1;
111 [X, Y] = meshgrid(x,y);
112 for ex=0:1 // examples
114 // Generating the surface
118 z = sqrt(0.3+sinc(sqrt(z)*3))*17-7;
123 title("Original profile Z")
125 e.thickness = 0; // removes the mesh
126 e.parent.tight_limits = "on";
128 // WRAPPED surface (flat)
130 zw = pmodulo(z, m); // wraps it
133 title(msprintf("Zw = pmodulo(Z, %g) (flat)",m))
135 ax0.tight_limits = "on";
137 // UNWRAPPED surfaces (flat):
138 // in both directions:
142 title(msprintf("unwrap(Zw, %g) (flat)", 0))
144 ax3.tight_limits = "on";
146 if ex==0, direc="r", else direc="c", end
147 // along a single direction:
148 u = unwrap(zw, m, direc);
151 title(msprintf("unwrap(Zw, %g, ""%s"") (flat)",m,direc))
153 ax1.tight_limits = "on";