1 | %% FOFB - data ans small scripts |
---|
2 | |
---|
3 | %% 48x48 |
---|
4 | IDBPM = getidbpmlist; |
---|
5 | |
---|
6 | [betax betaz] = modeltwiss('beta', 'BPMx', IDBPM); |
---|
7 | [mux muz] = modeltwiss('mu', 'BPMx', IDBPM); |
---|
8 | R0 = measbpmresp('BPMx',IDBPM, 'BPMz', IDBPM, 'FHCOR', 'FVCOR', 'Model','Struct'); |
---|
9 | Rinv0H= inv(R0(1,1).Data); |
---|
10 | Rinv0V= inv(R0(2,2).Data); |
---|
11 | %save 'fofbdata96x96' betax betaz mux muz Rinv |
---|
12 | |
---|
13 | %% 120x48 |
---|
14 | BPM = family2dev('BPMx'); |
---|
15 | |
---|
16 | [betax betaz] = modeltwiss('beta', 'BPMx'); |
---|
17 | [mux muz] = modeltwiss('mu', 'BPMx'); |
---|
18 | R1 = measbpmresp('BPMx',BPM, 'BPMz', BPM, 'FHCOR', 'FVCOR', 'Model','Struct'); |
---|
19 | Rinv1H= pinv(R1(1,1).Data); |
---|
20 | Rinv1V= pinv(R1(2,2).Data); |
---|
21 | %Rinv1= pinv(R1); |
---|
22 | |
---|
23 | save 'fofbdata240x96' betax betaz mux muz Rinv |
---|
24 | |
---|
25 | %% SVD |
---|
26 | |
---|
27 | h=figure; |
---|
28 | set(h,'Position',[223 311 1087 420]) |
---|
29 | [U, S, V] = svd(R0(1,1).Data, 0); %'econ'); |
---|
30 | S = diag(S); |
---|
31 | |
---|
32 | subplot(1,2,1) |
---|
33 | semilogy(S) |
---|
34 | xlabel('Singular value number') |
---|
35 | ylabel('Singular value amplitude') |
---|
36 | grid on |
---|
37 | xaxis([0 48]) |
---|
38 | title('H-plane') |
---|
39 | |
---|
40 | subplot(1,2,2) |
---|
41 | [U, S, V] = svd(R0(2,2).Data, 0); %'econ'); |
---|
42 | S = diag(S); |
---|
43 | semilogy(S) |
---|
44 | xlabel('Singular value number') |
---|
45 | ylabel('Singular value amplitude') |
---|
46 | grid on |
---|
47 | xaxis([0 48]) |
---|
48 | title('V-plane') |
---|
49 | |
---|
50 | suptitle('FOFB 96x96') |
---|
51 | |
---|
52 | %% 48 * 48 avec Rf |
---|
53 | |
---|
54 | Eta = modeldisp('BPMx',IDBPM); |
---|
55 | Smat = R0(1,1).Data; |
---|
56 | |
---|
57 | RFWeight = 10 * mean(std(Smat)) / std(Eta); |
---|
58 | Smat = [R0(1,1).Data RFWeight*Eta]; |
---|
59 | |
---|
60 | [U, S, V] = svd(Smat, 0); %'econ'); |
---|
61 | S = diag(S); |
---|
62 | |
---|
63 | subplot(1,2,1) |
---|
64 | semilogy(S) |
---|
65 | xlabel('Singular value number') |
---|
66 | ylabel('Singular value amplitude') |
---|
67 | grid on |
---|
68 | xaxis([0 48]); hold on; |
---|
69 | title('H-plane') |
---|
70 | |
---|
71 | SVDIndex = 1:48; |
---|
72 | RinvH = V(:,SVDIndex)*diag(S(SVDIndex).^(-1)) * U(:,SVDIndex)'; |
---|
73 | |
---|
74 | subplot(1,2,2) |
---|
75 | [U, S, V] = svd(R0(2,2).Data, 0); %'econ'); |
---|
76 | S = diag(S); |
---|
77 | semilogy(S) |
---|
78 | xlabel('Singular value number') |
---|
79 | ylabel('Singular value amplitude') |
---|
80 | grid on |
---|
81 | xaxis([0 48]) |
---|
82 | title('V-plane') |
---|
83 | |
---|
84 | suptitle('FOFB 96x96 + RF') |
---|
85 | |
---|
86 | |
---|
87 | %% SVD 120x48 |
---|
88 | h=figure; |
---|
89 | set(h,'Position',[223 311 1087 420]) |
---|
90 | [U, S, V] = svd(R1(1,1).Data, 0); %'econ'); |
---|
91 | S = diag(S); |
---|
92 | |
---|
93 | subplot(1,2,1) |
---|
94 | semilogy(S) |
---|
95 | xlabel('Singular value number') |
---|
96 | ylabel('Singular value amplitude') |
---|
97 | grid on |
---|
98 | xaxis([0 48]) |
---|
99 | title('H-plane') |
---|
100 | |
---|
101 | subplot(1,2,2) |
---|
102 | [U, S, V] = svd(R1(2,2).Data, 0); %'econ'); |
---|
103 | S = diag(S); |
---|
104 | semilogy(S) |
---|
105 | xlabel('Singular value number') |
---|
106 | ylabel('Singular value amplitude') |
---|
107 | grid on |
---|
108 | xaxis([0 48]) |
---|
109 | title('V-plane') |
---|
110 | |
---|
111 | suptitle('FOFB 96x96') |
---|
112 | |
---|
113 | % Correction with 48 singular values |
---|
114 | %% H-correction |
---|
115 | dI = -pinv(R0(1,1).Data)*(getx(IDBPM)-GoalOrbitVec); stepsp('FHCOR',dI) |
---|
116 | |
---|
117 | %% V-correction |
---|
118 | dI = -pinv(R0(2,2).Data)*(getz(IDBPM) - GoalZOrbitVec); stepsp('FVCOR',dI) |
---|
119 | |
---|
120 | %% |
---|
121 | % Correction with n singular values |
---|
122 | [U, S, V] = svd(R0(1,1).Data, 0); |
---|
123 | S = diag(S); |
---|
124 | %GoalOrbitVec = getgolden('BPMx', IDBPM)*0; |
---|
125 | GoalOrbitVec = getgolden('BPMx', IDBPM); |
---|
126 | |
---|
127 | %% H-correction |
---|
128 | SVDIndex = 1:48; |
---|
129 | |
---|
130 | b = U(:,SVDIndex)' * (GoalOrbitVec - getx(IDBPM)); |
---|
131 | b = diag(S(SVDIndex).^(-1)) * b; |
---|
132 | |
---|
133 | % Convert the b vector back to coefficents of response matrix |
---|
134 | Delcm = V(:,SVDIndex) * b; |
---|
135 | |
---|
136 | stepsp('FHCOR', Delcm) |
---|
137 | |
---|
138 | %% |
---|
139 | clf |
---|
140 | plot(getspos('BPMx', IDBPM), getx(IDBPM)); hold on |
---|
141 | plot(getspos('BPMx', IDBPM), GoalOrbitVec,'k'); |
---|
142 | |
---|
143 | %% |
---|
144 | clf |
---|
145 | plot(getspos('BPMx', IDBPM), getx(IDBPM)-GoalOrbitVec); hold on |
---|
146 | |
---|
147 | %% |
---|
148 | Rinv = pinv(R0(1,1).Data); |
---|
149 | Rinvfull=zeros(48,120); |
---|
150 | |
---|
151 | Rinvfull(:,dev2elem('BPMx',IDBPM)) = Rinv; |
---|
152 | |
---|
153 | %% |
---|
154 | %A/mm = µA/nm |
---|
155 | %(Rinvfull(4,:)*1714.412*1.77)*(getz - GoalZOrbitVec)/36000*10 |
---|