1 | function [phix,phiy]=calcphase(nux,nuy,fadx,fady) |
---|
2 | %CALCPHASE - Calculate the betatron oscillation phase at the BPM using turn-by-turn data |
---|
3 | % [phix,phiy]=calcphase(nux,nuy,fadx,fady) |
---|
4 | % |
---|
5 | % This function calculates the betatron oscillation phase at the BPMs |
---|
6 | % using FAD data (turn by turn orbit measurement). |
---|
7 | % |
---|
8 | % return values: |
---|
9 | % phix, phiy horizontal and vertical betatron oscillation phase at every BPM |
---|
10 | % |
---|
11 | % input values: |
---|
12 | % nux, nuy horizontal and vertical tunes (as calculated by findfreq) |
---|
13 | % fadx horizontal FAD data (number of BPMs and number of turns is variable) |
---|
14 | % fady vertical FAD data |
---|
15 | |
---|
16 | % |
---|
17 | % Christoph Steier, July 1999 |
---|
18 | |
---|
19 | tmpx = sum(nux./abs(nux-mean(nux)))/sum(ones(size(nux))./abs(nux-mean(nux))); |
---|
20 | |
---|
21 | tmpy = sum(nuy./abs(nuy-mean(nuy)))/sum(ones(size(nuy))./abs(nuy-mean(nuy))); |
---|
22 | |
---|
23 | qx = 0.0; tmpsumx = 0.0; qy = 0.0; tmpsumy = 0.0; |
---|
24 | |
---|
25 | %for n = 1:length(tmpx) |
---|
26 | for n = 1:length(nux) |
---|
27 | if (abs(nux(n)-tmpx)<std(nux)) |
---|
28 | qx = qx + nux(n)/abs(nux(n)-tmpx); |
---|
29 | tmpsumx = tmpsumx + 1/abs(nux(n)-tmpx); |
---|
30 | end |
---|
31 | if (abs(nuy(n)-tmpy)<std(nuy)) |
---|
32 | qy = qy + nuy(n)/abs(nuy(n)-tmpy); |
---|
33 | tmpsumy = tmpsumy + 1/abs(nuy(n)-tmpy); |
---|
34 | end |
---|
35 | end |
---|
36 | |
---|
37 | qx = qx/tmpsumx; |
---|
38 | qy = qy/tmpsumy; |
---|
39 | |
---|
40 | fprintf('\n\nBPM #\tnu_x\t\tnu_y\n'); |
---|
41 | |
---|
42 | for n=1:length(nux) |
---|
43 | fprintf('%2d:\t%8.6g\t%8.6g\n',n,nux(n),nuy(n)); |
---|
44 | end |
---|
45 | |
---|
46 | outstring = sprintf('\nfractional horizontal tune (default=%g) ',qx); |
---|
47 | |
---|
48 | inx = input(outstring); |
---|
49 | |
---|
50 | if ~isempty(inx) |
---|
51 | qx = inx; |
---|
52 | end |
---|
53 | |
---|
54 | outstring = sprintf('\nfractional vertical tune (default=%g) ',qy); |
---|
55 | |
---|
56 | iny = input(outstring); |
---|
57 | |
---|
58 | if ~isempty(iny) |
---|
59 | qy = iny; |
---|
60 | end |
---|
61 | |
---|
62 | sfx=size(fadx); |
---|
63 | sfy=size(fady); |
---|
64 | |
---|
65 | %substract mean value |
---|
66 | mfadx = fadx-ones(sfx(1),1)*mean(fadx); |
---|
67 | mfady = fady-ones(sfy(1),1)*mean(fady); |
---|
68 | |
---|
69 | sfadx = sum(mfadx .* (ones(sfx(2),1)*sin(2*pi*qx*[0:(sfx(1)-1)]))'); |
---|
70 | cfadx = sum(mfadx .* (ones(sfx(2),1)*cos(2*pi*qx*[0:(sfx(1)-1)]))'); |
---|
71 | sfady = sum(mfady .* (ones(sfy(2),1)*sin(2*pi*qy*[0:(sfy(1)-1)]))'); |
---|
72 | cfady = sum(mfady .* (ones(sfy(2),1)*cos(2*pi*qy*[0:(sfy(1)-1)]))'); |
---|
73 | |
---|
74 | phix = atan2(cfadx,sfadx)/(2*pi); |
---|
75 | %phix = atan(sfadx./cfadx)/(2pi); |
---|
76 | for n = 1:length(phix) |
---|
77 | if (phix(n) < 0.0) |
---|
78 | phix(n) = phix(n)+1.0; |
---|
79 | end |
---|
80 | end |
---|
81 | |
---|
82 | %phiy = atan2(cfady,sfady)/(2*pi); |
---|
83 | phiy = -atan2(sfady,cfady)/(2*pi); |
---|
84 | for n = 1:length(phiy) |
---|
85 | if (phiy(n) < 0.0) |
---|
86 | phiy(n) = phiy(n)+1.0; |
---|
87 | end |
---|
88 | end |
---|
89 | |
---|
90 | for n = 2:length(phix) |
---|
91 | while (phix(n) < (phix(n-1)-0.2)) |
---|
92 | phix(n) = phix(n)+1.0; |
---|
93 | end |
---|
94 | end |
---|
95 | |
---|
96 | for n = 2:length(phiy) |
---|
97 | while (phiy(n) < (phiy(n-1)-0.3)) |
---|
98 | phiy(n) = phiy(n)+1.0; |
---|
99 | end |
---|
100 | end |
---|