1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of peaklock</title> |
---|
6 | <meta name="keywords" content="peaklock"> |
---|
7 | <meta name="description" content="'peaklock': determines peacklocking errors from velocity histograms."> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../index.html">Home</a> > <a href="index.html">.</a> > peaklock.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>peaklock |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
24 | <div class="box"><strong>'peaklock': determines peacklocking errors from velocity histograms.</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function [histinter,x,error]=peaklock(nbb,minim,maxim,histu) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">'peaklock': determines peacklocking errors from velocity histograms. |
---|
31 | ------------------------------------------------------- |
---|
32 | first smooth the input histogram 'histu' in such a way that the integral over |
---|
33 | n-n+1 is preserved, then deduce the peaklocking 'error' function of the pixcel displacement 'x'. |
---|
34 | |
---|
35 | [histinter,x,error]=peaklock(nbb,minim,maxim,histu) |
---|
36 | OUTPUT: |
---|
37 | histinter: smoothed interpolated histogram |
---|
38 | x: vector of displacement values. |
---|
39 | error: vector of estimated errors corresponding to x |
---|
40 | INPUT: |
---|
41 | histu=vector representing the values of histogram of measured velocity ; |
---|
42 | minim, maxim: extremal values of the measured velocity (absica for histu) |
---|
43 | nbb: number of bins inside each integer interval for the histograms |
---|
44 | SUBROUTINES INCLUDED: |
---|
45 | spline4.m% spline interpolation at 4th order |
---|
46 | splinhist.m: give spline coeff cc for a smooth histo (call spline4) |
---|
47 | histsmooth.m(x,cc): calculate the smooth histo for any value x |
---|
48 | histder.m(x,cc): calculate the derivative of the smooth histo</pre></div> |
---|
49 | |
---|
50 | <!-- crossreference --> |
---|
51 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
52 | This function calls: |
---|
53 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
54 | </ul> |
---|
55 | This function is called by: |
---|
56 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
57 | <li><a href="get_field.html" class="code" title="function varargout = get_field(varargin)">get_field</a> 'get_field': display variables and attributes from a Netcdf file, and plot selected fields</li></ul> |
---|
58 | <!-- crossreference --> |
---|
59 | |
---|
60 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
61 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
62 | <li><a href="#_sub1" class="code">function [histsmooth,cc]= splinhist(Integ,mini,nbb)</a></li><li><a href="#_sub2" class="code">function [histsmooth,bb]= spline4(aa,mini,n)</a></li><li><a href="#_sub3" class="code">function histx= histsmooth(chi,cc)</a></li><li><a href="#_sub4" class="code">function histder= histder(chi,cc)</a></li></ul> |
---|
63 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
64 | <div class="fragment"><pre>0001 <span class="comment">%'peaklock': determines peacklocking errors from velocity histograms.</span> |
---|
65 | 0002 <span class="comment">%-------------------------------------------------------</span> |
---|
66 | 0003 <span class="comment">%first smooth the input histogram 'histu' in such a way that the integral over</span> |
---|
67 | 0004 <span class="comment">%n-n+1 is preserved, then deduce the peaklocking 'error' function of the pixcel displacement 'x'.</span> |
---|
68 | 0005 <span class="comment">%</span> |
---|
69 | 0006 <span class="comment">% [histinter,x,error]=peaklock(nbb,minim,maxim,histu)</span> |
---|
70 | 0007 <span class="comment">%OUTPUT:</span> |
---|
71 | 0008 <span class="comment">%histinter: smoothed interpolated histogram</span> |
---|
72 | 0009 <span class="comment">% x: vector of displacement values.</span> |
---|
73 | 0010 <span class="comment">% error: vector of estimated errors corresponding to x</span> |
---|
74 | 0011 <span class="comment">%INPUT:</span> |
---|
75 | 0012 <span class="comment">%histu=vector representing the values of histogram of measured velocity ;</span> |
---|
76 | 0013 <span class="comment">%minim, maxim: extremal values of the measured velocity (absica for histu)</span> |
---|
77 | 0014 <span class="comment">%nbb: number of bins inside each integer interval for the histograms</span> |
---|
78 | 0015 <span class="comment">%SUBROUTINES INCLUDED:</span> |
---|
79 | 0016 <span class="comment">%spline4.m% spline interpolation at 4th order</span> |
---|
80 | 0017 <span class="comment">%splinhist.m: give spline coeff cc for a smooth histo (call spline4)</span> |
---|
81 | 0018 <span class="comment">%histsmooth.m(x,cc): calculate the smooth histo for any value x</span> |
---|
82 | 0019 <span class="comment">%histder.m(x,cc): calculate the derivative of the smooth histo</span> |
---|
83 | 0020 <a name="_sub0" href="#_subfunctions" class="code">function [histinter,x,error]=peaklock(nbb,minim,maxim,histu)</a> |
---|
84 | 0021 |
---|
85 | 0022 nint=maxim-minim+1 |
---|
86 | 0023 xfin=[minim-0.5+1/(2*nbb):(1/nbb):maxim+0.5-(1/(2*nbb))]; |
---|
87 | 0024 histo=(reshape(histu,nbb,nint));<span class="comment">%extract values with x between integer -1/2 integer +1/2</span> |
---|
88 | 0025 Integ=sum(histo)/nbb; <span class="comment">%integral of the pdf on each integer bin</span> |
---|
89 | 0026 [histinter,cc]=<a href="#_sub1" class="code" title="subfunction [histsmooth,cc]= splinhist(Integ,mini,nbb)">splinhist</a>(Integ,minim,nbb); |
---|
90 | 0027 histx=reshape(histinter,nbb,nint); |
---|
91 | 0028 xint=[minim:1:maxim]; |
---|
92 | 0029 x=zeros(nbb,nint); |
---|
93 | 0030 <span class="comment">%determination of the displacement x(j,:)</span> |
---|
94 | 0031 <span class="comment">%j=1</span> |
---|
95 | 0032 delx=histo(1,:)./<a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>(-0.5*ones(1,nint),cc)/nbb; |
---|
96 | 0033 <span class="comment">%del(1,:)=delx;</span> |
---|
97 | 0034 x(1,:)=-0.5+delx-(delx.*delx/2).*<a href="#_sub4" class="code" title="subfunction histder= histder(chi,cc)">histder</a>(-0.5*ones(1,nint),cc); |
---|
98 | 0035 <span class="comment">%histx(1,:)=histsmooth(x(j-1,:),cc);</span> |
---|
99 | 0036 <span class="keyword">for</span> j=2:nbb |
---|
100 | 0037 delx=histo(j,:)./<a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>(x(j-1,:),cc)/nbb; |
---|
101 | 0038 <span class="comment">%delx=delx.*(delx<3*ones(1,nint)/nbb)+3*ones(1,nint)/nbb.*~(delx <3*ones(1,nint)/nbb)</span> |
---|
102 | 0039 x(j,:)=x(j-1,:)+delx-(delx.*delx/2).*<a href="#_sub4" class="code" title="subfunction histder= histder(chi,cc)">histder</a>(x(j-1,:),cc); |
---|
103 | 0040 <span class="keyword">end</span> |
---|
104 | 0041 <span class="comment">%reshape</span> |
---|
105 | 0042 xint=ones(nbb,1)*xint; |
---|
106 | 0043 x=x+xint; |
---|
107 | 0044 x=reshape(x,1,nbb*nint); |
---|
108 | 0045 error=xfin+1/(2*nbb)-x; |
---|
109 | 0046 |
---|
110 | 0047 <span class="comment">%-------------------------------------------------------</span> |
---|
111 | 0048 <span class="comment">% --- determine the spline coefficients cc for the interpolated histogram.</span> |
---|
112 | 0049 <span class="comment">%-------------------------------------------------</span> |
---|
113 | 0050 <a name="_sub1" href="#_subfunctions" class="code">function [histsmooth,cc]= splinhist(Integ,mini,nbb)</a> |
---|
114 | 0051 <span class="comment">% provides a smooth histogramm histmooth, which remains always positive,</span> |
---|
115 | 0052 <span class="comment">% and is such that its sum over each integer bin [i-1/2 i+1/2] is equal to</span> |
---|
116 | 0053 <span class="comment">% Integ(i). The function determines histmooth as the exponential of a 4th</span> |
---|
117 | 0054 <span class="comment">% order spline function and adjust the cefficients by a Newton method to</span> |
---|
118 | 0055 <span class="comment">% fit the integral conditions Integ</span> |
---|
119 | 0056 <span class="comment">% histmooth is determined at the abscissa</span> |
---|
120 | 0057 <span class="comment">% xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))] (maxi=mini+size(aa)-1)</span> |
---|
121 | 0058 <span class="comment">%cc(1-5,i) provides the spline coefficients</span> |
---|
122 | 0059 |
---|
123 | 0060 <span class="comment">% order 0</span> |
---|
124 | 0061 siz=size(Integ); |
---|
125 | 0062 nint=siz(2); |
---|
126 | 0063 izero=find(Integ==0); <span class="comment">%indices of zero elements</span> |
---|
127 | 0064 inonzero=find(Integ); |
---|
128 | 0065 Integ(izero)=min(Integ(inonzero)); |
---|
129 | 0066 aa=log(Integ);<span class="comment">%initial guess for a coeff</span> |
---|
130 | 0067 spli=<a href="#_sub2" class="code" title="subfunction [histsmooth,bb]= spline4(aa,mini,n)">spline4</a>(aa,mini,nbb); <span class="comment">%appel à la fonction spline4</span> |
---|
131 | 0068 <a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>=exp(spli); |
---|
132 | 0069 |
---|
133 | 0070 S=(sum(reshape(<a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>,nbb,nint)))/nbb;<span class="comment">% integral of the fit histsmooth on ]i-1/2 i+1/2[</span> |
---|
134 | 0071 epsilon=max(abs(Integ-S)); |
---|
135 | 0072 iter=0; |
---|
136 | 0073 <span class="keyword">while</span> epsilon > 0.000001 & iter<10 |
---|
137 | 0074 ident=eye(nint); |
---|
138 | 0075 dSda=ones(nint); |
---|
139 | 0076 <span class="keyword">for</span> j=1:nint<span class="comment">% determination of the jacobian matrix dSda</span> |
---|
140 | 0077 dhistda=<a href="#_sub2" class="code" title="subfunction [histsmooth,bb]= spline4(aa,mini,n)">spline4</a>(ident(j,:),mini,nbb); |
---|
141 | 0078 expdhistda=dhistda.*<a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>; |
---|
142 | 0079 dSda(j,:)=(sum(reshape(expdhistda,nbb,nint)))/nbb; |
---|
143 | 0080 <span class="keyword">end</span> |
---|
144 | 0081 aa=aa+(Integ-S)*inv(dSda);<span class="comment">%new estimate of coefficients aa by linear interpolation</span> |
---|
145 | 0082 [spli,bb]=<a href="#_sub2" class="code" title="subfunction [histsmooth,bb]= spline4(aa,mini,n)">spline4</a>(aa,mini,nbb);<span class="comment">% new fit histsmooth</span> |
---|
146 | 0083 <a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>=exp(spli); |
---|
147 | 0084 S=(sum(reshape(<a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>,nbb,nint)))/nbb;<span class="comment">% integral of the fit histsmooth on ]i-1/2 i+1/2[</span> |
---|
148 | 0085 epsilon=max(abs(Integ-S)); |
---|
149 | 0086 iter=iter+1; |
---|
150 | 0087 <span class="keyword">end</span> |
---|
151 | 0088 <span class="keyword">if</span> iter==10, errordlg(<span class="string">'splinhist did not converge after 10 iterations'</span>),<span class="keyword">end</span> |
---|
152 | 0089 cc(1,:)=aa; |
---|
153 | 0090 cc(2,:)=bb(1,:); |
---|
154 | 0091 cc(3,:)=bb(2,:); |
---|
155 | 0092 cc(4,:)=bb(3,:); |
---|
156 | 0093 cc(5,:)=bb(4,:); |
---|
157 | 0094 |
---|
158 | 0095 <span class="comment">%-------------------------------------------------------</span> |
---|
159 | 0096 <span class="comment">% --- determine the 4th order spline coefficients from the function values aa.</span> |
---|
160 | 0097 <span class="comment">%-------------------------------------------------</span> |
---|
161 | 0098 <a name="_sub2" href="#_subfunctions" class="code">function [histsmooth,bb]= spline4(aa,mini,n)</a> |
---|
162 | 0099 <span class="comment">% spline interpolation at 4th order</span> |
---|
163 | 0100 <span class="comment">%aa=vector of values of a function at integer abscissa, starting at mini</span> |
---|
164 | 0101 <span class="comment">%n=number of subdivisions for the interpolated function</span> |
---|
165 | 0102 <span class="comment">% histmooth =interpolated values at absissa</span> |
---|
166 | 0103 <span class="comment">% xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))] (maxi=mini+size(aa)-1)</span> |
---|
167 | 0104 <span class="comment">%bb=[b(i);c(i);d(i); e(i)] matrix of spline coeff</span> |
---|
168 | 0105 L1=[1/2 1/4 1/8 1/16;1 1 3/4 1/2;0 2 3 3;0 0 6 12]; |
---|
169 | 0106 L2=[-1/2 1/4 -1/8 1/16;1 -1 3/4 -1/2;0 2 -3 3;0 0 6 -12]; |
---|
170 | 0107 M=inv(L2)*L1; |
---|
171 | 0108 [V,D]=eig(M); |
---|
172 | 0109 F=-inv(V)*inv(L2)*[1 ;0 ;0;0]; |
---|
173 | 0110 a1rev=[1 -1/D(1,1)]; |
---|
174 | 0111 b1rev=[F(1)/D(1,1)]; |
---|
175 | 0112 a2rev=[1 -1/D(2,2)]; |
---|
176 | 0113 b2rev=[F(2)/D(2,2)]; |
---|
177 | 0114 a3=[1 -D(3,3)]; |
---|
178 | 0115 b3=[F(3)]; |
---|
179 | 0116 a4=[1 -D(4,4)]; |
---|
180 | 0117 b4=[F(4)]; |
---|
181 | 0118 |
---|
182 | 0119 <span class="comment">%data</span> |
---|
183 | 0120 <span class="comment">% n=10;% résolution de la pdf: nbre de points par unite de u</span> |
---|
184 | 0121 <span class="comment">% mini=-10.0;%general mini=uint16(min(values)-1 CHOOSE maxi-mini+1 EVEN</span> |
---|
185 | 0122 <span class="comment">% maxi=9.0; % general maxi=uint16(max(values))+1</span> |
---|
186 | 0123 <span class="comment">%nint=double(maxi-mini+1); % nombre d'intervals entiers EVEN!</span> |
---|
187 | 0124 siz=size(aa); |
---|
188 | 0125 nint=siz(2); |
---|
189 | 0126 maxi=mini+nint-1; |
---|
190 | 0127 npdf=nint*n;<span class="comment">% nbre total d'intervals à introduire dans la pdf: hist(u,npdf)</span> |
---|
191 | 0128 <span class="comment">%simulation de pdf</span> |
---|
192 | 0129 xfin=[mini-0.5+1/(2*n):(1/n):maxi+0.5-(1/(2*n))];<span class="comment">% valeurs d'interpolation: we take n values in each integer interval</span> |
---|
193 | 0130 <span class="comment">%histolin=exp(-(xfin-1).*(xfin-1)).*(2+cos(10*(xfin-1)));% simulation d'une pdf</span> |
---|
194 | 0131 <span class="comment">%histo=log(histolin);</span> |
---|
195 | 0132 <span class="comment">%histo=sin(2*pi*xfin);</span> |
---|
196 | 0133 <span class="comment">%histextract=(reshape(histo,n,nint));</span> |
---|
197 | 0134 <span class="comment">%aa=sum(histextract)/n %integral of the pdf on each integer bin</span> |
---|
198 | 0135 IP=[0 diff(aa)]; |
---|
199 | 0136 Irev=zeros(size(aa)); |
---|
200 | 0137 <span class="keyword">for</span> i=1:nint |
---|
201 | 0138 Irev(i)=aa(end-i+1); |
---|
202 | 0139 <span class="keyword">end</span> |
---|
203 | 0140 IPrev=[0 diff(Irev)]; |
---|
204 | 0141 |
---|
205 | 0142 <span class="comment">%get the spline coelfficients a_d, using filter on the eigen vectors A,B,C</span> |
---|
206 | 0143 Arev=filter(b1rev,a1rev,IPrev); |
---|
207 | 0144 Brev=filter(b2rev,a2rev,IPrev); |
---|
208 | 0145 C=filter(b3,a3,IP); |
---|
209 | 0146 D=filter(b4,a4,IP); |
---|
210 | 0147 A=zeros(size(Arev)); |
---|
211 | 0148 B=zeros(size(Brev)); |
---|
212 | 0149 <span class="keyword">for</span> i=1:nint |
---|
213 | 0150 A(i)=Arev(end-i+1); |
---|
214 | 0151 B(i)=Brev(end-i+1); |
---|
215 | 0152 <span class="keyword">end</span> |
---|
216 | 0153 <span class="comment">%Matr=V*[A;B;C;D];</span> |
---|
217 | 0154 bb=V*[A;B;C;D]; |
---|
218 | 0155 <span class="comment">%b=Matr(1,:);</span> |
---|
219 | 0156 <span class="comment">%c=Matr(2,:);</span> |
---|
220 | 0157 <span class="comment">%d=Matr(3,:);</span> |
---|
221 | 0158 <span class="comment">%e=Matr(4,:);</span> |
---|
222 | 0159 <span class="comment">%a=aa;</span> |
---|
223 | 0160 |
---|
224 | 0161 <span class="comment">%calculate the interpolation using the spline coefficients a-d</span> |
---|
225 | 0162 <span class="comment">%xextract=(reshape(xfin,n,nint));%</span> |
---|
226 | 0163 chi=xfin+1/(2*n)-min(xfin)-double(int16(xfin+(1/(2*n))-min(xfin)))-0.5;<span class="comment">% decimal part</span> |
---|
227 | 0164 chi2=chi.*chi; |
---|
228 | 0165 chi3=chi2.*chi; |
---|
229 | 0166 chi4=chi3.*chi; |
---|
230 | 0167 avec=reshape(ones(n,1)*aa,1,n*nint); |
---|
231 | 0168 bvec=reshape(ones(n,1)*bb(1,:),1,n*nint); |
---|
232 | 0169 cvec=reshape(ones(n,1)*bb(2,:),1,n*nint); |
---|
233 | 0170 dvec=reshape(ones(n,1)*bb(3,:),1,n*nint); |
---|
234 | 0171 evec=reshape(ones(n,1)*bb(4,:),1,n*nint); |
---|
235 | 0172 <a href="#_sub3" class="code" title="subfunction histx= histsmooth(chi,cc)">histsmooth</a>=avec+bvec.*chi+cvec.*chi2+dvec.*chi3+evec.*chi4; |
---|
236 | 0173 |
---|
237 | 0174 <span class="comment">%-------------------------------------------------------</span> |
---|
238 | 0175 <span class="comment">% --- determine the interpolated histogram at points chi from the spline ceff cc.</span> |
---|
239 | 0176 <span class="comment">%-------------------------------------------------</span> |
---|
240 | 0177 <a name="_sub3" href="#_subfunctions" class="code">function histx= histsmooth(chi,cc)</a> |
---|
241 | 0178 <span class="comment">% provides the value of the interpolated histogram at values chi=x-i</span> |
---|
242 | 0179 <span class="comment">%(difference with the mnearest integer)</span> |
---|
243 | 0180 <span class="comment">% cc(5,size(chi)) is the set of spline coefficients obtained by splinhist</span> |
---|
244 | 0181 chi2=chi.*chi; |
---|
245 | 0182 chi3=chi2.*chi; |
---|
246 | 0183 chi4=chi3.*chi; |
---|
247 | 0184 histx=exp(cc(1,:)+cc(2,:).*chi+cc(3,:).*chi2+cc(4,:).*chi3+cc(5,:).*chi4); |
---|
248 | 0185 |
---|
249 | 0186 <span class="comment">%-------------------------------------------------------</span> |
---|
250 | 0187 <span class="comment">% --- determine the derivative p'/p of the interpolated histogram at points chi from the spline ceff cc.</span> |
---|
251 | 0188 <span class="comment">%-------------------------------------------------</span> |
---|
252 | 0189 <a name="_sub4" href="#_subfunctions" class="code">function histder= histder(chi,cc)</a> |
---|
253 | 0190 <span class="comment">% provides the logarithmique derivative p'/p of the interpolated histogram</span> |
---|
254 | 0191 <span class="comment">%at values chi=x-i</span> |
---|
255 | 0192 <span class="comment">%(difference with the nearest integer)</span> |
---|
256 | 0193 <span class="comment">% cc(5,size(chi)) is the set of spline coefficients obtained by splinhist</span> |
---|
257 | 0194 chi2=chi.*chi; |
---|
258 | 0195 chi3=chi2.*chi; |
---|
259 | 0196 chi4=chi3.*chi; |
---|
260 | 0197 <a href="#_sub4" class="code" title="subfunction histder= histder(chi,cc)">histder</a>=cc(2,:)+2*cc(3,:).*chi+3*cc(4,:).*chi2+4*cc(5,:).*chi3;</pre></div> |
---|
261 | <hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
262 | </body> |
---|
263 | </html> |
---|