1 | function [ChiV,Corr,ExterProfile]=PositionDirection(prof2,prof)
|
---|
2 | [ChiV1,Corr1,ExterProfile1]=Position(prof2,prof);
|
---|
3 | [ChiV2,Corr2,ExterProfile2]=Position(fliplr(prof2),prof);
|
---|
4 | if ChiV1<ChiV2
|
---|
5 | ChiV=ChiV1;
|
---|
6 | Corr=Corr1;
|
---|
7 | ExterProfile=ExterProfile1;
|
---|
8 | else
|
---|
9 | ChiV=ChiV2;
|
---|
10 | Corr=Corr2;
|
---|
11 | ExterProfile=ExterProfile2;
|
---|
12 | end
|
---|
13 | end
|
---|
14 |
|
---|
15 |
|
---|
16 | function [ChiV,Corr,ExterProfile]=Position(prof2,prof)
|
---|
17 | c1=find(cumsum(prof2)>=(sum(prof2)/2),1);
|
---|
18 | c2=find(cumsum(prof)>=(sum(prof)/2),1);
|
---|
19 | fi=(1+sqrt(5))/2;
|
---|
20 | T=100;
|
---|
21 | a=c2-T; b=c2+T;
|
---|
22 | while(abs(b-a)>1)
|
---|
23 | x1=b-(b-a)/fi;
|
---|
24 | x2=a+(b-a)/fi;
|
---|
25 | y1=Chi(circshift(prof2,[ 1 round(x1)-c1]),prof);
|
---|
26 | y2=Chi(circshift(prof2,[ 1 round(x2)-c1]),prof);
|
---|
27 | if(y1<=y2)
|
---|
28 | b=x2;
|
---|
29 | else
|
---|
30 | a=x1;
|
---|
31 | end
|
---|
32 | end
|
---|
33 | y1=Chi(circshift(prof2,[ 1 round(a)-c1]),prof);
|
---|
34 | y2=Chi(circshift(prof2,[ 1 round(b)-c1]),prof);
|
---|
35 | if ((y1-y2)>0) rez=b; ChiV=y2;
|
---|
36 | else rez=a;ChiV=y1
|
---|
37 | end
|
---|
38 | ExterProfile=circshift(prof2,[ 1 round(rez)-c1]);
|
---|
39 | Corr=sum(prof.*ExterProfile)/(sqrt(sum((prof).^2))*sqrt(sum((ExterProfile).^2)));
|
---|
40 | end
|
---|
41 |
|
---|
42 | function Chi=Chi(funk1,funk2)
|
---|
43 | Chi=sum((funk1-funk2).^2./abs(funk1+funk2+1e-10)./(length(funk1)));
|
---|
44 | end
|
---|
45 | % %one side
|
---|
46 | % c1=centerOFweight(abs(funk1));%find center of weight of function
|
---|
47 | % c2=centerOFweight(funk2b);%base funk
|
---|
48 | % c1=c1-(T+1);
|
---|
49 | % for i=1:(2*T+1)
|
---|
50 | % c1=c1+1;
|
---|
51 | % delta=c2-c1;
|
---|
52 | % N1=zeros(size(funk1));
|
---|
53 | % if delta>0
|
---|
54 | % N1(delta:end)=funk1(1:length(funk1)-delta+1);
|
---|
55 | % end
|
---|
56 | % if c1==c2
|
---|
57 | % N1=funk1;
|
---|
58 | % end
|
---|
59 | % if delta<0
|
---|
60 | % N1(1:end+delta+1)=funk1(-delta:end);
|
---|
61 | % end
|
---|
62 | %
|
---|
63 |
|
---|
64 | % [chi1(i),cor1(i)]=ChiCor(N1,funk2b);
|
---|
65 | % end
|
---|
66 |
|
---|
67 | % [chi1V,chi1P]=min(chi1);
|
---|
68 | % [cor1V,cor1P]=max(cor1);
|
---|
69 | %
|
---|
70 | % %Other side
|
---|
71 | % funk1fliped=flip(funk1);
|
---|
72 | % c1=centerOFweight(abs(funk1fliped));%find center of weight of function
|
---|
73 | % c2=centerOFweight(funk2b);
|
---|
74 | % c1=c1-(T+1);
|
---|
75 | % for i=1:(2*T+1)
|
---|
76 | % c1=c1+1;
|
---|
77 | % delta=c2-c1;
|
---|
78 | % N1=zeros(size(funk1));
|
---|
79 | % if delta>0
|
---|
80 | % N1(delta:length(N1))=funk1fliped(1:length(funk1)-delta+1);
|
---|
81 | % end
|
---|
82 | % if c1==c2
|
---|
83 | % N1=funk1;
|
---|
84 | % end
|
---|
85 | % if delta<0
|
---|
86 | % N1(1:length(N1)+delta+1)=funk1fliped(-delta:length(funk1));
|
---|
87 | % end
|
---|
88 | %
|
---|
89 | % [chi2(i),cor2(i)]=ChiCor(N1,funk2b);
|
---|
90 | % end
|
---|
91 | % [chi2V,chi2P]=min(chi2);
|
---|
92 | % [cor2V,cor2P]=max(cor2);
|
---|
93 | %
|
---|
94 | % %compare both sides
|
---|
95 | %
|
---|
96 | %
|
---|
97 | % %by minimum of chi2
|
---|
98 | %
|
---|
99 | % if chi1V<chi2V
|
---|
100 | % c1=centerOFweight(abs(funk1))-(T+1)+chi1P;
|
---|
101 | % c2=centerOFweight(funk2b);
|
---|
102 | % delta=c2-c1;
|
---|
103 | % N1=zeros(size(funk1));
|
---|
104 | % if delta>0
|
---|
105 | % N1(delta:length(N1))=funk1(1:length(funk1)-delta+1);
|
---|
106 | % end
|
---|
107 | % if c1==c2
|
---|
108 | % N1=funk1;
|
---|
109 | % end
|
---|
110 | % if delta<0
|
---|
111 | % N1(1:length(N1)+delta+1)=funk1(-delta:length(funk1));
|
---|
112 | % end
|
---|
113 | % ChiVal1=chi1V;
|
---|
114 | % CorVal1=cor1V;
|
---|
115 | % else
|
---|
116 | %
|
---|
117 | % c1=centerOFweight(abs(funk1fliped))+chi2P-(T+1);
|
---|
118 | % c2=centerOFweight(funk2b);
|
---|
119 | % delta=c2-c1;
|
---|
120 | % N1=zeros(size(funk1));
|
---|
121 | % if delta>0
|
---|
122 | % N1(delta:length(N1))=funk1fliped(1:length(funk1)-delta+1);
|
---|
123 | % end
|
---|
124 | % if c1==c2
|
---|
125 | % N1=funk1;
|
---|
126 | % end
|
---|
127 | % if delta<0
|
---|
128 | % N1(1:length(N1)+delta+1)=funk1fliped(-delta:length(funk1));
|
---|
129 | % end
|
---|
130 | % ChiVal1=chi2V;
|
---|
131 | % CorVal1=cor2V;
|
---|
132 | % end
|
---|
133 | %
|
---|
134 | % % %by maximum of corr
|
---|
135 | % %
|
---|
136 | % % if cor1V>cor2V
|
---|
137 | % % c1=centerOFweight(abs(funk1))-201+cor1P;
|
---|
138 | % % c2=centerOFweight(funk2b);
|
---|
139 | % % delta=c2-c1;
|
---|
140 | % % N1c=zeros(size(funk1));
|
---|
141 | % % if delta>0
|
---|
142 | % % N1c(delta:length(N1c))=funk1(1:length(funk1)-delta+1);
|
---|
143 | % % end
|
---|
144 | % % if c1==c2
|
---|
145 | % % N1c=funk1;
|
---|
146 | % % end
|
---|
147 | % % if delta<0
|
---|
148 | % % N1c(1:length(N1c)+delta+1)=funk1(-delta:length(funk1));
|
---|
149 | % % end
|
---|
150 | % % ChiVal2=chi1V;
|
---|
151 | % % CorVal2=cor1V;
|
---|
152 | % % else
|
---|
153 | % %
|
---|
154 | % % c1=centerOFweight(abs(funk1fliped))+cor2P-201;
|
---|
155 | % % c2=centerOFweight(funk2b);
|
---|
156 | % % delta=c2-c1;
|
---|
157 | % % N1c=zeros(size(funk1));
|
---|
158 | % % if delta>0
|
---|
159 | % % N1c(delta:length(N1c))=funk1fliped(1:length(funk1)-delta+1);
|
---|
160 | % % end
|
---|
161 | % % if c1==c2
|
---|
162 | % % N1c=funk1;
|
---|
163 | % % end
|
---|
164 | % % if delta<0
|
---|
165 | % % N1c(1:length(N1c)+delta+1)=funk1fliped(-delta:length(funk1));
|
---|
166 | % % end
|
---|
167 | % % ChiVal2=chi2V;
|
---|
168 | % % CorVal2=cor2V;
|
---|
169 | % % end
|
---|
170 | %
|
---|
171 | % ExterProfile=N1;
|
---|
172 | % %ExterProfileCor=N1c; |
---|