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 rmdisp</title> |
---|
6 | <meta name="keywords" content="rmdisp"> |
---|
7 | <meta name="description" content="RMDISP - Removes the portion of the orbit that correlates with the 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> > rmdisp.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>rmdisp |
---|
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>RMDISP - Removes the portion of the orbit that correlates with the 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, BPM, c, DispOrbit] = rmdisp(varargin) </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">RMDISP - Removes the portion of the orbit that correlates with the dispersion |
---|
31 | [DeltaRF, OrbitRM, c, DispOrbit] = rmdisp(BPMFamily, Orbit, BPMList, Dispersion) |
---|
32 | [DeltaRF, OrbitRM, c, DispOrbit] = rmdisp(BPMStruct, Dispersion) |
---|
33 | |
---|
34 | INPUTS |
---|
35 | 1. BPMFamily - Family name {Default: 'BPMx'} |
---|
36 | BPMStruct - BPM data structure. When using data structures, the orbit and |
---|
37 | BPMList are in the .Data and .DeviceList fields, respectively. |
---|
38 | 2. Orbit - Input orbit {Default or empty: get the present orbit} |
---|
39 | 3. BPMList - Device or element list of BPMs {Default or empty: all} |
---|
40 | 4 FLAGS - 'FitMean' or 'FitDispersionOnly' {Default} - Include or don't include the mean in the fit |
---|
41 | 'MeasDisp' - Measure the dispersion |
---|
42 | 'ModelDisp' - Calculate the model dispersion |
---|
43 | 'GoldenDisp' - Use the golden dispersion {Default} |
---|
44 | 'Display' - Plot orbit information {Default: no display unless there are no outputs} |
---|
45 | 'NoDisplay' - No plot |
---|
46 | 'SetRF' - Sets the RF frequency to the new value (prompts to check the value if 'Display' is on) |
---|
47 | 'NoSetRF' - Don't set the RF frequency |
---|
48 | (the usual Units and Mode flags: 'Online', 'Model', 'Manual', 'Hardware', 'Physics', etc.) |
---|
49 | 5. Dispersion - Optional input to specify the dispersion |
---|
50 | |
---|
51 | OUTPUTS |
---|
52 | 1. DeltaRF - Change in RF frequency required to remove the dispersion component of |
---|
53 | the orbit. The units are the in RF frequency units used by getrf/setrf. |
---|
54 | If DeltaRF = [], the units of dispersion or RF frequency were not unknown. In |
---|
55 | which case use c, output 3, to get the change in RF frequency. |
---|
56 | 2. OrbitRM - Estimated orbit with the dispersion orbit removed |
---|
57 | 3. c - fit coefficient, OrbitRM = Orbit - c * Dispersion |
---|
58 | c converts to RF frequency change but it depends on the units for the |
---|
59 | orbit and dispersion. For instance, if Orbit is in [mm] and Dispersion is |
---|
60 | in [mm/MHz], then c is in MHz. If Orbit is in [m] and Dispersion is in |
---|
61 | [meter/(dp/p)], then c is energy shift (DeltaRF = -c*mcf*RF [Hz]). |
---|
62 | To correct the orbit, change the RF frequency by negative of the frequency |
---|
63 | change determined by the c coefficient. |
---|
64 | 3. DispOrbit - Dispersion orbit used in the calculation |
---|
65 | |
---|
66 | NOTES |
---|
67 | 1. It is unclear to the author if it is better to fit the mean or not. If the |
---|
68 | BPM offsets are not known very well then fitting the mean may be better. That way |
---|
69 | the dispersion is not used as a way to change the orbit mean (beyond |
---|
70 | the mean change due to the shape and sampling of the dispersion function). |
---|
71 | 2. When fitting the mean the RF frequency change is only based only the dispersion |
---|
72 | fit coefficient. |
---|
73 | 3. It is best to use structure inputs, since the units are in the structure. Hence, |
---|
74 | the DeltaRF can be determined. |
---|
75 | |
---|
76 | See also <a href="setorbit.html" class="code" title="function [OCS, OCS0, V, S, ErrorFlag] = setorbit(varargin)">setorbit</a> <a href="findrf.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = findrf(varargin)">findrf</a> <a href="plotcm.html" class="code" title="function [DeltaRF, HCMEnergyChangeTotal, DeltaL] = plotcm(varargin)">plotcm</a> |
---|
77 | |
---|
78 | Written by Greg Portmann</pre></div> |
---|
79 | |
---|
80 | <!-- crossreference --> |
---|
81 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
82 | This function calls: |
---|
83 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
84 | <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="getdisp.html" class="code" title="function [Data, FileName] = getdisp(varargin)">getdisp</a> GETDISP - Returns the dispersion for a family (from file)</li><li><a href="getlist.html" class="code" title="function DeviceList = getlist(varargin)">getlist</a> GETLIST - Returns Device List 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="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a> GETRF - Gets the RF frequency</li><li><a href="getspos.html" class="code" title="function S = getspos(Family, DeviceList)">getspos</a> GETSPOS - Returns the longitudinal position in meters</li><li><a href="getunits.html" class="code" title="function [Units, UnitsString] = getunits(Family, Field)">getunits</a> GETUNITS - Return the present family units and units string</li><li><a href="isfamily.html" class="code" title="function [FamilyFlag, AO] = isfamily(Family, Field)">isfamily</a> ISFAMILY - True for family names</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="steprf.html" class="code" title="function steprf(varargin)">steprf</a> STEPRF - Increment change in the RF frequency</li></ul> |
---|
85 | This function is called by: |
---|
86 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
87 | </ul> |
---|
88 | <!-- crossreference --> |
---|
89 | |
---|
90 | |
---|
91 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
92 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [DeltaRF, BPM, c, DispOrbit] = rmdisp(varargin)</a> |
---|
93 | 0002 <span class="comment">%RMDISP - Removes the portion of the orbit that correlates with the dispersion</span> |
---|
94 | 0003 <span class="comment">% [DeltaRF, OrbitRM, c, DispOrbit] = rmdisp(BPMFamily, Orbit, BPMList, Dispersion)</span> |
---|
95 | 0004 <span class="comment">% [DeltaRF, OrbitRM, c, DispOrbit] = rmdisp(BPMStruct, Dispersion)</span> |
---|
96 | 0005 <span class="comment">%</span> |
---|
97 | 0006 <span class="comment">% INPUTS</span> |
---|
98 | 0007 <span class="comment">% 1. BPMFamily - Family name {Default: 'BPMx'}</span> |
---|
99 | 0008 <span class="comment">% BPMStruct - BPM data structure. When using data structures, the orbit and</span> |
---|
100 | 0009 <span class="comment">% BPMList are in the .Data and .DeviceList fields, respectively.</span> |
---|
101 | 0010 <span class="comment">% 2. Orbit - Input orbit {Default or empty: get the present orbit}</span> |
---|
102 | 0011 <span class="comment">% 3. BPMList - Device or element list of BPMs {Default or empty: all}</span> |
---|
103 | 0012 <span class="comment">% 4 FLAGS - 'FitMean' or 'FitDispersionOnly' {Default} - Include or don't include the mean in the fit</span> |
---|
104 | 0013 <span class="comment">% 'MeasDisp' - Measure the dispersion</span> |
---|
105 | 0014 <span class="comment">% 'ModelDisp' - Calculate the model dispersion</span> |
---|
106 | 0015 <span class="comment">% 'GoldenDisp' - Use the golden dispersion {Default}</span> |
---|
107 | 0016 <span class="comment">% 'Display' - Plot orbit information {Default: no display unless there are no outputs}</span> |
---|
108 | 0017 <span class="comment">% 'NoDisplay' - No plot</span> |
---|
109 | 0018 <span class="comment">% 'SetRF' - Sets the RF frequency to the new value (prompts to check the value if 'Display' is on)</span> |
---|
110 | 0019 <span class="comment">% 'NoSetRF' - Don't set the RF frequency</span> |
---|
111 | 0020 <span class="comment">% (the usual Units and Mode flags: 'Online', 'Model', 'Manual', 'Hardware', 'Physics', etc.)</span> |
---|
112 | 0021 <span class="comment">% 5. Dispersion - Optional input to specify the dispersion</span> |
---|
113 | 0022 <span class="comment">%</span> |
---|
114 | 0023 <span class="comment">% OUTPUTS</span> |
---|
115 | 0024 <span class="comment">% 1. DeltaRF - Change in RF frequency required to remove the dispersion component of</span> |
---|
116 | 0025 <span class="comment">% the orbit. The units are the in RF frequency units used by getrf/setrf.</span> |
---|
117 | 0026 <span class="comment">% If DeltaRF = [], the units of dispersion or RF frequency were not unknown. In</span> |
---|
118 | 0027 <span class="comment">% which case use c, output 3, to get the change in RF frequency.</span> |
---|
119 | 0028 <span class="comment">% 2. OrbitRM - Estimated orbit with the dispersion orbit removed</span> |
---|
120 | 0029 <span class="comment">% 3. c - fit coefficient, OrbitRM = Orbit - c * Dispersion</span> |
---|
121 | 0030 <span class="comment">% c converts to RF frequency change but it depends on the units for the</span> |
---|
122 | 0031 <span class="comment">% orbit and dispersion. For instance, if Orbit is in [mm] and Dispersion is</span> |
---|
123 | 0032 <span class="comment">% in [mm/MHz], then c is in MHz. If Orbit is in [m] and Dispersion is in</span> |
---|
124 | 0033 <span class="comment">% [meter/(dp/p)], then c is energy shift (DeltaRF = -c*mcf*RF [Hz]).</span> |
---|
125 | 0034 <span class="comment">% To correct the orbit, change the RF frequency by negative of the frequency</span> |
---|
126 | 0035 <span class="comment">% change determined by the c coefficient.</span> |
---|
127 | 0036 <span class="comment">% 3. DispOrbit - Dispersion orbit used in the calculation</span> |
---|
128 | 0037 <span class="comment">%</span> |
---|
129 | 0038 <span class="comment">% NOTES</span> |
---|
130 | 0039 <span class="comment">% 1. It is unclear to the author if it is better to fit the mean or not. If the</span> |
---|
131 | 0040 <span class="comment">% BPM offsets are not known very well then fitting the mean may be better. That way</span> |
---|
132 | 0041 <span class="comment">% the dispersion is not used as a way to change the orbit mean (beyond</span> |
---|
133 | 0042 <span class="comment">% the mean change due to the shape and sampling of the dispersion function).</span> |
---|
134 | 0043 <span class="comment">% 2. When fitting the mean the RF frequency change is only based only the dispersion</span> |
---|
135 | 0044 <span class="comment">% fit coefficient.</span> |
---|
136 | 0045 <span class="comment">% 3. It is best to use structure inputs, since the units are in the structure. Hence,</span> |
---|
137 | 0046 <span class="comment">% the DeltaRF can be determined.</span> |
---|
138 | 0047 <span class="comment">%</span> |
---|
139 | 0048 <span class="comment">% See also setorbit findrf plotcm</span> |
---|
140 | 0049 <span class="comment">%</span> |
---|
141 | 0050 <span class="comment">% Written by Greg Portmann</span> |
---|
142 | 0051 |
---|
143 | 0052 |
---|
144 | 0053 <span class="comment">% Option to fit the mean as well as the dispersion</span> |
---|
145 | 0054 <span class="comment">% FitMeanFlag = 0 -> only fit the dispersion</span> |
---|
146 | 0055 <span class="comment">% FitMeanFlag = 1 -> fit both the mean and dispersion but only remove the</span> |
---|
147 | 0056 <span class="comment">% dispersion coefficient from the orbit</span> |
---|
148 | 0057 <span class="comment">% It can be good fit the mean (at least if BPM offsets are not known),</span> |
---|
149 | 0058 <span class="comment">% so that the dispersion is not used as a way to change the orbit mean (beyond</span> |
---|
150 | 0059 <span class="comment">% the mean change due to the shape and sampling of the dispersion function).</span> |
---|
151 | 0060 <span class="comment">% When using difference orbits, I wouldn't fit the mean.</span> |
---|
152 | 0061 <span class="comment">% Note: fitting the mean and dispersion together is different from removing</span> |
---|
153 | 0062 <span class="comment">% the mean then fitting the dispersion.</span> |
---|
154 | 0063 FitMeanFlag = 0; |
---|
155 | 0064 |
---|
156 | 0065 |
---|
157 | 0066 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
158 | 0067 <span class="comment">% Input parsing and checking %</span> |
---|
159 | 0068 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
160 | 0069 |
---|
161 | 0070 <span class="keyword">if</span> nargout == 0 |
---|
162 | 0071 DisplayFlag = 1; |
---|
163 | 0072 <span class="keyword">else</span> |
---|
164 | 0073 DisplayFlag = 0; |
---|
165 | 0074 <span class="keyword">end</span> |
---|
166 | 0075 ChangeRFFlag = 0; |
---|
167 | 0076 DispFlag = <span class="string">'GoldenDisp'</span>; |
---|
168 | 0077 StructOutputFlag = 0; |
---|
169 | 0078 NumericOutputFlag = 0; |
---|
170 | 0079 DispOrbitStruct = []; |
---|
171 | 0080 InputFlags = {}; |
---|
172 | 0081 <span class="keyword">for</span> i = length(varargin):-1:1 |
---|
173 | 0082 <span class="keyword">if</span> isstruct(varargin{i}) |
---|
174 | 0083 <span class="comment">% Ignor structures</span> |
---|
175 | 0084 <span class="keyword">elseif</span> iscell(varargin{i}) |
---|
176 | 0085 <span class="comment">% Ignor cells</span> |
---|
177 | 0086 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'SetRF'</span>) |
---|
178 | 0087 ChangeRFFlag = 1; |
---|
179 | 0088 varargin(i) = []; |
---|
180 | 0089 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'NoSetRF'</span>) |
---|
181 | 0090 ChangeRFFlag = 0; |
---|
182 | 0091 varargin(i) = []; |
---|
183 | 0092 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'Display'</span>) |
---|
184 | 0093 DisplayFlag = 1; |
---|
185 | 0094 varargin(i) = []; |
---|
186 | 0095 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'NoDisplay'</span>) |
---|
187 | 0096 DisplayFlag = 0; |
---|
188 | 0097 varargin(i) = []; |
---|
189 | 0098 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'ModelDisp'</span>) |
---|
190 | 0099 DispFlag = varargin{i}; |
---|
191 | 0100 varargin(i) = []; |
---|
192 | 0101 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'MeasDisp'</span>) |
---|
193 | 0102 DispFlag = varargin{i}; |
---|
194 | 0103 varargin(i) = []; |
---|
195 | 0104 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'FitMean'</span>) |
---|
196 | 0105 FitMeanFlag = 1; |
---|
197 | 0106 varargin(i) = []; |
---|
198 | 0107 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'FitDispersionOnly'</span>) |
---|
199 | 0108 FitMeanFlag = 0; |
---|
200 | 0109 varargin(i) = []; |
---|
201 | 0110 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'GoldenDisp'</span>) |
---|
202 | 0111 DispFlag = varargin{i}; |
---|
203 | 0112 varargin(i) = []; |
---|
204 | 0113 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'simulator'</span>) | strcmpi(varargin{i},<span class="string">'model'</span>) |
---|
205 | 0114 ModeFlag = <span class="string">'SIMULATOR'</span>; |
---|
206 | 0115 InputFlags = [InputFlags varargin(i)]; |
---|
207 | 0116 varargin(i) = []; |
---|
208 | 0117 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'Online'</span>) |
---|
209 | 0118 ModeFlag = <span class="string">'Online'</span>; |
---|
210 | 0119 InputFlags = [InputFlags varargin(i)]; |
---|
211 | 0120 varargin(i) = []; |
---|
212 | 0121 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'Manual'</span>) |
---|
213 | 0122 ModeFlag = <span class="string">'Manual'</span>; |
---|
214 | 0123 InputFlags = [InputFlags varargin(i)]; |
---|
215 | 0124 varargin(i) = []; |
---|
216 | 0125 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'physics'</span>) |
---|
217 | 0126 UnitsFlag = <span class="string">'Physics'</span>; |
---|
218 | 0127 InputFlags = [InputFlags varargin(i)]; |
---|
219 | 0128 varargin(i) = []; |
---|
220 | 0129 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'hardware'</span>) |
---|
221 | 0130 UnitsFlag = <span class="string">'Hardware'</span>; |
---|
222 | 0131 InputFlags = [InputFlags varargin(i)]; |
---|
223 | 0132 varargin(i) = []; |
---|
224 | 0133 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'struct'</span>) |
---|
225 | 0134 StructOutputFlag = 1; |
---|
226 | 0135 varargin(i) = []; |
---|
227 | 0136 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'numeric'</span>) |
---|
228 | 0137 NumericOutputFlag = 1; |
---|
229 | 0138 StructOutputFlag = 0; |
---|
230 | 0139 varargin(i) = []; |
---|
231 | 0140 <span class="keyword">end</span> |
---|
232 | 0141 <span class="keyword">end</span> |
---|
233 | 0142 |
---|
234 | 0143 <span class="keyword">if</span> length(varargin) < 1 |
---|
235 | 0144 varargin = {<span class="string">'BPMx'</span>}; |
---|
236 | 0145 <span class="keyword">end</span> |
---|
237 | 0146 |
---|
238 | 0147 <span class="keyword">if</span> isstruct(varargin{1}) |
---|
239 | 0148 BPM = varargin{1}; |
---|
240 | 0149 <span class="keyword">if</span> ~<a href="isfamily.html" class="code" title="function [FamilyFlag, AO] = isfamily(Family, Field)">isfamily</a>(BPM) |
---|
241 | 0150 error(sprintf(<span class="string">'%s is not a family'</span>), BPM.FamilyName); |
---|
242 | 0151 <span class="keyword">end</span> |
---|
243 | 0152 <span class="keyword">if</span> length(varargin) >= 2 |
---|
244 | 0153 <span class="comment">% Use dispersion for the input line</span> |
---|
245 | 0154 DispOrbitStruct = varargin{2}; |
---|
246 | 0155 <span class="keyword">end</span> |
---|
247 | 0156 |
---|
248 | 0157 <span class="comment">% Only change StructOutputFlag if 'numeric' is not on the input line</span> |
---|
249 | 0158 <span class="keyword">if</span> ~NumericOutputFlag |
---|
250 | 0159 StructOutputFlag = 1; |
---|
251 | 0160 <span class="keyword">end</span> |
---|
252 | 0161 <span class="keyword">else</span> |
---|
253 | 0162 <span class="keyword">if</span> ischar(varargin{1}) |
---|
254 | 0163 BPM.FamilyName = varargin{1}; |
---|
255 | 0164 <span class="keyword">else</span> |
---|
256 | 0165 error(<span class="string">'First input must be a structure or FamilyName'</span>); |
---|
257 | 0166 <span class="keyword">end</span> |
---|
258 | 0167 <span class="keyword">if</span> ~<a href="isfamily.html" class="code" title="function [FamilyFlag, AO] = isfamily(Family, Field)">isfamily</a>(BPM.FamilyName) |
---|
259 | 0168 error(sprintf(<span class="string">'%s is not a BPM family'</span>, BPM.FamilyName)); |
---|
260 | 0169 <span class="keyword">end</span> |
---|
261 | 0170 <span class="keyword">if</span> length(varargin) >= 2 |
---|
262 | 0171 BPM.Data = varargin{2}; |
---|
263 | 0172 <span class="keyword">else</span> |
---|
264 | 0173 BPM = <a href="getam.html" class="code" title="function [AM, tout, DataTime, ErrorFlag] = getam(varargin)">getam</a>(BPM.FamilyName, <span class="string">'Struct'</span>, InputFlags{:}); |
---|
265 | 0174 <span class="keyword">end</span> |
---|
266 | 0175 <span class="keyword">if</span> length(varargin) >= 3 |
---|
267 | 0176 BPM.DeviceList = varargin{3}; |
---|
268 | 0177 <span class="keyword">elseif</span> ~isfield(BPM, <span class="string">'DeviceList'</span>) |
---|
269 | 0178 BPM.DeviceList = <a href="getlist.html" class="code" title="function DeviceList = getlist(varargin)">getlist</a>(BPM.FamilyName); |
---|
270 | 0179 <span class="keyword">end</span> |
---|
271 | 0180 <span class="keyword">if</span> length(varargin) >= 4 |
---|
272 | 0181 <span class="comment">% Use dispersion for the input line</span> |
---|
273 | 0182 DispOrbitStruct = varargin{4}; |
---|
274 | 0183 <span class="keyword">end</span> |
---|
275 | 0184 <span class="keyword">end</span> |
---|
276 | 0185 |
---|
277 | 0186 |
---|
278 | 0187 <span class="comment">%%%%%%%%%%%%%%%%%%</span> |
---|
279 | 0188 <span class="comment">% Get Dispersion %</span> |
---|
280 | 0189 <span class="comment">%%%%%%%%%%%%%%%%%%</span> |
---|
281 | 0190 DispUnitsString = <span class="string">''</span>; |
---|
282 | 0191 <span class="keyword">if</span> isempty(DispOrbitStruct) |
---|
283 | 0192 <span class="keyword">if</span> strcmpi(DispFlag,<span class="string">'ModelDisp'</span>) |
---|
284 | 0193 DispOrbitStruct = <a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a>(BPM, <span class="string">'Struct'</span>, <span class="string">'Model'</span>, InputFlags{:}); |
---|
285 | 0194 DispUnitsString = DispOrbitStruct.UnitsString; |
---|
286 | 0195 <span class="keyword">elseif</span> strcmpi(DispFlag,<span class="string">'MeasDisp'</span>) |
---|
287 | 0196 DispOrbitStruct = <a href="measdisp.html" class="code" title="function [Dx, Dy, FileName] = measdisp(varargin);">measdisp</a>(BPM, <span class="string">'Struct'</span>, InputFlags{:}); |
---|
288 | 0197 DispUnitsString = DispOrbitStruct.UnitsString; |
---|
289 | 0198 <span class="keyword">elseif</span> strcmpi(DispFlag,<span class="string">'GoldenDisp'</span>) |
---|
290 | 0199 DispOrbitStruct = <a href="getdisp.html" class="code" title="function [Data, FileName] = getdisp(varargin)">getdisp</a>(BPM.FamilyName, BPM.DeviceList, <span class="string">'Struct'</span>); |
---|
291 | 0200 DispUnitsString = DispOrbitStruct.UnitsString; |
---|
292 | 0201 <span class="keyword">end</span> |
---|
293 | 0202 <span class="keyword">end</span> |
---|
294 | 0203 <span class="keyword">if</span> isempty(DispOrbitStruct) |
---|
295 | 0204 error(<span class="string">'Did not find or generate a proper dispersion function'</span>); |
---|
296 | 0205 <span class="keyword">end</span> |
---|
297 | 0206 |
---|
298 | 0207 <span class="comment">% If dispersion is a structure, just use the .Data field</span> |
---|
299 | 0208 <span class="keyword">if</span> isstruct(DispOrbitStruct) |
---|
300 | 0209 DispOrbit = DispOrbitStruct.Data; |
---|
301 | 0210 <span class="keyword">else</span> |
---|
302 | 0211 DispOrbit = DispOrbitStruct; |
---|
303 | 0212 <span class="keyword">end</span> |
---|
304 | 0213 |
---|
305 | 0214 |
---|
306 | 0215 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
307 | 0216 <span class="comment">% Fit the orbit into the dispersion function %</span> |
---|
308 | 0217 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
309 | 0218 |
---|
310 | 0219 <span class="comment">% Dot product of dispersion and the orbit can be used</span> |
---|
311 | 0220 <span class="comment">% to find the RF frequency but to find the orbit which best</span> |
---|
312 | 0221 <span class="comment">% correlates to the dispersion use a least squares fit</span> |
---|
313 | 0222 <span class="comment">% c = BPM.Data' * DispOrbit;</span> |
---|
314 | 0223 |
---|
315 | 0224 BPMDataOld = BPM.Data; |
---|
316 | 0225 <span class="keyword">if</span> FitMeanFlag |
---|
317 | 0226 <span class="comment">% Fit the mean and the dispersion orbit</span> |
---|
318 | 0227 X = [ones(size(DispOrbit)) DispOrbit]; |
---|
319 | 0228 cfit = X \ BPM.Data; |
---|
320 | 0229 c = cfit(2); |
---|
321 | 0230 <span class="comment">%BPM.Data = BPM.Data - X * c;</span> |
---|
322 | 0231 <span class="keyword">else</span> |
---|
323 | 0232 <span class="comment">% Fit the dispersion orbit</span> |
---|
324 | 0233 cfit = DispOrbit \ BPM.Data; |
---|
325 | 0234 c = cfit; |
---|
326 | 0235 <span class="keyword">end</span> |
---|
327 | 0236 |
---|
328 | 0237 <span class="comment">%BPM.Data = BPM.Data - X * c;</span> |
---|
329 | 0238 BPM.Data = BPM.Data - DispOrbit * c; |
---|
330 | 0239 |
---|
331 | 0240 |
---|
332 | 0241 <span class="comment">% Comput the change in RF frequency</span> |
---|
333 | 0242 <span class="comment">% Units are a big pain the neck when it comes to determining the actual RF change</span> |
---|
334 | 0243 <span class="comment">% Note: this section will depend a little on how the UnitsString is setup</span> |
---|
335 | 0244 <span class="comment">% c units = BPM units / Dispersion units</span> |
---|
336 | 0245 RF0 = <a href="getrf.html" class="code" title="function [RFsp, RFam, DataTime, ErrorFlag] = getrf(varargin)">getrf</a>(<span class="string">'Struct'</span>, InputFlags{:}); |
---|
337 | 0246 DeltaRF = []; |
---|
338 | 0247 <span class="keyword">if</span> ~isfield(BPM,<span class="string">'UnitsString'</span>) |
---|
339 | 0248 [units, unitsstring] = <a href="getunits.html" class="code" title="function [Units, UnitsString] = getunits(Family, Field)">getunits</a>(BPM, <span class="string">'Monitor'</span>); |
---|
340 | 0249 BPM.UnitsString = unitsstring; <span class="comment">% Hopefully this is true</span> |
---|
341 | 0250 <span class="comment">%if DisplayFlag</span> |
---|
342 | 0251 <span class="comment">% fprintf(' BPM units are defined. Assuming units are %s.\n', unitsstring);</span> |
---|
343 | 0252 <span class="comment">%end</span> |
---|
344 | 0253 <span class="keyword">end</span> |
---|
345 | 0254 <span class="keyword">if</span> ~isempty(BPM.UnitsString) & ~isempty(DispUnitsString) |
---|
346 | 0255 <span class="comment">% May need to scale by the orbit units</span> |
---|
347 | 0256 <span class="keyword">if</span> strfind(lower(BPM.UnitsString), <span class="string">'mm'</span>) | strfind(lower(BPM.UnitsString), <span class="string">'millimeter'</span>) | strfind(lower(BPM.UnitsString), <span class="string">'millimeters'</span>) |
---|
348 | 0257 <span class="comment">% BPM is in mm</span> |
---|
349 | 0258 <span class="keyword">if</span> strfind(DispUnitsString, <span class="string">'mm'</span>) | strfind(DispUnitsString, <span class="string">'millimeter'</span>) | strfind(DispUnitsString, <span class="string">'millimeters'</span>) |
---|
350 | 0259 <span class="comment">% Dispersion is in mm, hence the units are ok</span> |
---|
351 | 0260 <span class="keyword">elseif</span> strfind(DispUnitsString, <span class="string">'m'</span>) | strfind(DispUnitsString, <span class="string">'meter'</span>) | strfind(DispUnitsString, <span class="string">'meters'</span>) |
---|
352 | 0261 <span class="comment">% Dispersion is in meters</span> |
---|
353 | 0262 c = c / 1000; |
---|
354 | 0263 <span class="keyword">else</span> |
---|
355 | 0264 DeltaRF = []; |
---|
356 | 0265 <span class="keyword">end</span> |
---|
357 | 0266 <span class="keyword">elseif</span> strfind(lower(BPM.UnitsString), <span class="string">'m'</span>) | strfind(lower(BPM.UnitsString), <span class="string">'meter'</span>) | strfind(lower(BPM.UnitsString), <span class="string">'meter'</span>) |
---|
358 | 0267 <span class="comment">% BPM is in meters</span> |
---|
359 | 0268 <span class="keyword">if</span> strfind(lower(DispUnitsString), <span class="string">'mm'</span>) | strfind(lower(DispUnitsString), <span class="string">'millimeter'</span>) | strfind(lower(DispUnitsString), <span class="string">'millimeters'</span>) |
---|
360 | 0269 <span class="comment">% Dispersion is in mm, hence the units are ok</span> |
---|
361 | 0270 c = c * 1000; |
---|
362 | 0271 <span class="keyword">elseif</span> strfind(lower(DispUnitsString), <span class="string">'m'</span>) | strfind(lower(DispUnitsString), <span class="string">'meter'</span>) | strfind(lower(DispUnitsString), <span class="string">'meters'</span>) |
---|
363 | 0272 <span class="comment">% Dispersion is in meters, hence the units are ok</span> |
---|
364 | 0273 <span class="keyword">else</span> |
---|
365 | 0274 DeltaRF = []; |
---|
366 | 0275 <span class="keyword">end</span> |
---|
367 | 0276 <span class="keyword">end</span> |
---|
368 | 0277 |
---|
369 | 0278 <span class="comment">% Change units to the same as getrf</span> |
---|
370 | 0279 <span class="keyword">if</span> strfind(lower(DispUnitsString), <span class="string">'mhz'</span>) |
---|
371 | 0280 <span class="keyword">if</span> strcmpi(RF0.UnitsString, <span class="string">'MHz'</span>) |
---|
372 | 0281 DeltaRF = c; <span class="comment">% c is MHz, DeltaRF is MHz</span> |
---|
373 | 0282 <span class="keyword">elseif</span> strcmpi(RF0.UnitsString, <span class="string">'Hz'</span>) |
---|
374 | 0283 DeltaRF = c * 1e6; <span class="comment">% c is MHz, DeltaRF is Hz</span> |
---|
375 | 0284 <span class="keyword">else</span> |
---|
376 | 0285 DeltaRF = []; |
---|
377 | 0286 <span class="keyword">end</span> |
---|
378 | 0287 <span class="keyword">elseif</span> strfind(lower(DispUnitsString), <span class="string">'hz'</span>) |
---|
379 | 0288 <span class="keyword">if</span> strcmpi(RF0.UnitsString, <span class="string">'MHz'</span>) |
---|
380 | 0289 DeltaRF = c / 1e6; <span class="comment">% c is Hz, DeltaRF is MHz</span> |
---|
381 | 0290 <span class="keyword">elseif</span> strcmpi(RF0.UnitsString, <span class="string">'Hz'</span>) |
---|
382 | 0291 DeltaRF = c; <span class="comment">% c is Hz, DeltaRF is Hz</span> |
---|
383 | 0292 <span class="keyword">else</span> |
---|
384 | 0293 DeltaRF = []; |
---|
385 | 0294 <span class="keyword">end</span> |
---|
386 | 0295 <span class="keyword">elseif</span> strfind(lower(DispUnitsString), <span class="string">'dp/p'</span>) |
---|
387 | 0296 DeltaRF = c * <a href="getmcf.html" class="code" title="function Alpha = getmcf(ModelString)">getmcf</a> * RF0.Data; <span class="comment">% Units same as RF0</span> |
---|
388 | 0297 <span class="keyword">else</span> |
---|
389 | 0298 DeltaRF = []; |
---|
390 | 0299 <span class="keyword">end</span> |
---|
391 | 0300 |
---|
392 | 0301 <span class="comment">% Return the change in RF required to remove the orbit error</span> |
---|
393 | 0302 DeltaRF = -DeltaRF; |
---|
394 | 0303 <span class="keyword">else</span> |
---|
395 | 0304 DeltaRF = -c; |
---|
396 | 0305 <span class="keyword">end</span> |
---|
397 | 0306 |
---|
398 | 0307 |
---|
399 | 0308 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
400 | 0309 <span class="comment">% Output and display %</span> |
---|
401 | 0310 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span> |
---|
402 | 0311 <span class="keyword">if</span> DisplayFlag |
---|
403 | 0312 spos = <a href="getspos.html" class="code" title="function S = getspos(Family, DeviceList)">getspos</a>(BPM); |
---|
404 | 0313 clf reset |
---|
405 | 0314 subplot(2,1,1); |
---|
406 | 0315 plot(spos, BPMDataOld, <span class="string">'r'</span>, spos, BPM.Data, <span class="string">'b'</span>); |
---|
407 | 0316 grid on |
---|
408 | 0317 xlabel(<span class="string">'Position [Meters]'</span>); |
---|
409 | 0318 <span class="keyword">if</span> isfield(BPM,<span class="string">'UnitsString'</span>) |
---|
410 | 0319 ylabel(sprintf(<span class="string">'%s [%s]'</span>, BPM.FamilyName, BPM.UnitsString)); |
---|
411 | 0320 <span class="keyword">else</span> |
---|
412 | 0321 ylabel(sprintf(<span class="string">'%s'</span>, BPM.FamilyName)); |
---|
413 | 0322 <span class="keyword">end</span> |
---|
414 | 0323 legend(<span class="string">'Starting Orbit'</span>,<span class="string">'Dispersion Removed'</span>) |
---|
415 | 0324 <span class="keyword">if</span> length(cfit) == 2 |
---|
416 | 0325 title(sprintf(<span class="string">'%g + %g * Dispersion'</span>,cfit(1), cfit(2))); |
---|
417 | 0326 <span class="keyword">else</span> |
---|
418 | 0327 title(sprintf(<span class="string">'%g * Dispersion'</span>,cfit(1))); |
---|
419 | 0328 <span class="keyword">end</span> |
---|
420 | 0329 |
---|
421 | 0330 subplot(2,1,2); |
---|
422 | 0331 <span class="comment">%plot(spos, X * c, 'b');</span> |
---|
423 | 0332 plot(spos, DispOrbit * c, <span class="string">'b'</span>); |
---|
424 | 0333 grid on |
---|
425 | 0334 xlabel(<span class="string">'Position [Meters]'</span>); |
---|
426 | 0335 <span class="keyword">if</span> isfield(BPM,<span class="string">'UnitsString'</span>) |
---|
427 | 0336 ylabel(sprintf(<span class="string">'Orbit Removed [%s]'</span>,BPM.UnitsString)); |
---|
428 | 0337 <span class="keyword">else</span> |
---|
429 | 0338 ylabel(sprintf(<span class="string">'Orbit Removed'</span>)); |
---|
430 | 0339 <span class="keyword">end</span> |
---|
431 | 0340 <span class="keyword">end</span> |
---|
432 | 0341 |
---|
433 | 0342 |
---|
434 | 0343 <span class="keyword">if</span> ~StructOutputFlag |
---|
435 | 0344 BPM = BPM.Data; |
---|
436 | 0345 <span class="keyword">end</span> |
---|
437 | 0346 |
---|
438 | 0347 |
---|
439 | 0348 <span class="comment">% Set the RF frequency</span> |
---|
440 | 0349 <span class="keyword">if</span> ChangeRFFlag |
---|
441 | 0350 <span class="keyword">if</span> ~isempty(DeltaRF) |
---|
442 | 0351 <span class="keyword">if</span> DisplayFlag |
---|
443 | 0352 answer = inputdlg({strvcat(strvcat(sprintf(<span class="string">'Recommend change in RF is %g %s'</span>, DeltaRF, RF0.UnitsString), <span class="string">' '</span>), <span class="string">'Change the RF frequency?'</span>)},<span class="string">'RMDISP'</span>,1,{sprintf(<span class="string">'%g'</span>,DeltaRF)}); |
---|
444 | 0353 <span class="keyword">if</span> isempty(answer) |
---|
445 | 0354 fprintf(<span class="string">' No change was made to the RF frequency\n'</span>); |
---|
446 | 0355 <span class="keyword">return</span> |
---|
447 | 0356 <span class="keyword">end</span> |
---|
448 | 0357 DeltaRF = str2num(answer{1}); |
---|
449 | 0358 <span class="keyword">end</span> |
---|
450 | 0359 <a href="steprf.html" class="code" title="function steprf(varargin)">steprf</a>(DeltaRF, InputFlags{:}); |
---|
451 | 0360 <span class="keyword">else</span> |
---|
452 | 0361 error(<span class="string">'RF frequency not changed because of a problem converting the units for dispersion and orbit to RF frequency'</span>); |
---|
453 | 0362 <span class="keyword">end</span> |
---|
454 | 0363 <span class="keyword">end</span> |
---|
455 | 0364</pre></div> |
---|
456 | <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> |
---|
457 | </body> |
---|
458 | </html> |
---|