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 findrf1</title> |
---|
6 | <meta name="keywords" content="findrf1"> |
---|
7 | <meta name="description" content="FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion"> |
---|
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">mml</a> > findrf1.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 mml <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>findrf1 |
---|
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>FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion</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 [DeltaRF, RFnew, frf] = findrf1(DeltaRF, BPMFamily, BPMList, FileName) </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">FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion |
---|
31 | [DeltaRF, RFnew, frf] = findrf1(DeltaRFvec, BPMFamily, BPMList, FileName) |
---|
32 | |
---|
33 | INPUTS |
---|
34 | 1. DeltaRFvec - Vector of RF changes {Default or empty: [-.2% -.1% 0% .1% .2%] energy change} |
---|
35 | 2. BPMFamily - Family name {Default or empty: 'BPMx'} |
---|
36 | 3. BPMList - Device or element list of BPMs {Default or empty: all} |
---|
37 | 4. FileName to save data (data in structure 'frf') {Default or empty: don't save data} |
---|
38 | |
---|
39 | OUTPUTS |
---|
40 | 1. DeltaRF - Change in RF |
---|
41 | 2. RFnew - Zero crossing of the fit |
---|
42 | 3. frf - RF structure containing all the measurement data |
---|
43 | |
---|
44 | NOTES |
---|
45 | 1. The RF frequency that minimized the dispersion maybe not be the |
---|
46 | optimal RF frequency. The ALS found that choosing an RF frequency which |
---|
47 | minimizes the energy shift due to the horizontal corrector magnets |
---|
48 | to be a more robust and repeatable solution. |
---|
49 | 2. This function measures the dispersion, hence changes the RF frequency! |
---|
50 | rmdisp will basically do the same thing as findrf1 without changing the |
---|
51 | RF frequency. However, findrf1 gives more control over the fit range for |
---|
52 | the RF change and allows for more noise reduction in the fit. That said, |
---|
53 | rmdisp is usually just fine to use. |
---|
54 | 3. Beware of the magnitude of DeltaRFvec for nonlinear accelerators. |
---|
55 | |
---|
56 | See also <a href="findrf.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = findrf(varargin)">findrf</a> <a href="rmdisp.html" class="code" title="function [DeltaRF, BPM, c, DispOrbit] = rmdisp(varargin)">rmdisp</a> <a href="plotcm.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = plotcm(varargin)">plotcm</a> |
---|
57 | |
---|
58 | Written by Greg Portmann</pre></div> |
---|
59 | |
---|
60 | <!-- crossreference --> |
---|
61 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
62 | This function calls: |
---|
63 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
64 | <li><a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a> FAMILY2DEV - Return the device list for a family</li><li><a href="getam.html" class="code" title="function [AM, tout, DataTime, ErrorFlag] = getam(varargin)">getam</a> GETAM - Gets monitor channels</li><li><a href="getfamilydata.html" class="code" title="function [Data, ErrorFlag] = getfamilydata(Family, Field1, Field2, DeviceList)">getfamilydata</a> GETFAMILYDATA - Gets data associated with the accelerator control</li><li><a href="getgolden.html" class="code" title="function Data = getgolden(varargin)">getgolden</a> GETGOLDEN - Returns the golden values for a family</li><li><a href="getmcf.html" class="code" title="function Alpha = getmcf(ModelString)">getmcf</a> GETMCF - Returns the momentum compaction factor (MCF) stored in the AD or the model</li><li><a href="getoffset.html" class="code" title="function Data = getoffset(varargin)">getoffset</a> GETOFFSET - Returns the offset values for a family</li><li><a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a> GETRF - Gets the RF frequency</li><li><a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a> MEASDISP - Measures the dispersion function</li><li><a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a> SETRF - Sets the RF frequency</li><li><a href="steprf.html" class="code" title="function steprf(varargin)">steprf</a> STEPRF - Increment change in the RF frequency</li></ul> |
---|
65 | This function is called by: |
---|
66 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
67 | </ul> |
---|
68 | <!-- crossreference --> |
---|
69 | |
---|
70 | |
---|
71 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
72 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [DeltaRF, RFnew, frf] = findrf1(DeltaRF, BPMFamily, BPMList, FileName)</a> |
---|
73 | 0002 <span class="comment">%FINDRF1 - Finds the RF frequency that minimizes the horizonal dispersion</span> |
---|
74 | 0003 <span class="comment">% [DeltaRF, RFnew, frf] = findrf1(DeltaRFvec, BPMFamily, BPMList, FileName)</span> |
---|
75 | 0004 <span class="comment">%</span> |
---|
76 | 0005 <span class="comment">% INPUTS</span> |
---|
77 | 0006 <span class="comment">% 1. DeltaRFvec - Vector of RF changes {Default or empty: [-.2% -.1% 0% .1% .2%] energy change}</span> |
---|
78 | 0007 <span class="comment">% 2. BPMFamily - Family name {Default or empty: 'BPMx'}</span> |
---|
79 | 0008 <span class="comment">% 3. BPMList - Device or element list of BPMs {Default or empty: all}</span> |
---|
80 | 0009 <span class="comment">% 4. FileName to save data (data in structure 'frf') {Default or empty: don't save data}</span> |
---|
81 | 0010 <span class="comment">%</span> |
---|
82 | 0011 <span class="comment">% OUTPUTS</span> |
---|
83 | 0012 <span class="comment">% 1. DeltaRF - Change in RF</span> |
---|
84 | 0013 <span class="comment">% 2. RFnew - Zero crossing of the fit</span> |
---|
85 | 0014 <span class="comment">% 3. frf - RF structure containing all the measurement data</span> |
---|
86 | 0015 <span class="comment">%</span> |
---|
87 | 0016 <span class="comment">% NOTES</span> |
---|
88 | 0017 <span class="comment">% 1. The RF frequency that minimized the dispersion maybe not be the</span> |
---|
89 | 0018 <span class="comment">% optimal RF frequency. The ALS found that choosing an RF frequency which</span> |
---|
90 | 0019 <span class="comment">% minimizes the energy shift due to the horizontal corrector magnets</span> |
---|
91 | 0020 <span class="comment">% to be a more robust and repeatable solution.</span> |
---|
92 | 0021 <span class="comment">% 2. This function measures the dispersion, hence changes the RF frequency!</span> |
---|
93 | 0022 <span class="comment">% rmdisp will basically do the same thing as findrf1 without changing the</span> |
---|
94 | 0023 <span class="comment">% RF frequency. However, findrf1 gives more control over the fit range for</span> |
---|
95 | 0024 <span class="comment">% the RF change and allows for more noise reduction in the fit. That said,</span> |
---|
96 | 0025 <span class="comment">% rmdisp is usually just fine to use.</span> |
---|
97 | 0026 <span class="comment">% 3. Beware of the magnitude of DeltaRFvec for nonlinear accelerators.</span> |
---|
98 | 0027 <span class="comment">%</span> |
---|
99 | 0028 <span class="comment">% See also findrf rmdisp plotcm</span> |
---|
100 | 0029 <span class="comment">%</span> |
---|
101 | 0030 <span class="comment">% Written by Greg Portmann</span> |
---|
102 | 0031 |
---|
103 | 0032 |
---|
104 | 0033 ChangeRFFlag = 1; |
---|
105 | 0034 DisplayFlag = 1; |
---|
106 | 0035 |
---|
107 | 0036 |
---|
108 | 0037 <span class="comment">% Starting Point</span> |
---|
109 | 0038 RF0 = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>(<span class="string">'Struct'</span>); |
---|
110 | 0039 |
---|
111 | 0040 |
---|
112 | 0041 <span class="keyword">if</span> nargin < 1 |
---|
113 | 0042 DeltaRF = []; |
---|
114 | 0043 <span class="keyword">end</span> |
---|
115 | 0044 <span class="keyword">if</span> isempty(DeltaRF) |
---|
116 | 0045 <span class="comment">%DeltaRF = getfamilydata('DeltaRFChro');</span> |
---|
117 | 0046 <span class="keyword">if</span> isempty(DeltaRF) |
---|
118 | 0047 DeltaRF = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a> * <a href="getmcf.html" class="code" title="function Alpha = getmcf(ModelString)">getmcf</a> * [-.002 -.001 0 .001 .002]; <span class="comment">% .2% energy change</span> |
---|
119 | 0048 <span class="comment">%DeltaRF = getrf * getmcf * [-.006 -.003 0 .003 .006]; % .6% energy change</span> |
---|
120 | 0049 <span class="comment">%DeltaRF = [-400 -200 0 200 400]; % Hz</span> |
---|
121 | 0050 <span class="comment">%if strcmpi(RF0.UnitsString, 'Hz')</span> |
---|
122 | 0051 <span class="comment">%elseif strcmpi(RF0.UnitsString, 'MHz')</span> |
---|
123 | 0052 <span class="comment">% DeltaRF = DeltaRF * 1e-6; % MHz</span> |
---|
124 | 0053 <span class="comment">%else</span> |
---|
125 | 0054 <span class="comment">% error('RF units unknown, hence default input frequency cannot be choosen.');</span> |
---|
126 | 0055 <span class="comment">%end</span> |
---|
127 | 0056 <span class="keyword">end</span> |
---|
128 | 0057 <span class="keyword">end</span> |
---|
129 | 0058 <span class="keyword">if</span> nargin < 2 |
---|
130 | 0059 BPMFamily = <span class="string">''</span>; |
---|
131 | 0060 <span class="keyword">end</span> |
---|
132 | 0061 <span class="keyword">if</span> isempty(BPMFamily) |
---|
133 | 0062 BPMFamily = <span class="string">'BPMx'</span>; |
---|
134 | 0063 <span class="keyword">end</span> |
---|
135 | 0064 <span class="keyword">if</span> nargin < 3 |
---|
136 | 0065 BPMList = <a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a>(BPMFamily); |
---|
137 | 0066 <span class="keyword">end</span> |
---|
138 | 0067 <span class="keyword">if</span> isempty(BPMList) |
---|
139 | 0068 BPMList = <a href="family2dev.html" class="code" title="function DeviceList = family2dev(Family, varargin);">family2dev</a>(BPMFamily); |
---|
140 | 0069 <span class="keyword">end</span> |
---|
141 | 0070 <span class="keyword">if</span> nargin < 4 |
---|
142 | 0071 FileName = []; |
---|
143 | 0072 <span class="keyword">end</span> |
---|
144 | 0073 |
---|
145 | 0074 |
---|
146 | 0075 BPMDelay = <a href="getfamilydata.html" class="code" title="function [Data, ErrorFlag] = getfamilydata(Family, Field1, Field2, DeviceList)">getfamilydata</a>(<span class="string">'BPMDelay'</span>); |
---|
147 | 0076 <span class="keyword">if</span> isempty(BPMDelay) |
---|
148 | 0077 BPMDelay = 0; |
---|
149 | 0078 <span class="keyword">end</span> |
---|
150 | 0079 |
---|
151 | 0080 |
---|
152 | 0081 Xoffset = <a href="getoffset.html" class="code" title="function Data = getoffset(varargin)">getoffset</a>(BPMFamily, BPMList); |
---|
153 | 0082 Xgolden = <a href="getgolden.html" class="code" title="function Data = getgolden(varargin)">getgolden</a>(BPMFamily, BPMList); |
---|
154 | 0083 |
---|
155 | 0084 |
---|
156 | 0085 <span class="comment">% Get Dispersion</span> |
---|
157 | 0086 Dx = <a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a>([], BPMFamily, BPMList); |
---|
158 | 0087 |
---|
159 | 0088 |
---|
160 | 0089 <span class="keyword">for</span> i = 1:length(DeltaRF) |
---|
161 | 0090 fprintf(<span class="string">' %d. Setting RF to %f [%s] \n'</span>, i, RF0.Data + DeltaRF(i), RF0.UnitsString); |
---|
162 | 0091 <a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a>(RF0.Data + DeltaRF(i)); |
---|
163 | 0092 sleep(BPMDelay); |
---|
164 | 0093 x(:,i) = <a href="getam.html" class="code" title="function [AM, tout, DataTime, ErrorFlag] = getam(varargin)">getam</a>(BPMFamily, BPMList) - Xoffset; |
---|
165 | 0094 rf(1,i) = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>; |
---|
166 | 0095 <span class="keyword">end</span> |
---|
167 | 0096 |
---|
168 | 0097 |
---|
169 | 0098 <span class="comment">% Set RF back to starting point</span> |
---|
170 | 0099 <a href="setrf.html" class="code" title="function setrf(RF, varargin)">setrf</a>(RF0); |
---|
171 | 0100 |
---|
172 | 0101 |
---|
173 | 0102 <span class="comment">% Find LS fit to the line</span> |
---|
174 | 0103 y = x' * Dx; <span class="comment">% Dot product of Dx and the X orbit</span> |
---|
175 | 0104 X = [ones(max(size(rf)),1) rf']; |
---|
176 | 0105 <span class="comment">%b = inv(X'*X)*X'*y;</span> |
---|
177 | 0106 b = X \ y; |
---|
178 | 0107 RFnew = -b(1) / b(2); |
---|
179 | 0108 |
---|
180 | 0109 |
---|
181 | 0110 rf1 = linspace(rf(1),rf(max(size(rf))),100); |
---|
182 | 0111 yfit = b(1) + b(2)*rf1; |
---|
183 | 0112 |
---|
184 | 0113 DeltaRF = RFnew - RF0.Data; |
---|
185 | 0114 |
---|
186 | 0115 |
---|
187 | 0116 <span class="comment">%figure</span> |
---|
188 | 0117 clf reset |
---|
189 | 0118 plot(rf1,yfit, <span class="string">'b'</span>, rf,y,<span class="string">'og'</span>, RFnew,0,<span class="string">'xr'</span>); |
---|
190 | 0119 grid on |
---|
191 | 0120 xlabel(<span class="string">'RF Frequency [MHz]'</span>); |
---|
192 | 0121 ylabel(<span class="string">'Dot product of Dx and Hor. Orbit'</span>); |
---|
193 | 0122 title(sprintf(<span class="string">'FIT: %g + %g * RF, \\DeltaRF = %g'</span>, b(1), b(2), DeltaRF)); |
---|
194 | 0123 |
---|
195 | 0124 |
---|
196 | 0125 |
---|
197 | 0126 <span class="comment">% Set the RF frequency</span> |
---|
198 | 0127 <span class="keyword">if</span> ChangeRFFlag |
---|
199 | 0128 <span class="comment">% fprintf('\n Starting RF = %f [%s]\n', RF0.Data, RF0.UnitsString);</span> |
---|
200 | 0129 <span class="comment">% fprintf(' Zero crossing of the RF = %f Delta RF = %g [%s]\n', RFnew, DeltaRF, RF0.UnitsString);</span> |
---|
201 | 0130 <span class="comment">% answer = input(' Do you want to set the RF frequence now (n/y)? ','s');</span> |
---|
202 | 0131 <span class="comment">% if strcmp(answer, 'y') == 1</span> |
---|
203 | 0132 <span class="comment">% setrf(RFnew);</span> |
---|
204 | 0133 <span class="comment">% fprintf(' New RF frequency = %f [%s]\n', getrf, RF0.UnitsString);</span> |
---|
205 | 0134 <span class="comment">% fprintf(' Measurement complete.\n');</span> |
---|
206 | 0135 <span class="comment">% else</span> |
---|
207 | 0136 <span class="comment">% fprintf(' Measurement complete. No change to the RF frequency.\n');</span> |
---|
208 | 0137 <span class="comment">% end</span> |
---|
209 | 0138 <span class="keyword">if</span> ~isempty(DeltaRF) |
---|
210 | 0139 <span class="keyword">if</span> DisplayFlag |
---|
211 | 0140 answer = inputdlg({strvcat(strvcat(strvcat(sprintf(<span class="string">'Recommend new RF Freqenecy is %g %s'</span>, RFnew, RF0.UnitsString), sprintf(<span class="string">'Delta RF is %g %s'</span>, DeltaRF, RF0.UnitsString)), <span class="string">' '</span>),<span class="string">'Change the RF frequency?'</span>)},<span class="string">'FINDFR1'</span>,1,{sprintf(<span class="string">'%g'</span>,DeltaRF)}); |
---|
212 | 0141 <span class="keyword">if</span> isempty(answer) |
---|
213 | 0142 fprintf(<span class="string">' No change was made to the RF frequency.\n'</span>); |
---|
214 | 0143 <span class="keyword">return</span> |
---|
215 | 0144 <span class="keyword">end</span> |
---|
216 | 0145 DeltaRF = str2num(answer{1}); |
---|
217 | 0146 <span class="keyword">end</span> |
---|
218 | 0147 <a href="steprf.html" class="code" title="function steprf(varargin)">steprf</a>(DeltaRF); |
---|
219 | 0148 <span class="keyword">if</span> DisplayFlag |
---|
220 | 0149 fprintf(<span class="string">' RF frequency change by %f %s.\n'</span>, DeltaRF, RFUnitsString); |
---|
221 | 0150 <span class="keyword">end</span> |
---|
222 | 0151 <span class="keyword">else</span> |
---|
223 | 0152 error(<span class="string">'RF frequency not changed because of a calculation problem.'</span>); |
---|
224 | 0153 <span class="keyword">end</span> |
---|
225 | 0154 <span class="keyword">end</span> |
---|
226 | 0155 |
---|
227 | 0156 |
---|
228 | 0157 <span class="keyword">if</span> ~isempty(FileName) <span class="comment">%save file</span> |
---|
229 | 0158 frf.TimeStamp = clock; |
---|
230 | 0159 frf.CreatedBy = <span class="string">'findrf'</span>; |
---|
231 | 0160 frf.FileName = FileName; |
---|
232 | 0161 frf.x = x; |
---|
233 | 0162 frf.rf = rf; |
---|
234 | 0163 frf.Dx = Dx; |
---|
235 | 0164 frf.RF0 = RF0; |
---|
236 | 0165 frf.RFnew = RFnew; |
---|
237 | 0166 frf.DeltaRF = DeltaRF; |
---|
238 | 0167 frf.BPMFamily = BPMFamily; |
---|
239 | 0168 frf.BPMList = BPMList; |
---|
240 | 0169 frf.Xgolden = Xgolden; |
---|
241 | 0170 frf.Xoffset = Xoffset; |
---|
242 | 0171 save(FileName, <span class="string">'frf'</span>); |
---|
243 | 0172 fprintf(<span class="string">' Data saved to %s.mat in directory %s.\n'</span>, FileName, pwd); |
---|
244 | 0173 <span class="keyword">end</span> |
---|
245 | 0174 |
---|
246 | 0175 |
---|
247 | 0176</pre></div> |
---|
248 | <hr><address>Generated on Mon 21-May-2007 15:29:18 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
249 | </body> |
---|
250 | </html> |
---|