1 | function BPM = plotmonbpm(varargin) |
---|
2 | %PLOTMONBPM - plot BPM noise data archived |
---|
3 | % |
---|
4 | % INPUTS |
---|
5 | % 1. FileName |
---|
6 | % |
---|
7 | % See Also monbpm |
---|
8 | |
---|
9 | % |
---|
10 | % Written by Laurent S. Nadolski |
---|
11 | |
---|
12 | SummaryFlag = 1; |
---|
13 | for i = length(varargin):-1:1 |
---|
14 | if strcmpi(varargin{i},'Summary') |
---|
15 | SummaryFlag = 1; |
---|
16 | varargin(i) = []; |
---|
17 | elseif strcmpi(varargin{i},'NoSummary') |
---|
18 | SummaryFlag = 0; |
---|
19 | varargin(i) = []; |
---|
20 | end |
---|
21 | end |
---|
22 | |
---|
23 | if length(varargin) <1 |
---|
24 | FileName = ''; |
---|
25 | else |
---|
26 | FileName = varargin{1}; |
---|
27 | end |
---|
28 | |
---|
29 | |
---|
30 | if isempty(FileName) |
---|
31 | DirectoryName = getfamilydata('Directory','BPMData'); |
---|
32 | if isempty(DirectoryName) |
---|
33 | DirectoryName = [getfamilydata('Directory','DataRoot'), filesep, 'BPM', filesep]; |
---|
34 | else |
---|
35 | % Make sure default directory exists |
---|
36 | DirStart = pwd; |
---|
37 | [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName); |
---|
38 | cd(DirStart); |
---|
39 | end |
---|
40 | [FileName, DirectoryName] = uigetfile('*.mat', 'Select a BPM Monitor File', [DirectoryName FileName]); |
---|
41 | FileName = fullfile(DirectoryName, FileName); |
---|
42 | elseif FileName == -1 |
---|
43 | FileName = appendtimestamp('BPMData'); |
---|
44 | DirectoryName = getfamilydata('Directory','BPMData'); |
---|
45 | if isempty(DirectoryName) |
---|
46 | DirectoryName = [getfamilydata('Directory','DataRoot'), filesep, 'BPM', filesep]; |
---|
47 | end |
---|
48 | FileName = [DirectoryName, FileName]; |
---|
49 | end |
---|
50 | |
---|
51 | if exist(FileName, 'file') ~=2 |
---|
52 | error('File does not exist'); |
---|
53 | end |
---|
54 | |
---|
55 | A = load(FileName); |
---|
56 | if ~isfield(A, 'BPMxData') || ~isfield(A, 'BPMxData') |
---|
57 | error('Wrong file, no BPM data') |
---|
58 | end |
---|
59 | |
---|
60 | BPM(1) = A.BPMxData; |
---|
61 | BPM(2) = A.BPMyData; |
---|
62 | |
---|
63 | % Compute the standard deviation |
---|
64 | |
---|
65 | % Low frequency drifting increases the STD. For many purposes, like LOCO, |
---|
66 | % this is not desireable. Using difference orbits mitigates the drift problem. |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | % plot part |
---|
71 | figure |
---|
72 | subplot(2,2,1); |
---|
73 | |
---|
74 | tout = BPM(1).tout; |
---|
75 | Mx = BPM(1).Data; |
---|
76 | % Orbit compared to first set |
---|
77 | for i = 1:size(Mx,2) |
---|
78 | Mx(:,i) = Mx(:,i) - BPM(1).Data(:,1); |
---|
79 | end |
---|
80 | |
---|
81 | plot(tout, Mx); |
---|
82 | grid on; |
---|
83 | %title(sprintf('BPM Data (%s)', datestr(BPM(1).TimeStamp))) |
---|
84 | xlabel('Time [Seconds]'); |
---|
85 | ylabel('Horizontal Relative Position [mm]'); |
---|
86 | |
---|
87 | |
---|
88 | tout = BPM(2).tout; |
---|
89 | % Orbit compared to first set |
---|
90 | My = BPM(2).Data; |
---|
91 | for i = 1:size(My,2) |
---|
92 | My(:,i) = My(:,i) - BPM(2).Data(:,1); |
---|
93 | end |
---|
94 | |
---|
95 | subplot(2,2,3); |
---|
96 | plot(tout, My); |
---|
97 | grid on; |
---|
98 | xlabel('Time [Seconds]'); |
---|
99 | ylabel(sprintf('Vertical Position [%s]', BPM(2).UnitsString)); |
---|
100 | |
---|
101 | subplot(2,2,2); |
---|
102 | List = BPM(1).DeviceList; |
---|
103 | Nsectors = max(List(:,1)); |
---|
104 | Ndevices = max(List(:,2)); |
---|
105 | Sector = List(:,1) + List(:,2)/Ndevices + 1/Ndevices/2; |
---|
106 | [Sector Idx] = sort(Sector); |
---|
107 | plot(Sector, BPM(1).Sigma(Idx)); |
---|
108 | grid on; |
---|
109 | xaxis([1 Nsectors+1]) |
---|
110 | set(gca,'XTick',1:Nsectors); |
---|
111 | xlabel('Sector Number'); |
---|
112 | ylabel(sprintf('Horizontal STD [%s]', BPM(1).UnitsString)); |
---|
113 | |
---|
114 | subplot(2,2,4); |
---|
115 | List = BPM(2).DeviceList; |
---|
116 | Nsectors = max(List(:,1)); |
---|
117 | Ndevices = max(List(:,2)); |
---|
118 | Sector = List(:,1) + List(:,2)/Ndevices + 1/Ndevices/2; |
---|
119 | [Sector Idx] = sort(Sector); |
---|
120 | plot(Sector, BPM(2).Sigma(Idx)); |
---|
121 | grid on; |
---|
122 | xaxis([1 Nsectors+1]) |
---|
123 | set(gca,'XTick',1:Nsectors); |
---|
124 | xlabel('Sector Number'); |
---|
125 | ylabel(sprintf('Vertical STD [%s]', BPM(2).UnitsString)); |
---|
126 | |
---|
127 | addlabel(.5,1,sprintf('BPM Data (%s)', datestr(BPM(1).TimeStamp)), 10); |
---|
128 | orient landscape |
---|
129 | |
---|
130 | %plot fit of the dispersion in the H-plane |
---|
131 | figure |
---|
132 | spos = getspos('BPMx',BPM(1).DeviceList); |
---|
133 | etax = modeldisp('BPMx',BPM(1).DeviceList); |
---|
134 | % y = disp*delta + y0 |
---|
135 | x = lsqr([etax ones(size(BPM(1).Sigma))], BPM(1).Sigma*1e-3); % m |
---|
136 | plot(spos, BPM(1).Sigma); hold on |
---|
137 | plot(spos,(etax*x(1)+x(2))*1e3,'r'); hold on |
---|
138 | legend('Data', 'fit') |
---|
139 | title(sprintf('Noise in H-plane: Delta = %.2f %% (x0=%.2e mm)', x(1)*100, x(2)*1e3)); |
---|
140 | xlabel('s-position (m)') |
---|
141 | ylabel('RMS x (mm)') |
---|
142 | |
---|
143 | if SummaryFlag |
---|
144 | % Low frequency drifting increases the STD. For many purposes, like LOCO, |
---|
145 | % this is not desireable. Using difference orbits mitigates the drift problem. |
---|
146 | Mx = BPM(1).Data; |
---|
147 | for i = 1:size(Mx,2)-1 |
---|
148 | Mx(:,i) = Mx(:,i+1) - Mx(:,i); |
---|
149 | end |
---|
150 | Mx(:,end) = []; |
---|
151 | |
---|
152 | My = BPM(2).Data; |
---|
153 | for i = 1:size(My,2)-1 |
---|
154 | My(:,i) = My(:,i+1) - My(:,i); |
---|
155 | end |
---|
156 | My(:,end) = []; |
---|
157 | |
---|
158 | BPM(1).Sigma = std(Mx,0,2) / sqrt(2); % sqrt(2) comes from substracting 2 random variables |
---|
159 | BPM(2).Sigma = std(My,0,2) / sqrt(2); |
---|
160 | |
---|
161 | |
---|
162 | [SortedData1 DataIdx1] = sort(BPM(1).Sigma,'descend'); |
---|
163 | SortedDeviceList1 = BPM(1).DeviceList(DataIdx1,:); |
---|
164 | [SortedData2 DataIdx2] = sort(BPM(2).Sigma,'descend'); |
---|
165 | SortedDeviceList2 = BPM(2).DeviceList(DataIdx2,:); |
---|
166 | |
---|
167 | % sort by drift |
---|
168 | maxBPM1 = max(abs(Mx),[],2); |
---|
169 | [SortedData3 DataIdx3] = sort(maxBPM1,'descend'); |
---|
170 | SortedDeviceList3 = BPM(1).DeviceList(DataIdx3,:); |
---|
171 | maxBPM2 = max(abs(My),[],2); |
---|
172 | [SortedData4 DataIdx4] = sort(maxBPM2,'descend'); |
---|
173 | SortedDeviceList4 = BPM(2).DeviceList(DataIdx4,:); |
---|
174 | |
---|
175 | fprintf('\n\n BPMxname DevList Max drift BPMzname DevList Max drift\n'); |
---|
176 | for k=1:size(BPM(1).DeviceList,1), |
---|
177 | fprintf('%s [%2d %2d] %6.2e [%s] %s [%2d %2d] %6.2e [%s] \n', ... |
---|
178 | 'BPMx', SortedDeviceList3(k,1), SortedDeviceList3(k,2), SortedData3(k), BPM(1).UnitsString, ... |
---|
179 | 'BPMz', SortedDeviceList4(k,1), SortedDeviceList4(k,2), SortedData4(k), BPM(2).UnitsString); |
---|
180 | end |
---|
181 | |
---|
182 | fprintf('\n\n BPMxname DevList STD value BPMzname DevList STD value\n'); |
---|
183 | |
---|
184 | for k=1:size(BPM(1).DeviceList,1), |
---|
185 | fprintf('%s [%2d %2d] %6.2e [%s] %s [%2d %2d] %6.2e [%s] \n', ... |
---|
186 | 'BPMx', SortedDeviceList1(k,1), SortedDeviceList1(k,2), SortedData1(k), BPM(1).UnitsString, ... |
---|
187 | 'BPMz', SortedDeviceList2(k,1), SortedDeviceList2(k,2), SortedData2(k), BPM(2).UnitsString); |
---|
188 | end |
---|
189 | [SortedData1 DataIdx1] = sort(BPM(1).Sigma,'descend'); |
---|
190 | SortedDeviceList1 = BPM(1).DeviceList(DataIdx1,:); |
---|
191 | [SortedData2 DataIdx2] = sort(BPM(2).Sigma,'descend'); |
---|
192 | SortedDeviceList2 = BPM(2).DeviceList(DataIdx2,:); |
---|
193 | |
---|
194 | % sort by drift |
---|
195 | maxBPM1 = max(abs(Mx),[],2); |
---|
196 | [SortedData3 DataIdx3] = sort(maxBPM1,'descend'); |
---|
197 | SortedDeviceList3 = BPM(1).DeviceList(DataIdx3,:); |
---|
198 | maxBPM2 = max(abs(My),[],2); |
---|
199 | [SortedData4 DataIdx4] = sort(maxBPM2,'descend'); |
---|
200 | SortedDeviceList4 = BPM(2).DeviceList(DataIdx4,:); |
---|
201 | |
---|
202 | fprintf('\n\n BPMxname DevList Max drift BPMzname DevList Max drift\n'); |
---|
203 | for k=1:size(BPM(1).DeviceList,1), |
---|
204 | fprintf('%s [%2d %2d] %6.2e [%s] %s [%2d %2d] %6.2e [%s] \n', ... |
---|
205 | 'BPMx', SortedDeviceList3(k,1), SortedDeviceList3(k,2), SortedData3(k), BPM(1).UnitsString, ... |
---|
206 | 'BPMz', SortedDeviceList4(k,1), SortedDeviceList4(k,2), SortedData4(k), BPM(2).UnitsString); |
---|
207 | end |
---|
208 | |
---|
209 | fprintf('\n\n BPMxname DevList STD value BPMzname DevList STD value\n'); |
---|
210 | for k=1:size(BPM(1).DeviceList,1), |
---|
211 | fprintf('%s [%2d %2d] %6.2e [%s] %s [%2d %2d] %6.2e [%s] \n', ... |
---|
212 | 'BPMx', SortedDeviceList1(k,1), SortedDeviceList1(k,2), SortedData1(k), BPM(1).UnitsString, ... |
---|
213 | 'BPMz', SortedDeviceList2(k,1), SortedDeviceList2(k,2), SortedData2(k), BPM(2).UnitsString); |
---|
214 | end |
---|
215 | |
---|
216 | end |
---|