source: MML/trunk/machine/SOLEIL/StorageRing/bpm/plotBPMturns.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 27.3 KB
Line 
1function varargout = plotBPMturns(varargin)
2% PLOTBPMTURNS M-file for plotBPMturns.fig
3%      PLOTBPMTURNS, by itself, creates a new PLOTBPMTURNS or raises the existing
4%      singleton*.
5%
6%      H = PLOTBPMTURNS returns the handle to a new PLOTBPMTURNS or the handle to
7%      the existing singleton*.
8%
9%      PLOTBPMTURNS('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in PLOTBPMTURNS.M with the given input arguments.
11%
12%      PLOTBPMTURNS('Property','Value',...) creates a new PLOTBPMTURNS or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before plotBPMturns_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to plotBPMturns_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: GUIDE, GUIDATA, GUIHANDLES
22
23% Edit the above text to modify the response to help plotBPMturns
24
25% Last Modified by GUIDE v2.5 08-Aug-2006 14:29:40
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 0;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @plotBPMturns_OpeningFcn, ...
32                   'gui_OutputFcn',  @plotBPMturns_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before plotBPMturns is made visible.
48function plotBPMturns_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to plotBPMturns (see VARARGIN)
54
55% fprintf('%6.2f\n',hObject);
56
57datacursormode on;
58
59% Choose default command line output for plotBPMturns
60handles.output = hObject;
61
62% Update handles structure
63guidata(hObject, handles);
64
65% Make figure resizable
66set(hObject,'Resize','off');
67
68% Set default values for the various fields.
69set(handles.turns_input,'String','[1:100]');
70set(handles.FFTturns_input,'String','[1:100]');
71set(handles.fftxaxis,'String','[0 0.5 0 0.2 0.1 0.4]');
72set(handles.fftyaxis,'String','[0 0.5 0 0.1 0.1 0.4]');
73set(handles.FFTturns_input,'String','[1:512]');
74set(handles.BPMdev_input,'String','[1 1]');
75set(handles.sumplot_max,'String','15e5');
76set(handles.sumplot_min,'String','0');
77set(handles.xyplot_max,'String','10');
78set(handles.xyplot_min,'String','-10');
79set(handles.tuneplot_max,'String','0.5');
80set(handles.tuneplot_min,'String','0');
81
82% User data structure to store data
83data.maxturns = 6663;
84data.maxtunesamples = 20;
85data.turnsstr = '[1:100]';
86data.turns = 1:100;
87data.BPMdev = [1 1];
88data.sumplotaxis = [0 15e5];
89data.xyplotaxis = [-10 10];
90data.tuneplotaxis = [0 0.5];
91data.fftturnsstr = '[1:512]';
92data.fftturns = 1:512;
93% The last 2 numbers define the window over which to detect the tune.
94data.fftxaxis = [0 0.5 0 0.2 0.1 0.4];
95data.fftyaxis = [0 0.5 0 0.1 0.1 0.4];
96data.fftaverage = 10;
97data.Pxx = [];   % store power spectrum for averaging
98data.Pyy = [];   % store power spectrum for averaging
99
100% for liftime calculations
101data.prev_sum = NaN;
102data.prev_time = NaN;
103data.lifetime = NaN;
104%data.lifetime_pv = 'CR01:GENERAL_ANALOG_01_MONITOR';
105data.lifetime_handle = getlifetime;
106data.currsumarray = NaN;
107data.currsumarray2 = NaN;
108
109data.tuneind = 1;
110
111data.sum = zeros(data.maxturns,1);
112data.x = zeros(data.maxturns,1);
113data.y = zeros(data.maxturns,1)+1;
114data.xtune = zeros(data.maxtunesamples,1); data.xtune(:) = NaN;
115data.ytune = zeros(data.maxtunesamples,1); data.ytune(:) = NaN;
116
117% Initialise plots
118axes(handles.sum_plot);
119plot(data.sum,'LineWidth',2);
120set(gca,'XLim',[data.turns(1) data.turns(end)]);
121set(gca,'YLim',data.sumplotaxis);
122
123axes(handles.xy_plot);
124plot(data.x,'LineWidth',2,'Color','k','Tag','Horizontal');
125hold on;
126plot(data.y,'LineWidth',2,'Color','b','LineStyle','--','Tag','Vertical');
127hold off;
128set(gca,'XLim',[data.turns(1) data.turns(end)]);
129set(gca,'YLim',data.xyplotaxis);
130
131% Tunes only plot 20 samples/updates worth of tunes
132axes(handles.tune_plot);
133plot(data.xtune,'LineWidth',2,'Color','k','Tag','Htune','Marker','.');
134hold on;
135plot(data.ytune,'LineWidth',2,'Color','b','Tag','Vtune','Marker','.','LineStyle','--');
136hold off;
137set(gca,'XLim',[1 data.maxtunesamples]);
138set(gca,'YLim',data.tuneplotaxis);
139
140% Plots for the FFT. With more points than would be needed.
141axes(handles.fft_x);
142plot(zeros(1,length(data.maxturns/2)),'LineWidth',1,'Color','k','Tag','fftx');
143hold on;
144% Plot the tune window over which to detect the tune
145plot([data.fftxaxis(5) data.fftxaxis(5)],data.fftxaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','fftx_lower');
146plot([data.fftxaxis(6) data.fftxaxis(6)],data.fftxaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','fftx_upper');
147hold off;
148axis(data.fftxaxis(1:4));
149
150axes(handles.fft_y);
151plot(zeros(1,length(data.maxturns/2)),'LineWidth',1,'Color','k','Tag','ffty');
152hold on;
153% Plot the tune window over which to detect the tune
154plot([data.fftyaxis(5) data.fftyaxis(5)],data.fftyaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','ffty_lower');
155plot([data.fftyaxis(6) data.fftyaxis(6)],data.fftyaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','ffty_upper');
156hold off;
157axis(data.fftyaxis(1:4));
158
159
160set(handles.main,'UserData',data);
161
162
163
164% --- Outputs from this function are returned to the command line.
165function varargout = plotBPMturns_OutputFcn(hObject, eventdata, handles)
166% varargout  cell array for returning output args (see VARARGOUT);
167% hObject    handle to figure
168% eventdata  reserved - to be defined in a future version of MATLAB
169% handles    structure with handles and user data (see GUIDATA)
170
171% Get default command line output from handles structure
172varargout{1} = handles.output;
173
174
175
176function turns_input_Callback(hObject, eventdata, handles)
177% hObject    handle to turns_input (see GCBO)
178% eventdata  reserved - to be defined in a future version of MATLAB
179% handles    structure with handles and user data (see GUIDATA)
180
181% Hints: get(hObject,'String') returns contents of turns_input as text
182%        str2double(get(hObject,'String')) returns contents of turns_input as a double
183
184data = get(handles.main,'UserData');
185
186turnsstr = get(hObject,'String');
187turns = eval(turnsstr);
188if isnumeric(turns) && turns(end) < data.maxturns
189    data.turnsstr = turnsstr;
190    data.turns = turns;
191else
192    msgbox(sprintf('Invalid turns input. Max turns is < %d',data.maxturns));
193    set(hObject,'String',data.turnsstr);
194end
195   
196set(handles.main,'UserData',data);
197
198
199% --- Executes during object creation, after setting all properties.
200function turns_input_CreateFcn(hObject, eventdata, handles)
201% hObject    handle to turns_input (see GCBO)
202% eventdata  reserved - to be defined in a future version of MATLAB
203% handles    empty - handles not created until after all CreateFcns called
204
205% Hint: edit controls usually have a white background on Windows.
206%       See ISPC and COMPUTER.
207if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
208    set(hObject,'BackgroundColor','white');
209end
210
211function BPMdev_input_Callback(hObject, eventdata, handles)
212% hObject    handle to BPMdev_input (see GCBO)
213% eventdata  reserved - to be defined in a future version of MATLAB
214% handles    structure with handles and user data (see GUIDATA)
215
216% Hints: get(hObject,'String') returns contents of BPMdev_input as text
217%        str2double(get(hObject,'String')) returns contents of BPMdev_input as a double
218
219data = get(handles.main,'UserData');
220
221BPMdev = eval(get(hObject,'String'));
222BPMdevlist = family2dev('BPMx',1);
223
224ind = findrowindex(BPMdevlist,BPMdev);
225if isempty(ind)
226    msgbox('Invalid BPM device index');
227    set(hObject,'String',sprintf('[%d %d]',data.BPMdev(1), data.BPMdev(2)));
228else
229    data.BPMdev = BPMdev;
230end
231
232set(handles.main,'UserData',data);
233
234
235% --- Executes during object creation, after setting all properties.
236function BPMdev_input_CreateFcn(hObject, eventdata, handles)
237% hObject    handle to BPMdev_input (see GCBO)
238% eventdata  reserved - to be defined in a future version of MATLAB
239% handles    empty - handles not created until after all CreateFcns called
240
241% Hint: edit controls usually have a white background on Windows.
242%       See ISPC and COMPUTER.
243if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
244    set(hObject,'BackgroundColor','white');
245end
246
247
248% --- Executes on button press in start_stop.
249function start_stop_Callback(hObject, eventdata, handles)
250% hObject    handle to start_stop (see GCBO)
251% eventdata  reserved - to be defined in a future version of MATLAB
252% handles    structure with handles and user data (see GUIDATA)
253
254% Hint: get(hObject,'Value') returns toggle state of start_stop
255
256OnFlag = get(handles.start_stop,'Value');
257
258if OnFlag
259    % Turn on updates
260    set(handles.start_stop, 'String', 'Running');   
261   
262    % Turn lattice menu back off
263    %set(handles.('LatticeMenu'),'enable','off');
264   
265    % Setup timer
266    UpdatePeriod = 0.5;
267    t = timer;
268    set(t,'StartDelay',0);
269    set(t,'Period', UpdatePeriod);
270    tagstr = sprintf('PlotBPMTimer_%6.2f',handles.main);
271    set(t,'Tag', tagstr);
272    timerstr = sprintf('plotBPMturns(''single_shot_Callback'', getfield(get(timerfind(''Tag'',''%s''),''Userdata''),''main''), [], get(timerfind(''Tag'',''%s''),''Userdata'')); drawnow;',...
273        tagstr,tagstr);
274    set(t,'TimerFcn', timerstr);
275    set(t,'UserData', handles);
276       
277    set(t,'BusyMode','drop');  %'queue'
278    set(t,'TasksToExecute', 10000000);
279    set(t,'ExecutionMode','FixedRate');
280    start(t);
281   
282else
283    % Turn off updating by deleting timer handle
284    tagstr = sprintf('PlotBPMTimer_%6.2f',handles.main);
285    h = timerfind('Tag',tagstr);
286    for i = 1:length(h)
287        stop(h(i));
288        delete(h(i));
289    end
290
291    % Change OnOff label string
292    set(handles.start_stop, 'String', 'Continuous');
293end
294
295
296
297
298function sumplot_max_Callback(hObject, eventdata, handles)
299% hObject    handle to sumplot_max (see GCBO)
300% eventdata  reserved - to be defined in a future version of MATLAB
301% handles    structure with handles and user data (see GUIDATA)
302
303% Hints: get(hObject,'String') returns contents of sumplot_max as text
304%        str2double(get(hObject,'String')) returns contents of sumplot_max as a double
305data = get(handles.main,'UserData');
306
307val = str2double(get(hObject,'String'));
308if ~isnan(val)
309    data.sumplotaxis(2) = val;
310else
311    msgbox('Invalid number');
312    set(hObject,'String',num2str(data.sumplotaxis(2)));
313end
314
315set(handles.main,'UserData',data);
316   
317
318% --- Executes during object creation, after setting all properties.
319function sumplot_max_CreateFcn(hObject, eventdata, handles)
320% hObject    handle to sumplot_max (see GCBO)
321% eventdata  reserved - to be defined in a future version of MATLAB
322% handles    empty - handles not created until after all CreateFcns called
323
324% Hint: edit controls usually have a white background on Windows.
325%       See ISPC and COMPUTER.
326if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
327    set(hObject,'BackgroundColor','white');
328end
329
330
331
332function sumplot_min_Callback(hObject, eventdata, handles)
333% hObject    handle to sumplot_min (see GCBO)
334% eventdata  reserved - to be defined in a future version of MATLAB
335% handles    structure with handles and user data (see GUIDATA)
336
337% Hints: get(hObject,'String') returns contents of sumplot_min as text
338%        str2double(get(hObject,'String')) returns contents of sumplot_min as a double
339
340data = get(handles.main,'UserData');
341
342val = str2double(get(hObject,'String'));
343if ~isnan(val)
344    data.sumplotaxis(1) = val;
345else
346    msgbox('Invalid number');
347    set(hObject,'String',num2str(data.sumplotaxis(1)));
348end
349
350set(handles.main,'UserData',data);
351
352% --- Executes during object creation, after setting all properties.
353function sumplot_min_CreateFcn(hObject, eventdata, handles)
354% hObject    handle to sumplot_min (see GCBO)
355% eventdata  reserved - to be defined in a future version of MATLAB
356% handles    empty - handles not created until after all CreateFcns called
357
358% Hint: edit controls usually have a white background on Windows.
359%       See ISPC and COMPUTER.
360if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
361    set(hObject,'BackgroundColor','white');
362end
363
364
365
366function xyplot_max_Callback(hObject, eventdata, handles)
367% hObject    handle to xyplot_max (see GCBO)
368% eventdata  reserved - to be defined in a future version of MATLAB
369% handles    structure with handles and user data (see GUIDATA)
370
371% Hints: get(hObject,'String') returns contents of xyplot_max as text
372%        str2double(get(hObject,'String')) returns contents of xyplot_max as a double
373
374data = get(handles.main,'UserData');
375
376val = str2double(get(hObject,'String'));
377if ~isnan(val)
378    data.xyplotaxis(2) = val;
379else
380    msgbox('Invalid number');
381    set(hObject,'String',num2str(data.xyplotaxis(2)));
382end
383
384set(handles.main,'UserData',data);
385
386
387% --- Executes during object creation, after setting all properties.
388function xyplot_max_CreateFcn(hObject, eventdata, handles)
389% hObject    handle to xyplot_max (see GCBO)
390% eventdata  reserved - to be defined in a future version of MATLAB
391% handles    empty - handles not created until after all CreateFcns called
392
393% Hint: edit controls usually have a white background on Windows.
394%       See ISPC and COMPUTER.
395if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
396    set(hObject,'BackgroundColor','white');
397end
398
399
400
401function xyplot_min_Callback(hObject, eventdata, handles)
402% hObject    handle to xyplot_min (see GCBO)
403% eventdata  reserved - to be defined in a future version of MATLAB
404% handles    structure with handles and user data (see GUIDATA)
405
406% Hints: get(hObject,'String') returns contents of xyplot_min as text
407%        str2double(get(hObject,'String')) returns contents of xyplot_min as a double
408
409data = get(handles.main,'UserData');
410
411val = str2double(get(hObject,'String'));
412if ~isnan(val)
413    data.xyplotaxis(1) = val;
414else
415    msgbox('Invalid number');
416    set(hObject,'String',num2str(data.xyplotaxis(1)));
417end
418
419set(handles.main,'UserData',data);
420
421% --- Executes during object creation, after setting all properties.
422function xyplot_min_CreateFcn(hObject, eventdata, handles)
423% hObject    handle to xyplot_min (see GCBO)
424% eventdata  reserved - to be defined in a future version of MATLAB
425% handles    empty - handles not created until after all CreateFcns called
426
427% Hint: edit controls usually have a white background on Windows.
428%       See ISPC and COMPUTER.
429if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
430    set(hObject,'BackgroundColor','white');
431end
432
433
434
435function tuneplot_max_Callback(hObject, eventdata, handles)
436% hObject    handle to tuneplot_max (see GCBO)
437% eventdata  reserved - to be defined in a future version of MATLAB
438% handles    structure with handles and user data (see GUIDATA)
439
440% Hints: get(hObject,'String') returns contents of tuneplot_max as text
441%        str2double(get(hObject,'String')) returns contents of tuneplot_max as a double
442
443data = get(handles.main,'UserData');
444
445val = str2double(get(hObject,'String'));
446if ~isnan(val)
447    data.tuneplotaxis(2) = val;
448else
449    msgbox('Invalid number');
450    set(hObject,'String',num2str(data.tuneplotaxis(2)));
451end
452
453set(handles.main,'UserData',data);
454
455% --- Executes during object creation, after setting all properties.
456function tuneplot_max_CreateFcn(hObject, eventdata, handles)
457% hObject    handle to tuneplot_max (see GCBO)
458% eventdata  reserved - to be defined in a future version of MATLAB
459% handles    empty - handles not created until after all CreateFcns called
460
461% Hint: edit controls usually have a white background on Windows.
462%       See ISPC and COMPUTER.
463if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
464    set(hObject,'BackgroundColor','white');
465end
466
467
468
469function tuneplot_min_Callback(hObject, eventdata, handles)
470% hObject    handle to tuneplot_min (see GCBO)
471% eventdata  reserved - to be defined in a future version of MATLAB
472% handles    structure with handles and user data (see GUIDATA)
473
474% Hints: get(hObject,'String') returns contents of tuneplot_min as text
475%        str2double(get(hObject,'String')) returns contents of tuneplot_min as a double
476
477data = get(handles.main,'UserData');
478
479val = str2double(get(hObject,'String'));
480if ~isnan(val)
481    data.tuneplotaxis(1) = val;
482else
483    msgbox('Invalid number');
484    set(hObject,'String',num2str(data.tuneplotaxis(1)));
485end
486
487set(handles.main,'UserData',data);
488
489% --- Executes during object creation, after setting all properties.
490function tuneplot_min_CreateFcn(hObject, eventdata, handles)
491% hObject    handle to tuneplot_min (see GCBO)
492% eventdata  reserved - to be defined in a future version of MATLAB
493% handles    empty - handles not created until after all CreateFcns called
494
495% Hint: edit controls usually have a white background on Windows.
496%       See ISPC and COMPUTER.
497if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
498    set(hObject,'BackgroundColor','white');
499end
500
501
502% --- Executes on button press in single_shot.
503function single_shot_Callback(hObject, eventdata, handles)
504% hObject    handle to single_shot (see GCBO)
505% eventdata  reserved - to be defined in a future version of MATLAB
506% handles    structure with handles and user data (see GUIDATA)
507
508data = get(handles.main,'UserData');
509
510setlibera('TT_READY_STATUS',0,data.BPMdev);
511setlibera('TT_ARM_CMD',1,data.BPMdev);
512
513ii = 0;
514while ~getlibera('TT_READY_STATUS',data.BPMdev);
515    pause(0.3);
516    ii = ii + 1;
517    if ii > 20
518        msgbox('Problem with this bpm. Maybe not triggering properly. Try another BPM');
519        return
520    end
521end
522
523[data.sum temp datatime] = getlibera('TT_WF_S_MONITOR',data.BPMdev);
524data.x = getlibera('TT_WF_HPOS_MONITOR',data.BPMdev)/1e6; % convert into mm
525data.y = getlibera('TT_WF_VPOS_MONITOR',data.BPMdev)/1e6; % convert into mm
526
527% FFT
528npoints = 2^(floor(log2(length(data.fftturns))));
529
530% FFT horizontal. Data stack is cleared everytime number of fft_turns is
531% changed
532XX = fft(data.x(data.fftturns) - mean(data.x(data.fftturns)));
533f = [0:npoints/2]/npoints;
534if size(data.Pxx,2) >= data.fftaverage
535    % First In First Out, push data on stack
536    data.Pxx(:,1:end-1) = data.Pxx(:,2:end);
537    data.Pxx(:,end) = XX.*conj(XX)/npoints;
538else
539    data.Pxx(:,end+1) = XX.*conj(XX)/npoints;
540end
541Pxx_mean = mean(data.Pxx(1:npoints/2+1,:),2);
542
543linehandle = get(handles.fft_x,'Children');
544for i=1:length(linehandle)
545    switch get(linehandle(i),'Tag')
546        case 'fftx'
547            set(linehandle(i),'XData',f,'YData',Pxx_mean);
548            set(handles.fft_x,'YLim',data.fftxaxis(3:4),'XLim',data.fftxaxis(1:2));
549        case 'fftx_lower'
550            set(linehandle(i),'XData',[data.fftxaxis(5) data.fftxaxis(5)],'YData',data.fftxaxis(3:4));
551        case 'fftx_upper'
552            set(linehandle(i),'XData',[data.fftxaxis(6) data.fftxaxis(6)],'YData',data.fftxaxis(3:4));
553    end
554end
555
556% Detect peak within window
557indices = find(f > data.fftxaxis(5) & f < data.fftxaxis(6));
558[temp xtuneind] = max(Pxx_mean(indices));
559xtuneind = xtuneind + 3;
560if data.tuneind == data.maxtunesamples + 1
561    data.xtune(1:data.maxtunesamples-1) = data.xtune(2:data.maxtunesamples);
562    data.xtune(data.maxtunesamples) = f(xtuneind+indices(1));
563else
564    data.xtune(data.tuneind) = f(xtuneind+indices(1));
565end
566
567
568% FFT vertical. Data stack is cleared everytime number of fft_turns is
569% changed
570YY = fft(data.y(data.fftturns) - mean(data.y(data.fftturns)));
571f = [0:npoints/2]/npoints;
572if size(data.Pyy,2) >= data.fftaverage
573    % First In First Out, push data on stack
574    data.Pyy(:,1:end-1) = data.Pyy(:,2:end);
575    data.Pyy(:,end) = YY.*conj(YY)/npoints;
576else
577    data.Pyy(:,end+1) = YY.*conj(YY)/npoints;
578end
579Pyy_mean = mean(data.Pyy(1:npoints/2+1,:),2);
580
581
582linehandle = get(handles.fft_y,'Children');
583for i=1:length(linehandle)
584    switch get(linehandle(i),'Tag')
585        case 'ffty'
586            set(linehandle(i),'XData',f,'YData',Pyy_mean);
587            set(handles.fft_y,'YLim',data.fftyaxis(3:4),'XLim',data.fftyaxis(1:2));
588        case 'ffty_lower'
589            set(linehandle(i),'XData',[data.fftyaxis(5) data.fftyaxis(5)],'YData',data.fftyaxis(3:4));
590        case 'ffty_upper'
591            set(linehandle(i),'XData',[data.fftyaxis(6) data.fftyaxis(6)],'YData',data.fftyaxis(3:4));
592    end
593end
594
595% Detect peak within window
596indices = find(f > data.fftyaxis(5) & f < data.fftyaxis(6));
597[temp ytuneind] = max(Pyy_mean(indices));
598ytuneind = ytuneind + 3;
599if data.tuneind == data.maxtunesamples + 1
600    data.ytune(1:data.maxtunesamples-1) = data.ytune(2:data.maxtunesamples);
601    data.ytune(data.maxtunesamples) = f(ytuneind+indices(1));
602else
603    data.ytune(data.tuneind) = f(ytuneind+indices(1));
604    data.tuneind = data.tuneind + 1;
605end
606
607
608   
609
610linehandle = get(handles.sum_plot,'Children');
611set(linehandle,'YData',data.sum);
612set(handles.sum_plot,'XLim',[data.turns(1) data.turns(end)]);
613set(handles.sum_plot,'YLim',data.sumplotaxis);
614
615linehandle = get(handles.xy_plot,'Children');
616for i=1:length(linehandle)
617    switch get(linehandle(i),'Tag')
618        case 'Horizontal'
619            % only set the axis limits once since it should cycle through
620            % both horizontal and vertical
621            set(linehandle(i),'YData',data.x);
622            set(handles.xy_plot,'XLim',[data.turns(1) data.turns(end)]);
623            set(handles.xy_plot,'YLim',data.xyplotaxis);
624        case 'Vertical'
625            set(linehandle(i),'YData',data.y);
626    end
627end
628
629linehandle = get(handles.tune_plot,'Children');
630for i=1:length(linehandle)
631    switch get(linehandle(i),'Tag')
632        case 'Htune'
633            set(linehandle(i),'YData',data.xtune);
634            set(handles.tune_plot,'XLim',[1 data.maxtunesamples]);
635            set(handles.tune_plot,'YLim',data.tuneplotaxis);
636        case 'Vtune'
637            set(linehandle(i),'YData',data.ytune);
638    end
639end
640
641% Calculate Lifetime
642sumindex = 1000:1002;
643%sumindex2 = 5000:6000;
644currsum = mean(data.sum(sumindex));
645%currsum2 = mean(data.sum(sumindex2));
646data.currsumarray = [data.currsumarray currsum];
647%data.currsumarray2 = [data.currsumarray2 currsum2];
648%figure(10);
649%plot(data.currsumarray,'x-');
650%hold on
651%plot(data.currsumarray2,'ro-');
652%axis([1 length(data.currsumarray) 1.525e6 1.535e6]);
653%hold off;
654
655if isnan(data.prev_sum)
656    data.lifetime = NaN;
657else
658    data.lifetime = - currsum/(currsum-data.prev_sum)*(datatime - data.prev_time)*1e5/60;
659    %data.lifetime = - currsum/(currsum-data.prev_sum)*1/60;
660end
661data.prev_sum = currsum;
662data.prev_time = datatime;
663if data.lifetime_handle ~= 0
664    mcaput(data.lifetime_handle,data.lifetime);
665end
666
667set(handles.lifetime_text,'String',sprintf('%+06.3f',data.lifetime));
668
669
670set(handles.main,'UserData',data);
671
672
673
674function FFTturns_input_Callback(hObject, eventdata, handles)
675% hObject    handle to FFTturns_input (see GCBO)
676% eventdata  reserved - to be defined in a future version of MATLAB
677% handles    structure with handles and user data (see GUIDATA)
678
679% Hints: get(hObject,'String') returns contents of FFTturns_input as text
680%        str2double(get(hObject,'String')) returns contents of FFTturns_input as a double
681data = get(handles.main,'UserData');
682
683fftturnsstr = get(hObject,'String');
684fftturns = eval(fftturnsstr);
685if isnumeric(fftturns) && fftturns(end) < data.maxturns
686    data.fftturnsstr = fftturnsstr;
687    data.fftturns = fftturns;
688    % If changing fft turns then must reset FFT data structure due to
689    % averaging.
690    data.Pxx = [];
691    data.Pyy = [];
692else
693    msgbox(sprintf('Invalid FFT turns input. Max turns is < %d',data.maxturns));
694    set(hObject,'String',data.fftturnsstr);
695end
696
697set(handles.main,'UserData',data);
698
699
700% --- Executes during object creation, after setting all properties.
701function FFTturns_input_CreateFcn(hObject, eventdata, handles)
702% hObject    handle to FFTturns_input (see GCBO)
703% eventdata  reserved - to be defined in a future version of MATLAB
704% handles    empty - handles not created until after all CreateFcns called
705
706% Hint: edit controls usually have a white background on Windows.
707%       See ISPC and COMPUTER.
708if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
709    set(hObject,'BackgroundColor','white');
710end
711
712
713
714
715% --- Executes when main is resized.
716function main_ResizeFcn(hObject, eventdata, handles)
717% hObject    handle to main (see GCBO)
718% eventdata  reserved - to be defined in a future version of MATLAB
719% handles    structure with handles and user data (see GUIDATA)
720
721
722
723function fftyaxis_Callback(hObject, eventdata, handles)
724% hObject    handle to fftyaxis (see GCBO)
725% eventdata  reserved - to be defined in a future version of MATLAB
726% handles    structure with handles and user data (see GUIDATA)
727
728% Hints: get(hObject,'String') returns contents of fftyaxis as text
729%        str2double(get(hObject,'String')) returns contents of fftyaxis as a double
730data = get(handles.main,'UserData');
731
732fftystr = get(hObject,'String');
733data.fftyaxis = eval(fftystr);
734
735set(handles.main,'UserData',data);
736
737% --- Executes during object creation, after setting all properties.
738function fftyaxis_CreateFcn(hObject, eventdata, handles)
739% hObject    handle to fftyaxis (see GCBO)
740% eventdata  reserved - to be defined in a future version of MATLAB
741% handles    empty - handles not created until after all CreateFcns called
742
743% Hint: edit controls usually have a white background on Windows.
744%       See ISPC and COMPUTER.
745if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
746    set(hObject,'BackgroundColor','white');
747end
748
749
750
751function fftxaxis_Callback(hObject, eventdata, handles)
752% hObject    handle to fftxaxis (see GCBO)
753% eventdata  reserved - to be defined in a future version of MATLAB
754% handles    structure with handles and user data (see GUIDATA)
755
756% Hints: get(hObject,'String') returns contents of fftxaxis as text
757%        str2double(get(hObject,'String')) returns contents of fftxaxis as a double
758data = get(handles.main,'UserData');
759
760fftxstr = get(hObject,'String');
761data.fftxaxis = eval(fftxstr);
762
763set(handles.main,'UserData',data);
764
765% --- Executes during object creation, after setting all properties.
766function fftxaxis_CreateFcn(hObject, eventdata, handles)
767% hObject    handle to fftxaxis (see GCBO)
768% eventdata  reserved - to be defined in a future version of MATLAB
769% handles    empty - handles not created until after all CreateFcns called
770
771% Hint: edit controls usually have a white background on Windows.
772%       See ISPC and COMPUTER.
773if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
774    set(hObject,'BackgroundColor','white');
775end
776
777
778
779
780% --- Executes when user attempts to close main.
781function main_CloseRequestFcn(hObject, eventdata, handles)
782% hObject    handle to main (see GCBO)
783% eventdata  reserved - to be defined in a future version of MATLAB
784% handles    structure with handles and user data (see GUIDATA)
785
786% Hint: delete(hObject) closes the figure
787
788% If the continuous update still running, then turn off before closing
789% window. Else it will loop and keep creating new figure, new application.
790if get(handles.start_stop,'Value')
791    set(handles.start_stop,'Value',0);
792    start_stop_Callback(handles.start_stop, eventdata, handles)
793end
794
795% Close handle for the PV holding the lifetime values.
796data = get(handles.main,'UserData');
797
798delete(hObject);
799
800
801
802
Note: See TracBrowser for help on using the repository browser.