-
Notifications
You must be signed in to change notification settings - Fork 0
/
QCM_v002e_Eurynomos.m
4767 lines (4579 loc) · 280 KB
/
QCM_v002e_Eurynomos.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = QCM_v002e_Eurynomos(varargin)
%
% Copyright (C) 2016 Joshua Yeh (Shull Research Group, Northwestern Uni.)
% Con tributing authors: Shu Funato
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>
%
%
% QCM_V002E_EURYNOMOS MATLAB code for QCM_v002e_Eurynomos.fig
% QCM_V002E_EURYNOMOS, by itself, creates a new QCM_V002E_EURYNOMOS or raises the existing
% singleton*.
%
% H = QCM_V002E_EURYNOMOS returns the handle to a new QCM_V002E_EURYNOMOS or the handle to
% the existing singleton*.
%
% QCM_V002E_EURYNOMOS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in QCM_V002E_EURYNOMOS.M with the given input arguments.
%
% QCM_V002E_EURYNOMOS('Property','Value',...) creates a new QCM_V002E_EURYNOMOS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before QCM_v002e_Eurynomos_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to QCM_v002e_Eurynomos_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help QCM_v002e_Eurynomos
% Last Modified by GUIDE v2.5 11-Aug-2017 15:44:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @QCM_v002e_Eurynomos_OpeningFcn, ...
'gui_OutputFcn', @QCM_v002e_Eurynomos_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before QCM_v002e_Eurynomos is made visible.
function QCM_v002e_Eurynomos_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to QCM_v002e_Eurynomos (see VARARGIN)
% Choose default command line output for QCM_v002e_Eurynomos
handles.output = hObject;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%NOTE: YOU CAN ADJUST THE DEFAULT VALUES/SETTINGS HERE, BUT BE CAREFULL
%WHEN MANIPULATING THE VALUES!! SAVING THE ORIGINAL VERSION IS STRONGLY
%RECOMMENDED.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%initialize AccessMyVNA program
clc; format compact; format long;
handles.GUI_hf=gcf;%store the main GUI handle in the handles structure
pos=get(handles.GUI_hf,'position');%extract the position values of the main GUI handle
set(handles.GUI_hf,'position',[20 pos(2) pos(3) pos(4)])%adjust the main GUI handle position values
h=waitbar(0,'Initializing MATLAB GUI...');
set(h,'WindowStyle','modal');
figure(h);
disp('Initializing MATLAB GUI...');
handles.din.AVNA='AccessMyVNAv0.7\release\AccessMyVNA.exe';%gold version of AccessMyVNA
% handles.din.AVNA='AccessMyVNAv0.7\release\AccessMyVNA_mod021015.exe';% modiied version
try %This try block attempts to kill the AccessMyVNA program through the Windows Command program, this will prevent multiple instances of the same program
[~,~]=system('taskkill /im "AccessMyVNA.exe"');
[~,~]=system('taskkill /im "MyVNA.exe"');s
catch
disp('Error in running commands in Windows Command line');
end%try
% Update handles structure
handles.din.freq_range=[4 6; 14 16; 24 26; 34 36; 44 46; 54 56];%this stores the accepted frequency ranges for each harmonic
handles.din.avail_harms=[1 3 5 7 9 11];%DO NOT CHANGE THIS
handles.din.error_count=1;%declar an error log vounter variable that is stored int he handles structure
handles.din.error_log={};%declare an error log variable that is stored in the handles structure
handles.din.prev_cond=zeros(str2double(get(handles.num_datapoints,'string')),1);
handles.din.harmonic=1;%default current harmonic value
handles.din.active_harm_primaryaxes1=[];%allocate fieldname that will hold the active harmonics that will be plotted
handles.din.active_harm_primaryaxes2=[];%allocate fieldname that will hold the active harmonics that will be plotted
handles.din.n=1;%starting initial index for FG_frequency
handles.din.max_datapts=2.5e4;%maximum datapoints the program will collect
handles.din.FG_frequency=NaN(handles.din.max_datapts,13);%preallocate matrix
handles.din.FG_freq_shifts=NaN(handles.din.max_datapts,13);%preallocate matrix
handles.din.chi_sqr_value=NaN(handles.din.max_datapts,13);%preallocate matrix
handles.din.std_fit=NaN(handles.din.max_datapts,13);%preallocate matrix
handles.din.set_span_factor_sensitivity=0.1;%this factor governs the sensitivity for the "set span" peak tracking algorithm
handles.din.fit_factor_range=6;%this factor influences the width or freq range in which the raw spectras will be fitted
set(handles.fit_factor,'string',handles.din.fit_factor_range);
handles.din.default_start_freq=[4.9;14.9;24.9;34.9;44.9;54.9];%set default start frequencies
handles.din.default_end_freq=[5.1;15.1;25.1;35.1;45.1;55.1];%set default end frequencies
handles.din.num_pts=300;%set default number of datapoints
handles.din.flag=0;%this is the toggle state of the raw fig button
handles.din.output_path=pwd;%set default path directory to current path working directory
handles.din.refit_flag=0;%create a flag that keeps track whether or not raw spectra data has been uploaded (0: no data loaded) (1: loaded)
handles.din.refit.loaded_var=[];%create a dummy variable that will hold any raw spectra data information for refitting processes
handles.din.bare_flag=0;%create a flag that keeps track whether or not a bare crystal data that redefines the reference freq and diss has been loaded (0=unloaded) (1=loaded)
handles.prefs.show_GB=0;%set the default option to show fitted parameters to on
handles.prefs.schedule_toggle=0;%This is the default toggle state of whether or not to run on a measurement schedule or not (1 for yes and 0 for no)
handles.prefs.clc_cw=0;%set default option to clear the command window before recording data
handles.prefs.output_diary=0;%set default option to not save a log of the comman window into a text file
handles.prefs.output_raw=0;%set default option to output the raw data onto the base workspace after each scan
handles.prefs.simul_peak=1;%set default option to fit conductance and susceptance simultaneously
handles.prefs.num_peaks=[1,0,1,0,1,0,1,0,1,0,1];%set default option for the number of peaks the program will maximally fit
handles.prefs.sensitivity(1)=5e-3;%peak sensitivity factor for the 1st harmonic
handles.prefs.sensitivity(3)=5e-3;%peak sensitivity factor for the 3rd harmonic
handles.prefs.sensitivity(5)=5e-3;%peak sensitivity factor for the 5th harmonic
handles.prefs.sensitivity(7)=5e-3;%peak sensitivity factor for the 7th harmonic
handles.prefs.sensitivity(9)=5e-3;%peak sensitivity factor for the 9th harmonic
handles.prefs.sensitivity(11)=5e-3;%peak sensitivity factor for the 11th harmonic
handles.prefs.peak_min(1)=.2;%min. peak finding threshold for the 1st harmonic
handles.prefs.peak_min(3)=.2;%min. peak finding threshold for the 3rd harmonic
handles.prefs.peak_min(5)=.2;%min. peak finding threshold for the 5th harmonic
handles.prefs.peak_min(7)=.2;%min. peak finding threshold for the 7th harmonic
handles.prefs.peak_min(9)=.2;%min. peak finding threshold for the 9th harmonic
handles.prefs.peak_min(11)=.2;%min. peak finding threshold for the 11th harmonic
handles.prefs.measurement_schedule=[];%set the default measurement schedule
handles.prefs.measurement_schedule_rnames={'Start','End'};%row names associated with the measurement scheduler
handles.prefs.schedule_toggle=0;%toggle state of the measurement schedule
handles.prefs.show_dfdg=0;%default state of whether or not to show the freq and bandwidth shifts
handles.prefs.email_recipient=[];%prealloate empty field that will be used to store a recipient email address for the email notfication functionality
handles.prefs.email_host=[];%preallocate empty field that will be used to store the host email address for the email notification functionality
handles.prefs.email_pw=[];%preallocate empty field that will be used to store the password of the host mail address for the email notification functionality
handles.prefs.email_outgoing_server=[];%preallocate empty filed that will be used to store the outgoing email server for the email notification functionality
handles.prefs.plot_dynamic_refresh=1;%this determines whether or not the plot will be dynamically refreshed after each scan
handles.prefs.save_spectra=0;%This determines whether or not the program will save the spectra files in the legacy format (v002d and below or not)
handles.din.refit.counter=1;%this counter is associated with keeping track which variable to load onto the program duringthe refitting process
handles.din.refit_filename=[];%the filename in which the refitting process will be enacted on
handles.din.refit_finish1=0;%this is a flag that represent whether or not all of the spectras for the 1st harmonic is finished refitting (refitting mode)
handles.din.refit_finish3=0;%this is a flag that represent whether or not all of the spectras for the 3rd harmonic is finished refitting (refitting mode)
handles.din.refit_finish5=0;%this is a flag that represent whether or not all of the spectras for the 5th harmonic is finished refitting (refitting mode)
handles.din.refit_finish7=0;%this is a flag that represent whether or not all of the spectras for the 7th harmonic is finished refitting (refitting mode)
handles.din.refit_finish9=0;%this is a flag that represent whether or not all of the spectras for the 9th harmonic is finished refitting (refitting mode)
handles.din.refit_finish11=0;%this is a flag that represent whether or not all of the spectras for the 11th harmonic is finished refitting (refitting mode)
handles.din.bare_path=pwd;%sets the default path directory when loading the bare crystal file
handles.din.refit_raw=[];%creates an empty structure array in which the raw loaded data will be stored in
handles.din.refit_time_index=1;%this index determines where in the loaded variable name to interpret as time
handles.din.refit_path=pwd;%set the default path directory
handles.din.refit_flag1=0;%flag associated with the refitting process
set(handles.wb,'xlim',[0 1]);cla(handles.wb);%set properties associated with the progress bar in between recordings of measurements
set(handles.refit_start,'visible','off');%turn of visibility of starting refit point
set(handles.refit_inc,'visible','off');%turn off visibility of the incremental value for the refitting proces
set(handles.refit_end,'visible','off');%turn off visibility of the ending refit point
filename='AccessMyVNAv0.7\release\state_matlab.txt';%define the filename in which the text file reflects the state of the MATLAB GUI
fileID=fopen(filename,'w');%set the text file to "Writeable"
fprintf(fileID,'%i\r\n',1);%Write in the "state_matlab.txt" with a value on 1, this indicates that the GUI is on and active. A value of zero means that the GUI is closed and inactive.
fclose(fileID);%properly close the filename associated with the file identifier, fileID
for dum=1:2:11%define the start/end frequencies and number of spectral datapoints for each harmonics
name1=['start_f',num2str(dum)];
name2=['end_f',num2str(dum)];
name3=['num_pts',num2str(dum)];
set(handles.(name1),'string',num2str(handles.din.default_start_freq((dum+1)/2)));
set(handles.(name2),'string',num2str(handles.din.default_end_freq((dum+1)/2)));
set(handles.(name3),'string',['# pts: ',num2str(handles.din.num_pts)]);
end%for dum=1:2:11
waitbar(0.1,h,'Preallocated MATLAB arrayso...');
disp('Preallocated MATLAB arrays...');
figure(h);
%set reference frequency shifts and dissipation shifts
handles.din.ref_freq=[5 15 25 35 45 55].*1e6;%units in Hz
handles.din.ref_diss=[100 100 100 100 100 100];%units in Hz
waitbar(0.15,h,'Reference values set...');
%inital formating of axes and buttons, etc.
waitbar(0.2,h,'Formatting plots and legend boxes...');
disp('Formatting plots and legend boxes...');
plot(handles.axes7,[0,1],[nan,nan],'-',[0,1],[nan,nan],'r-','visible','on');%add a legend box for the raw conductance plots
set(handles.axes7,'fontsize',6);%set font size of the legend
uistack(handles.axes7,'top');
l=legend(handles.axes7,'Conductance','Susceptance','Location','West');
set(l,'orientation','horizontal'); %set location of legend box
%add a legend for the harmonics
marker_color={[0 0 0],[0 0 1],[1 0 0],[0 0.5 0],[1 .8398 0],[.25 .875 .8125]};%marker color for the legend
figure(h);
set(handles.uipanel8,'visible','off');
set(handles.uipanel4,'visible','off');
set(handles.peak_finding,'visible','on','userdata',[handles.prefs.sensitivity(1:2:11);handles.prefs.peak_min(1:2:11);handles.prefs.num_peaks(1:2:11)]');
axes(handles.axes14);
for dum=1:6
waitbar(0.2+dum*0.05,h);
plot([0,1],[nan,nan],'o','visible','on','color',...
marker_color{dum},'markersize',6,'linewidth',1.5);
if verLessThan('matlab','8.3.0.532')%execute if MATLAB version is 2013a or earlier
hold(handles.axes14);
else%execute if MATLAB version id 2014b or later
hold(handles.axes14,'on');
end%
figure(h);
end%for dum=1:6
%Create a legend box for the primaryaxes1 and primaryaxes2
l=legend('1st','3rd','5th','7th','9th','11th','location','west');
posL=get(l,'position');
set(l,'orientation','horizontal','fontsize',10,'position',[2.2*posL(1) 1.27*posL(2) posL(3) posL(4)]);
set(handles.axes14,'fontsize',6,'visible','off');
figure(h);
%The following code creates the plot handles for each axes in the GUI.
%There is a plot handle for each harmonic, for the conductance, and for the
%susceptance. So a total of 24 plothandles with an additional
%"miscellaneous" plot handles are created. Predefining plots handles before
%hand makes the plotting process smoother, since the plot handles are not
%being created/destroyed each time a plot on the GUI refreshes.
for dum=1:6%create plot handles for the raw spectra axes
ax_name1=['axes',num2str(dum)];
ax_name2=['sa',num2str(dum)];
plot_name1=['phantom',num2str(dum),'a'];
plot_name2=['phantom',num2str(dum),'b'];
plot_name3=['phantom',num2str(dum),'c'];
plot_name4=['phantom',num2str(dum),'d'];
plot_name5=['phantom',num2str(dum),'e'];
plot_name6=['phantom',num2str(dum),'f'];
plot_name7=['phantom',num2str(dum),'g'];
plot_name8=['phantom',num2str(dum),'h'];
plot_name9=['phantom',num2str(dum),'i'];
plot_name10=['phantom',num2str(dum),'j'];
if verLessThan('matlab','8.3.0.532')%execute if MATLAB version is 2013a or earlier
hold(handles.(ax_name1));hold(handles.(ax_name2));
else%execute if MATLAB version id 2014b or later
hold(handles.(ax_name1),'on');hold(handles.(ax_name2),'on');
end% if verLessThan('matlab','8.3.0.532')
handles.spectra_handles.(plot_name1)=plot(handles.(ax_name1),[1,2],[1,1],'bx-','markersize',6,'visible','off','userdata',2*dum-1);
handles.spectra_handles.(plot_name2)=plot(handles.(ax_name2),[1 2],[1 1],'rx-','markersize',6,'visible','off','userdata',2*dum-1);
handles.spectra_handles.(plot_name3)=plot(handles.(ax_name1),[1,2],[1,1],'k-','linewidth',2,'visible','off');
handles.spectra_handles.(plot_name4)=plot(handles.(ax_name2),[1,2],[1,1],'k-','linewidth',2,'visible','off');
handles.spectra_handles.(plot_name5)=plot(handles.(ax_name1),[1,2],[1,1],'-','linewidth',2,'color',[0.82031 0.410156 0.11718],'visible','off');
handles.spectra_handles.(plot_name6)=plot(handles.(ax_name1),[1,2],[1,1],'mo','linewidth',1,'markerfacecolor','m','markersize',6,'visible','off');
handles.spectra_handles.(plot_name7)=plot(handles.(ax_name1),[1,2],[1,1],'o','linewidth',1,'color',[0 0.5 0],'markerfacecolor',[0 0.5 0],'markersize',6,'visible','off');
handles.spectra_handles.(plot_name8)=plot(handles.(ax_name1),[1,2],[1,1],'k-.','linewidth',1,'visible','off');
handles.spectra_handles.(plot_name9)=plot(handles.(ax_name1),[1,2],[1,1],'k-.','linewidth',1,'visible','off');
handles.spectra_handles.(plot_name10)=plot(handles.(ax_name1),[1,2],[1,1],'x','linewidth',1,'visible','off','color',[0 0.5 0],'markersize',6);
set(handles.(ax_name2),'visible','off','box','off','yaxislocation','right','color','none','ycolor','r');
set(handles.(ax_name1),'visible','on','box','off');
if verLessThan('matlab','8.3.0.532')%execute if MATLAB version is 2013a or earlier
hold(handles.(ax_name1));hold(handles.(ax_name2));
else%execute if MATLAB version id 2014b or later
hold(handles.(ax_name1),'off');hold(handles.(ax_name2),'off');
end%if verLessThan('matlab','8.3.0.532')
end%for dum-1:6
if verLessThan('matlab','8.3.0.532')%execute if MATLAB version is 2013a or earlier
hold(handles.primaryaxes1);hold(handles.primaryaxes2);
else%execute if MATLAB version id 2014b or later
hold(handles.primaryaxes1,'on');hold(handles.primaryaxes2,'on');
end%if verLessThan('matlab','8.3.0.532')
for dum=1:6%create plot handles for the primary axes
handles.primary_handles.(['phantom',num2str(dum),'a'])=plot(handles.primaryaxes1,[1,2],[1,1],'o-','color',marker_color{dum},'visible','off','userdata',2*dum-1,'markersize',6);
handles.primary_handles.(['phantom',num2str(dum),'b'])=plot(handles.primaryaxes2,[1,2],[1,1],'o-','color',marker_color{dum},'visible','off','userdata',2*dum-1,'markersize',6);
end%for dum=1:6
if verLessThan('matlab','8.3.0.532')%execute if MATLAB version is 2013a or earlier
hold(handles.primaryaxes1);hold(handles.primaryaxes2);
disp(['This program is designed for MATLAB 2014b or later. Running this program on ',...
version,' might lead to unexpected bugs! Use at your own risk!']);
else%execute if MATLAB version id 2014b or later
hold(handles.primaryaxes1,'off');hold(handles.primaryaxes2,'off');
end%if verLessThan('matlab','8.3.0.532')
set(handles.axes7,'visible','off');
set(handles.peak_center,'visible','off');
set(handles.center1,'value',1);
set(handles.primaryaxes1,'fontsize',8);
set(handles.primaryaxes2,'fontsize',8);
set(handles.maintain_myVNA,'value',1);
dcm_obj=datacursormode(handles.primary1);
dcm_obj.Enable='off';
delete(findall([handles.primaryaxes1 handles.primaryaxes2],'Type','hggroup'));
set(dcm_obj,'UpdateFcn',@default_dcm);
xlabel(handles.primaryaxes1,'Time (min)','fontsize',8,'fontweight','bold');
ylabel(handles.primaryaxes1,'Frequency (Hz)','fontsize',8,'fontweight','bold');
xlabel(handles.primaryaxes2,'Time (min)','fontsize',8,'fontweight','bold');
ylabel(handles.primaryaxes2,'Frequency (Hz)','fontsize',8,'fontweight','bold');
set(handles.num_datapoints,'userdata',ones(11,1).*handles.din.num_pts);%set the default number of datapoints for each harmonic
waitbar(0.6,h);
for dum=1:6%add labels to the conductance axes
waitbar(0.6+dum*0.05,h);
axname=['axes',num2str(dum)];
if verLessThan('matlab','8.4.0')%execute if MATLAB version is 2013a or earlier
set(handles.(axname),'fontsize',4);
else%execute if MATLAB version id 2014b or later
set(handles.(axname),'fontsize',4,'fontsmoothing','on');
end%
xlabel(handles.(axname),'Freqency (Hz)','fontsize',6);
ylabel(handles.(axname),'mSiemens (mS)','fontsize',6);
end%for dum=1:6
%add folder paths
addpath('AccessMyVNAv0.7\release');
%set default reference time
set(handles.reference_time,'string',datestr(clock,'yy:mm:dd:HH:MM:SS:FFF'));
%set default appearances and properties for GUI objects
set(handles.uipanel8,'visible','on');
set(handles.uipanel4,'visible','on');
set(handles.text2,'userdata',0);
set(handles.confirm_del,'userdata',0);
set(handles.email_push,'userdata',0);
write_settings(handles,handles.din.harmonic);%this function writes out the settings text file
plot1_choice_Callback(hObject, eventdata, handles);%refresh primaryaxes1
plot2_choice_Callback(hObject, eventdata, handles);%refresh primaryaxes2
handles.default_settings=handles.din;%define a default handles.din state
waitbar(1,h,'MATLAB GUI initiatlized!');
figure(h);
disp('MATLAB GUI initialized!');
guidata(hObject, handles);
figure(h);delete(h);
warning('off','MATLAB:DELETE:FileNotFound');%suppress this warning message
try delete('qcm_diary.txt');catch;end;
% UIWAIT makes QCM_v002e_Eurynomos wait for user response (see UIRESUME)
% uiwait(handles.primary1);
% --- Outputs from this function are returned to the command line.
function varargout = QCM_v002e_Eurynomos_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in start.
function start_Callback(hObject, ~, handles)
handles=cla_raw_Callback(hObject, 1, handles);
tic
err_counter=0;
pause on;
if get(handles.raw_fig,'value')==1%if the raw fig mode is turned on before the recording process, toggle handles.din.flag to 1
handles.din.flag=1;
disp('Please turn off the Raw Figure Mode before starting the measurement process!');
set(handles.status,'string','Status: Please turn off the Raw Figure Mode before starting the measurement process!',...
'backgroundcolor','y','foregroundcolor','r');
handles.din.flag=0;
if handles.din.refit_flag==0
set(handles.start,'value',0,'string','Record Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
else
set(handles.start,'value',0,'string','Refit Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
end%if handles.din.refit_flag==0
guidata(hObject,handles);
return
end%get(handles.raw_fig,'value')==1
% %//////////////////////////////////////////////////////////////////////////
%This if statement block checks to see if the user defined an output
%filename and location to store the data (besides the default output
%filename and location
if strcmp(get(handles.filename_txt,'string'),'<Output Filename>')&&get(handles.start,'value')==1
choice=questdlg('Do you want to designate a filename and location to store your data?',...
'Output filename and path confirmation','Yes');
switch choice
case 'Yes'
handles=save_data_Callback(hObject, 1, handles);
if handles.din.refit_flag==0
try%test if the designated outputfilename is a valid filename
test.(handles.din.output_filename)=1;
clear test;
catch err_message
assignin('base','err_message',err_message);
disp('Filename is not valid! Please use MATLAB variable naming rules.');
disp('Please try again');
set(handles.status,'string','ERROR!Filename is not valid! PLease use MATLAB variable naming rules. Please try again...',...
'backgroundcolor','r','foregroundcolor','k');
if handles.din.refit_flag==0
set(handles.start,'value',0,'string','Record Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
else
set(handles.start,'value',0,'string','Refit Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
end%if handles.din.refit_flag==0
return
end%try
end%if handles.din.refit_flag==0
case 'No'
handles.din.output_filename='Default';
handles.din.output_path='';
case 'Cancel'
if handles.din.refit_flag==0
set(handles.start,'value',0,'string','Record Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
else
set(handles.start,'value',0,'string','Refit Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
end%if handles.din.refit_flag==0
return
end%switch choice
end%if strcmp(get(handles.filename_txt,'string'),'<Output Filename>')
% %//////////////////////////////////////////////////////////////////////////////////////////////////////
%DISABLE GUI FUNCTIONS
%disable some of the features to prevent errors from occuring caused by
%running two blocks of code simultaneously
set(handles.peak_centering,'value',0);
harm_tot=find_num_harms(handles);%find total active harmonics
if isempty(harm_tot)
harm_tot=1;
set(handles.harm1,'value',1);
end%if isempty(harm_tot)
set(handles.harmonics_text,'userdata',harm_tot);%store the harmonic that will be scanned in the userdata property of the harmonic_text gui handle
peak_centering_Callback(handles.peak_centering, 1, handles);drawnow;
set(handles.peak_centering,'visible','off');%hide the button
set(handles.clear_datapoints,'visible','off');%hide the button
set(handles.home_push,'visible','off');%hide the home button
set(handles.del_mode,'visible','off','state','off');%hide the del_mode toolbar button
del_mode_ClickedCallback(handles.del_mode, 1, handles);
set(handles.confirm_del,'visible','off');%hide the confim_del toolbar button
set(handles.refit_start,'style','text');%prevent the user from editing the value during the refitting process
% %/////////////////////////////////////////////////////////////////////////////////////////////////////
counter=1;%counter
write_settings(handles,harm_tot(1));%this function writes out the settings text file
%update string of the start button based on the toggle state
if get(handles.start,'value')==1
if isempty(findobj('Number',998))==0
delete(figure(998));
pref_ClickedCallback(handles.pref, 1, handles);
end%if isempty(findobj('string','Set Preferences (Beta)','Number',998))==0
if handles.prefs.clc_cw==1%clear window only when the user specifies to clear the window, this can be set in the user preferences
clc
end%if handles.prefs.clc_cw==1
set(handles.start,'string','Stop Scan','backgroundcolor','r');
elseif get(handles.start,'value')==0
if handles.din.refit_flag==0
set(handles.start,'value',0,'string','Record Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
else
set(handles.start,'value',0,'string','Refit Scan','backgroundcolor',[0 0.5 0],'foregroundcolor','w');
end%if handles.din.refit_flag==0
set(handles.uipanel1,'visible','off');%hides the settings panel
set(handles.status,'string','Status: Stopping the data recording process. Please wait...',...
'backgroundcolor','k','foregroundcolor','r');
set(handles.raw_fig,'value',0);
set(handles.peak_centering,'visible','on');%display the button
set(handles.clear_datapoints,'visible','on');%display the button
set(handles.uipanel1,'visible','on');%display uipanel1
set(handles.home_push,'visible','on');%display the reset button
set(handles.del_mode,'visible','on');%display the del_mode toolbar button
return
end%if get(handles.start,'value')==1
%Check/modify output filename so that errors will not occur during the
%scanning process and storing of spectra data
try
disp(['Output filename: ',handles.din.output_filename]);
output_filename=handles.din.output_filename;
output_filename=strrep(output_filename,' ','_');
output_filename=strrep(output_filename,'(','_');
output_filename=strrep(output_filename,')','_');
output_filename=strrep(output_filename,'.','_');
output_filename=strrep(output_filename,'-','_');
if length(output_filename)>namelengthmax
disp('Error in specifying filename!');
set(handles.status,'string','Status: ERROR in specifying filename! Filename is too long!',...
'backgroundcolor','r','foregroundcolor','k');
handles.din.error_log(handles.din.error_count,1)={[datestr(clock),' ERROR in specifying filename! Filename is too long!']};
handles.din.error_count=handles.din.error_count+1;
assignin('base','error_log',handles.din.error_log);
disp('Recording process terminated');
return
end%if length(output_filename)>namelengthmax
catch
disp('Error in specifying filename!');
set(handles.status,'string','Status: ERROR in specifying filename!','backgroundcolor','r','foregroundcolor','k');
handles.din.error_log(handles.din.error_count,1)={[datestr(clock),' ERROR in specifying filename!']};
handles.din.error_count=handles.din.error_count+1;
assignin('base','error_log',handles.din.error_log);
disp('Recording process terminated');
return
end
%///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
%designate output file location and name for output data
if get(handles.filename_txt,'userdata')==0&&handles.din.refit_flag==0
spectra = matfile('raw_spectras.mat','Writable',true);%open matfile and set access to writable
elseif get(handles.filename_txt,'userdata')~=0&&handles.din.refit_flag==0
spectra = matfile([handles.din.output_path,handles.din.output_filename,'_raw_spectras.mat'],'Writable',true);%open matfile and set access to writable
end%if get(handles.filename_txt,'userdata')==0
spectra.version=get(handles.text17,'string');%write the version of the matlab gui program that was used to collect the data
if get(handles.filename_txt,'userdata')==0
fg_values=matfile('fg_values.mat','Writable',true);
else
fg_values=matfile([handles.din.output_path,handles.din.output_filename],'Writable',true);
end%if get(handles.filename_txt,'userdata')==0
fg_values.version=get(handles.text17,'string');%write the version of the matlab gui program that was used to collect the data
% %///////////////////////////////////////////////////////////////////////////////////////////////////////
%Check to see if email notifications are turned on
if isempty(get(handles.email_push,'userdata'))~=1
if get(handles.email_push,'userdata')==1
diary('qcm_diary.txt'); diary on;
disp('#################################');
try
cprintf('blue','Email notifications have been turned on\n');
catch
disp('Email notifications have been turned on');
end%try
disp(['Notifications will be sent to ',get(handles.prefs.email_recipient,'userdata')]);
end% if get(handles.email_push,'userdata')==1
end%if isempty(get(handles.email_push,'userdata'))~=1
if handles.prefs.output_diary==1
try
cprintf('blue','The Command Window Diary has been turned on\n');
catch
disp('The Command Window Diary has been turned on');
end%try
diary('qcm_diary.txt'); diary on;
disp('#################################');
end%if handles.prefs.output_diary==1
% %//////////////////////////////////////////////////////////////////////////////////////////////////////////////
%Check to see if the fitting options were accidentally set to
%"user-defined" values. If so, change it to "Previous Values"
for dum=1:2:11
if get(handles.(['fit',num2str(dum)]),'userdata')==5||strcmp(get(handles.(['fit',num2str(dum)]),'string'),'User-defined')
set(handles.(['fit',num2str(dum)]),'userdata',4,'string','Previous values');
end%if get(handles.(['fit',num2str(dum)]),'userdata')==5
end%for dum=1:2:11
%///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
%Format reference time, define other variables, and disp other misc. things before initiating while loop
start_time2=datevec(get(handles.reference_time,'string'),'yy:mm:dd:HH:MM:SS:FFF');%get reference time into an appropriate format
n=handles.din.n;
disp('-------------------------------');
my_disp('Measurement process initiated>>>>>>>>\n',[0 0 0.7]);
my_disp('Time of initiation: ','text');
my_disp([datestr(clock),'\n'],[0 0.5 0]);
my_disp('Reference time: ','text');
my_disp([datestr(start_time2),'\n'],[0 0.5 0]);
if handles.prefs.schedule_toggle==1%if the measurement scheduler is turned on display the following
my_disp('Measurement Scheduler has been enabled!\n',[0 0 0.7]);
for dum=1:size(handles.prefs.measurement_schedule,1)%display the schedule
my_disp([handles.prefs.measurement_schedule_rnames{dum,1},': '],'text');
my_disp([handles.prefs.measurement_schedule{dum,1},'\n'],[0 0.5 0]);
end%for dum=1:size(handles.prefs.measurement_schedule,1)
start_date_vec=datevec(handles.prefs.measurement_schedule{1,1});%convert the start event to a date vector
%check to see if the start event should be triggered
while etime(start_date_vec,clock)>0&&get(handles.start,'value')==1%run this code if we should wait for time to pass before the start event
set(handles.status,'string',['Status: Start time for measurment is: ',handles.prefs.measurement_schedule{1,1},'........',...
num2str(etime(start_date_vec,clock)),'s left before start of the measurment process.'],'backgroundcolor','y','foregroundcolor','r');
drawnow;
pause(1);
end%if etime(start_date_vec,clock)<=0
end%if handles.prefs.schedule_toggle==1
handles.din.refit_flag1=0;%reset the refit_flag1
%-------------------------------------------------------------------------------------------------while loop begins here!
while get(handles.start,'value')==1&&handles.din.refit_flag==0||...
get(handles.start,'value')==1&&handles.din.refit_flag==1&&...
sum([handles.din.refit_finish1,handles.din.refit_finish3,...
handles.din.refit_finish5,handles.din.refit_finish7,...
handles.din.refit_finish9,handles.din.refit_finish11])==0%<-----------------while loop begins here!
%/////////////////////////////////////////////////////////////////////////////////////
%RUN THIS CODE IF THE MEASUREMENT SCHEDULER IS TURNED ON
if handles.prefs.schedule_toggle==1
timeline=handles.prefs.measurement_schedule(:,1);%extract out all of the times
timeline2=ones(size(timeline));%preallocate this array in order to speed the for loop
for dum=1:size(timeline,1)%determine the relative elapsed time from now to the defined times in the schedule
timeline2(dum)=etime(datevec(timeline{dum}),clock);
end%for dum=1:size(timeline,1)
k=find(timeline2<=0,1,'last');%find the the most recent event that has passed and execute it
if handles.prefs.schedule_state(k)==0%execute this code only if the code has not already been executed
set(handles.record_time_increment,'string',handles.prefs.measurement_schedule{k,2});%set the user-defined recording time increment
drawnow;%force the computer to display the updated recording time increment
my_disp(['Initiated ',handles.prefs.measurement_schedule_rnames{k},'!\n'],[0 0 0.7]);
handles.prefs.schedule_state(k)=1;%remember that this event has already bben excuted and does not need to be executed again
if k==size(handles.prefs.measurement_schedule,1)%Only execute this code if it is the ending event
set(handles.start,'value',0);%un toggle the start button
start_Callback(hObject,1,handles);%stop the measurement process
end%if k==size(handles.measurement_schedule,1)
end%if handles.prefs.schedule_state(k)==0
end%if get(handles.prefs.schedule_toggle)==1
%/////////////////////////////////////////////////////////////////////////////////////
harm_tot=find_num_harms(handles);%find total active harmonics
if isempty(harm_tot)%if there are no harmonics selected to be recorded by the user, default to recording the first harmonic
harm_tot=1;
set(handles.harm1,'value',1);
end%if isempty(harm_tot)
%//////////////////////////////////////////////////////////////
%Determine variable name in which the spectra information will be
%stored and time stamp information
if handles.din.refit_flag==0%run this if collecting dynamic data
time_now=datestr(clock,'yy:mm:dd:HH:MM:SS:FFF');%Current time
time_now1=datevec(time_now,'yy:mm:dd:HH:MM:SS:FFF');%Find current time and make it a vector
Z=etime(time_now1,start_time2);%elapsed time in seconds
time_elapsed=Z./60;%time in minutes
timestamp=strrep(num2str(time_elapsed),'.','dot');%replace decimal with 'dot'
my_disp('---------------------\n',[0 0.5 0]);
my_disp('Timestamp: ','text');
my_disp([num2str(time_elapsed),' min\n'],'blue');
set(handles.last_time,'string',['Last timepoint: ',num2str(time_elapsed),' min']);
else%run this if refitting raw spectra data
try
try
rawfile=['h',num2str(harm_tot(1))];
catch%run this if dum is equal to 1
rawfile=['h',num2str(harm_tot(2))];
end%try
time_elapsed=handles.din.refit_timepoints(handles.din.refit.counter);
timestamp2=num2str(time_elapsed);%time in minutes
my_disp('---------------------\n',[0 0.5 0]);
my_disp('Timestamp: ','text');
my_disp([timestamp2,' min\n'],'blue');
set(handles.last_time,'string',['Last timepoint: time_elapsed min']);
catch
end%try
end%if handles.din.refit_flag==0
%//////////////////////////////////////////////////////////////
%if in refitting mode display it in the command window
if handles.din.refit_flag==1
try cprintf('blue','Currently in refitting mode!\n');
catch; disp('Currently in refitting mode!');
end%try
end%if handles.din.refit_flag==1
for dum=1:size(harm_tot,1)%this for loop will repeat through a whole cycle of harmonics that will be measured
my_disp('..............................\n',[0 0.5 0]);
try
handles.din.harmonic=harm_tot(dum);%write the current harmonic into the handles.din structure
handles.din.n=n;%write the current index datapoint in the handles.din. structure
if dum==size(harm_tot,1)
handles.din.refit_flag1=1;
else
handles.din.refit_flag1=0;
end%if dum==size(harm_tot,1)
[freq,conductance,susceptance,handles]=read_scan(handles);%read the data from the output myVNA c++ output file
catch err_message
disp('Error reading data!');
set(handles.status,'string','Status: ERROR reading data!','foregroundcolor','k','backgroundcolor','r');
assignin('base','err_message',err_message);
end
if get(handles.start,'value')==1&&handles.din.refit_flag==0||handles.din.refit_flag==1&&handles.din.(['refit_finish',num2str(handles.din.harmonic)])==0
my_disp('Scanning harmonic: ','cyan');
my_disp([num2str(harm_tot(dum)),'\n'],'cyan');
tic
try
%only run the following if statement if the user wants to see the it dynamically
if get(handles.dynamic_fit,'value')==1%this if statement will run the Lorentzian fitting function
[combine_spectra,GB_parameters,handles,I,std_fit]=Lorentzian_dynamic_fit(handles,freq,conductance,susceptance,[freq,conductance,susceptance]);
else%if the "dynamic fit" option is not turned on, output the freq, conductance, susceptance as a zero matrix
combine_spectra=[freq,conductance,susceptance,zeros(size(freq,1),7)];
end%if get(handles.dynamic_fit,'value')==1
G_fit=combine_spectra(:,4);
B_fit=combine_spectra(:,5);
%//////////////////////////////////////////////////////////////
%write out spectra in specified spectra filename
try
if handles.din.refit_flag==0%only run this code if not in "refitting" mode
if handles.prefs.save_spectra==1%decide what format to save the raw spectra
full_outputfilename=sprintf([output_filename,'_t_%s_iq_1_ih_',num2str((harm_tot(dum)+1)./2)],timestamp);
spectra.(full_outputfilename) = combine_spectra;%renames variable based on harm and writes the raw spectra data to <filename?>_raw_spectras.mat
end%if handles.prefs.save_spectra==1
spectra.(['raw_spectra_',num2str(harm_tot(dum))])(n,1:4)={time_elapsed,output_filename,harm_tot(dum),combine_spectra};
end%if handles.din.refit_flag==0
if get(handles.dynamic_fit,'value')==1
handles.din.FG_frequency(n,1)=time_elapsed;%timestamp
handles.din.FG_frequency(n,harm_tot(dum)+1)=GB_parameters(1)*1e6;%frequency at peak of Lorentzian fit, f0
handles.din.FG_frequency(n,harm_tot(dum)+2)=GB_parameters(2)*1e4;%HMHW of Lorentzian peak, Ga
handles.din.FG_freq_shifts(n,1)=handles.din.FG_frequency(n,1);%timestamp
handles.din.FG_freq_shifts(n,harm_tot(dum)+1)=GB_parameters(1)*1e6-handles.din.ref_freq((harm_tot(dum)+1)./2);%calculate delta f
handles.din.FG_freq_shifts(n,harm_tot(dum)+2)=GB_parameters(2)*1e4-handles.din.ref_diss((harm_tot(dum)+1)./2); %calculate delta Gamma
%Chi sq calculation (right now it is least squares not chi squares (04012014))
handles.din.chi_sqr_value(n,1)=time_elapsed;%Timestamps chi squared value variable
handles.din.chi_sqr_value(n,harm_tot(dum)+1)=sum(combine_spectra(:,6));%stores chi squared for G
handles.din.chi_sqr_value(n,harm_tot(dum)+2)=sum(combine_spectra(:,7));%stores chi squared for B
%standard deviation from Lorentz fit using nlparci function
handles.din.std_fit(n,1)=time_elapsed;%Timestamp
handles.din.std_fit(n,harm_tot(dum)+1)=std_fit(1);%standard deviation of fitted f value
handles.din.std_fit(n,harm_tot(dum)+2)=std_fit(2);%standard deviation of fitted gamma value
if get(handles.radio_chi,'value')==1 %determine whether or not to show chi squared parameters next to plots
xsq_name=['X',num2str(harm_tot(dum))];
set(handles.(xsq_name),'visible','on','string',...
[char(935),'sq = ',num2str(handles.din.chi_sqr_value(n,harm_tot(dum)+1))],'fontsize',8);
disp([char(935),'sq = ',num2str(handles.din.chi_sqr_value(n,harm_tot(dum)+1))]);
end%if get(handles.radio_chi,'value')==1
if handles.prefs.show_dfdg==1&&get(handles.radio_chi,'value')==0
xsq_name=['X',num2str(harm_tot(dum))];
set(handles.(xsq_name),'visible','on','string',...
[char(916),'f= ',num2str(GB_parameters(1)*1e6-handles.din.ref_freq((harm_tot(dum)+1)./2),1),...
' ',char(916),char(915),'= ',num2str(GB_parameters(2)*1e4-handles.din.ref_diss((harm_tot(dum)+1)./2),1)],'fontsize',10,...
'tooltipstring',['<html>Δf= ',num2str(GB_parameters(1)*1e6-handles.din.ref_freq((harm_tot(dum)+1)./2),8),...
' ΔΓ= ',num2str(GB_parameters(2)*1e4-handles.din.ref_diss((harm_tot(dum)+1)./2),8),'</html>']);
end%if handles.prefs.show_dfdg==1
end%if get(handles.dynamic_fit,'value')==1
catch err_message
disp('Error in writing out spectra to specified filename!');
set(handles.status,'string','Status: ERROR in saving spectra!','backgroundcolor','r','foregroundcolor','k');
handles.din.error_log(handles.din.error_count,1)={[datestr(clock),' ERROR in saving spectra!']};
handles.din.error_count=handles.din.error_count+1;
err_counter=err_counter+1;
assignin('base','error_log',handles.din.error_log);
assignin('base','matlab_err_message',err_message);
if get(handles.email_push,'userdata')==1&&mod(err_counter,10)==9;
email_send(handles,'An error was detected by the QCM MATLAB Program: ERROR in saving spectra!');
end
end% err_message
%//////////////////////////////////////////////////////////////
catch err_message
disp('Error in start_callback function!');
set(handles.status,'string','Status: ERROR in callback function!','backgroundcolor','r','foregroundcolor','k');
handles.din.error_log(handles.din.error_count,1)={[datestr(clock),' ERROR in callback function!']};
handles.din.error_count=handles.din.error_count+1;
err_counter=err_counter+1;
assignin('base','error_log',handles.din.error_log);
assignin('base','matlab_err_message',err_message);
if get(handles.email_push,'userdata')==1&&mod(err_counter,10)==9;
email_send(handles,'An error was detected by the QCM MATLAB Program: ERROR in callback function!');
end
end%try err_message
if get(handles.start,'value')==0
disp('Scan stopped');
end%if get(handles.start,'value')==0
counter=counter+1;
%/////////////////////////////////////////////////////////////////
%plot the data set
%this if statement code refreshes the spectra every <user-defined>th iteration of the while loop
%output harmonic in appropriate axes
ax1=['axes',num2str((harm_tot(dum)+1)*0.5)];
ax2=['sa',num2str((harm_tot(dum)+1)*0.5)];
try
try%this try statement will turn off the visibility of all of the spectra plothandles
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'a']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'b']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'c']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'d']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'e']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'f']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'g']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'h']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'i']),'visible','off');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'j']),'visible','off');
catch
handles=cla_raw_Callback(hObject, 1, handles);
end%try
if mod(counter,str2double(get(handles.refresh_spectra,'string')))==0
if get(handles.polar_plot,'value')==0%<-----------------------------------------------------------------------------determine whether or not to show the raw data in polar coordinates
disp(['Plotting harmonic: ', num2str(harm_tot(dum)),' in ',ax1]);%show in the command window which harmonic is being plotted
refreshing(handles,harm_tot(dum),1);%show which plot is being refreshed
if get(handles.show_susceptance,'value')==1 %<--------------------------------PLOT BOTH THE CONDUCTANCE AND SUSCEPTANCE
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'a']),...
'xdata',freq,'ydata',conductance,'visible','on');%plot conductance versus frequency
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'b']),...
'xdata',freq,'ydata',susceptance,'visible','on');%plot susceptance versus frequency
set(handles.(ax1),'xlim',[min(freq) max(freq)],...
'ylim',[min(conductance),min(conductance)+1.2*(max(conductance)-min(conductance))]-0.05*(max(conductance)-min(conductance)));%adjust axes
set(handles.(ax2),'xlim',get(handles.(ax1),'xlim'),...
'ylim',[min(susceptance),min(susceptance)+1.2*(max(susceptance)-min(susceptance))]-0.05*(max(susceptance)-min(susceptance)),'visible','on');%adjust axes
else%if get(handles.show_susceptance,'value')==1 <-----------------------------ONLY PLOT THE CONDUCTANCE CURVE
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'a']),...
'xdata',freq,'ydata',conductance,'visible','on');%Plot conductance versus frequency
set(handles.(ax1),'xlim',[min(freq) max(freq)],...
'ylim',[min(conductance),min(conductance)+1.2*(max(conductance)-min(conductance))]-0.05*(max(conductance)-min(conductance)));%adjust axes
end%if get(handles.show_susceptance,'value')==1
if get(handles.dynamic_fit,'value')==1%<---------------------------------------run this block of code if the option to fit the curves dynamically is turned on
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'c']),...
'xdata',freq,'ydata',G_fit,'visible','on')%Plot the fitted conductance versus the frequency
xdata=freq(I);ydata=ones(size(I,1),1)'.*min(conductance);
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'e']),...
'xdata',xdata,'ydata',ydata,'visible','on');%plot the range in which the dataset was used to find the fitted parameters
set(handles.(ax1),'xlim',[min(freq) max(freq)]);%adjust axes
if get(handles.show_susceptance,'value')==1%<-------------------------------- SUSCEPTANCE CURVE IS TURNED ON
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'d']),...
'xdata',freq,'ydata',B_fit,'visible','on');%plot the fitted susceptance values versus the frequency
set(handles.(ax2),'xlim',get(handles.(ax1),'xlim'),'visible','on');%adjust the axes
if length(GB_parameters)>=6%<------------if plotting 1 peak
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'f']),...
'xdata',GB_parameters(1)*1e6,'ydata',GB_parameters(4)+GB_parameters(5),'visible','on');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'g']),...
'xdata',[GB_parameters(1)*1e6-GB_parameters(2)*1e4,GB_parameters(1)*1e6+GB_parameters(2)*1e4],...
'ydata',[GB_parameters(4)/2,GB_parameters(4)/2]+GB_parameters(5),'visible','on');
end%if length(GB_parameters)>=6
peak_track=get(handles.(['peak_track',num2str(handles.din.harmonic)]),'userdata');%extract out the peak tracking conditions
if peak_track(1)==1&&peak_track(2)==0%if peak tracking algorithm is set to set span, show tolerance interval lines
current_span=max(freq)-min(freq);%extract the span set by the start and end frequencies
temp_ylim=get(handles.(ax1),'ylim');%extract out the current span of the axes
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'h']),...
'xdata',[mean(freq)-current_span*handles.din.set_span_factor_sensitivity,mean(freq)-current_span*handles.din.set_span_factor_sensitivity],...
'ydata',temp_ylim,'visible','on');%plot the LOWER bound tolerances for adjusting the start and end frequencies based on the set span algorithm
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'i']),...
'xdata',[mean(freq)+current_span*handles.din.set_span_factor_sensitivity,mean(freq)+current_span*handles.din.set_span_factor_sensitivity],...
'ydata',temp_ylim,'visible','on');%plot the UPPER bound tolerances for adjusting the start and end frequencies based on the set span algorithm
end %if peak_track(1)==1&&peak_track(2)==0
set(handles.(ax1),'ylimmode','auto');
linkaxes([handles.(ax1),handles.(ax2)],'x');%link the xaxis together
else%if get(handles.show_susceptance,'value')==1<-------------------------------- SUSCEPTANCE CURVE IS TURNED OFF
peak_track=get(handles.(['peak_track',num2str(handles.din.harmonic)]),'userdata');%extract out the peak tracking conditions
if peak_track(1)==1&&peak_track(2)==0%if peak tracking algorithm is set to set span, show tolerance interval lines
current_span=max(freq)-min(freq);%determine the span of the colleccted data based on the start and end frequencies
temp_ylim=[min(conductance)-.2*abs(min(conductance)),max(conductance)+.2*abs(max(conductance))];%define ylim values for the axes
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'h']),...
'xdata',[mean(freq)-current_span*handles.din.set_span_factor_sensitivity,mean(freq)-current_span*handles.din.set_span_factor_sensitivity],...
'ydata',temp_ylim,'visible','on');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'i']),...
'xdata',[mean(freq)+current_span*handles.din.set_span_factor_sensitivity,mean(freq)+current_span*handles.din.set_span_factor_sensitivity],...
'ydata',temp_ylim,'visible','on');
end %if peak_track(1)==1&&peak_track(2)==0
if length(GB_parameters)>=6%<------------if plotting 1 peak
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'f']),...
'xdata',GB_parameters(1)*1e6,'ydata',GB_parameters(4)+GB_parameters(5),'visible','on');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'g']),...
'xdata',[GB_parameters(1)*1e6-GB_parameters(2)*1e4,GB_parameters(1)*1e6+GB_parameters(2)*1e4],...
'ydata',[GB_parameters(4)/2,GB_parameters(4)/2]+GB_parameters(5),'visible','on');
end%if length(G_parameters)==5
set(handles.(ax1),'ylimmode','auto');
end%if get(handles.show_susceptance,'value')==1
plot_primaryaxes1(handles,handles.din.FG_frequency,harm_tot,n);
plot_primaryaxes2(handles,handles.din.FG_frequency,harm_tot,n);
end%if get(handles.dynamic_fit,'value')==1
ylabel(handles.(ax1),'mSiemans (mS)','fontsize',6);
xlabel(handles.(ax1),'Frequency (Hz)','fontsize',6);
else%<-----------------------------------------------------------------------------plot the raw data in polar plot form
disp(['Plotting harmonic: ', num2str(harm_tot(dum)),' in ',ax1]);
refreshing(handles,harm_tot(dum),1);%show which plot is being refreshed
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'j']),...
'xdata',conductance,'ydata',susceptance,'visible','on');
axis tight
if get(handles.dynamic_fit,'value')==1
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'c']),...
'xdata',G_fit','ydata',B_fit,'visible','on');
set(handles.spectra_handles.(['phantom',num2str((harm_tot(dum)+1)*0.5),'e']),...
'xdata',G_fit(I),'ydata',B_fit(I),'visible','on');
set(handles.(ax1),'xlim',[min(G_fit) max(G_fit)],'ylim',[min(B_fit) max(B_fit)])
end%if get(handles.dynamic_fit,'value')==1
if get(handles.dynamic_fit,'value')==1
plot_primaryaxes1(handles,handles.din.FG_frequency,harm_tot,n);
plot_primaryaxes2(handles,handles.din.FG_frequency,harm_tot,n);
end%if get(handles.dynamic_fit,'value')==1
xlabel(handles.(ax1),'Conductance (mS)','fontsize',6);
ylabel(handles.(ax1),'Susceptance (mS)','fontsize',6);
end%if get(handles.polar_plot,'value')==1
drawnow;
if get(handles.raw_fig,'value')==1&&handles.din.refit_flag==1%display the plots in raw figure mode
clf(figure((handles.din.harmonic+1)/2));
rf_axes=copyobj(handles.(ax1),figure((handles.din.harmonic+1)/2));
set(rf_axes,'units','normalized','position',[0.13 0.11 0.775 0.815],'fontsize',12);
end%if get(handles.raw_fig,'value')==1&&handles.din.refit_flag==0s
end%if mod(counter,str2double(get(handles.refresh_spectra,'string')))==0
catch err_message
disp('Error in plotting data!');
set(handles.status,'string','Status: ERROR in plotting data!','backgroundcolor','r','foregroundcolor','k');
handles.din.error_log(handles.din.error_count,1)={[datestr(clock),' ERROR in plotting data!']};
handles.din.error_count=handles.din.error_count+1;
err_counter=err_counter+1;
assignin('base','error_log',handles.din.error_log);
assignin('base','matlab_err_message',err_message);
handles=cla_raw_Callback(hObject, 1, handles);
if get(handles.email_push,'userdata')==1&&mod(err_counter,10)==9;
email_send(handles,'An error was detected by the QCM MATLAB Program: ERROR in plotting data!');
end
end%try err_message
%//////////////////////////////////////////////////////////////////////
%this block of code deals with peak tracking
if get(handles.dynamic_fit,'value')==1&&handles.din.refit_flag==0%use the fitted parameters to determine how to track the peak
disp('Tracking peak...');
try handles=smart_peak_tracker(handles,freq,conductance,susceptance,GB_parameters(1:5)); catch; end;
elseif get(handles.dynamic_fit,'value')~=1&&handles.din.refit_flag==0%guess what f0 and gamma0 to determine how to track the peak
[peak_detect,index]=findpeaks(conductance,'sortstr','descend');
Gmax=peak_detect(1);%find peak of curve
f0=freq(index(1));%finds freq at which Gmax happens
halfg=Gmax./2;%half of the Gmax
halfg_freq=freq(find(abs(halfg-conductance)==min(abs((halfg-conductance))),1));
gamma0=abs(halfg_freq-f0);%Guess for gamma, HMHW of peak
guess=[f0 gamma0 0 Gmax 0];
disp('Tracking peak...');
handles=smart_peak_tracker(handles,freq,conductance,susceptance,guess);
end
%//////////////////////////////////////////////////////////////////////
if handles.din.refit_flag==0
pause(str2double(get(handles.wait_time,'string'))./1000);
end%if handles.din.refit_flag==0
refreshing(handles,harm_tot(dum),0);
temp=toc;
my_disp('Elapsed time is ','cyan');
my_disp([num2str(temp),' seconds\n'],'cyan');
end%for get(handles.start,'value')==1
write_settings(handles,harm_tot(dum));%update the setting txt file
if handles.prefs.plot_dynamic_refresh==1
guidata(handles.primary1,handles);
end%if handles.prefs.plot_dynamic_refresh==1
end%for dum=1:size(harm_tot)
my_disp('Datapoint(s): ','cyan');
my_disp([num2str(n),'\n'],'cyan');
set(handles.tot_datapts,'string',['Datapts collected: ',num2str(n)]); %display total number of collected datapoints for each harmonic
n=n+1;
%//////////////////////////////////////////////////////////////////////////
%Autosave code starts here
if str2double(get(handles.record_time_increment,'string'))>60
%//////////////////////////////////////////////////////////////////////////
%Write out chi values, f0, and gamma0 into spectra file
disp('Saving Data...');
set(handles.status,'string','Status: Saving data...','backgroundcolor','k','foregroundcolor','r');
drawnow;
reference=char(get(handles.reference_time,'string'),get(handles.wait_time,'string')...
,get(handles.num_datapoints,'string'),get(handles.record_time_increment,'string'));%records reference time
fg_values.reference=reference;
if handles.din.refit_flag==0
spectra.reference=reference;
end%if handles.din.refit_flag==0
if get(handles.dynamic_fit,'value')==1
save_shifts(handles,fg_values);
disp('Data saved!');
end%if get(handles.dynamic_fit,'value')==1
set(handles.status,'string','Status: Data saved! Ready...','backgroundcolor','k','foregroundcolor','r');
%//////////////////////////////////////////////////////////////////////////
%Update handles structure
for dum=1:2:11
name=['X',num2str(dum)];
prev_data=get(handles.(name),'userdata');
if isempty(prev_data)~=1
handles.din.(['GB_prev',num2str(dum)])=prev_data(1,:);
end%if isempty(prev_data)~=1
end%for dum=1:2:11
handles.din.n=n;
if get(handles.email_push,'userdata')==1&&mod(n,round(3600/str2double(get(handles.record_time_increment,'string'))))==0
email_send(handles,'Update notification sent by QCM MATLAB Program.');
end%if get(handles.email_push,'userdata')==1
elseif mod(n,50)==0
%//////////////////////////////////////////////////////////////////////////
%Write out chi values, f0, and gamma0 into spectra file
disp('Saving Data...');
set(handles.status,'string','Status: Saving data...','backgroundcolor','k','foregroundcolor','r');
drawnow;
reference=char(get(handles.reference_time,'string'),get(handles.wait_time,'string')...
,get(handles.num_datapoints,'string'),get(handles.record_time_increment,'string'));%records reference time
fg_values.reference=reference;
if handles.din.refit_flag==0
spectra.reference=reference;
end%if handles.din.refit_flag==0
if get(handles.dynamic_fit,'value')==1
save_shifts(handles,fg_values);
disp('Data saved!');
end%if get(handles.dynamic_fit,'value')==1
set(handles.status,'string','Status: Data saved! Ready...','backgroundcolor','k','foregroundcolor','r');
%//////////////////////////////////////////////////////////////////////////
%Update handles structure
for dum=1:2:11
name=['X',num2str(dum)];
prev_data=get(handles.(name),'userdata');
if isempty(prev_data)~=1
handles.din.(['GB_prev',num2str(dum)])=prev_data(1,:);
end%if isempty(prev_data)~=1
end%for dum=1:2:11
handles.din.n=n;
if mod(n,200)==0&&get(handles.email_push,'userdata')==1
email_send(handles,'Update notification sent by QCM MATLAB Program.');
end%if mod(n,200)==0
end%if str2double(get(handles.record_time_increment,'string'))>20
%//////////////////////////////////////////////////////////////////////////
if str2double(get(handles.record_time_increment,'string'))-toc>.1%this block of code deals with the waitbar that appears at the bottom of the GUI (timer in between scans)
if str2double(get(handles.record_time_increment,'string'))-toc>5
hold(handles.wb,'on');
wbh=barh(handles.wb,0,'facecolor',[0 0.5 0],'edgecolor','g','barwidth',1);
wbt=text(0.1,1,'test','parent',handles.wb,'color','w');
stop1=str2double(get(handles.record_time_increment,'string'));
set(handles.status,'string','Status: Pausing before next scan...','backgroundcolor','k','foregroundcolor','r');
for dum5=0:.1:stop1
if get(handles.start,'value')==1
pause(.1)
set(wbh,'ydata',dum5/stop1);
set(wbt,'string',[num2str(stop1-dum5,'%8.2f'),' s left']);
set(handles.wb,'xlim',[0 1],'box','off','color','k');
else
try delete(hp); catch; end;%try
end%if get(handles.start,'value')==1
end%for dum5=0:.8:str2double(get(handles.record_time_increment,'string'))
if handles.din.refit_flag==0
pause(mod(str2double(get(handles.record_time_increment,'string')),.8))
end%if handles.din.refit_flag==0
cla(handles.wb);
else
stop1=str2double(get(handles.record_time_increment,'string'));
for dum5=0:.1:stop1
if get(handles.start,'value')==1&&handles.din.refit_flag==0
pause(.1)
end%if get(handles.start,'value')==1
end%for dum5=0:.8:str2double(get(handles.record_time_increment,'string'))
if handles.din.refit_flag==0
pause(mod(str2double(get(handles.record_time_increment,'string')),.8))
end%if handles.din.refit_flag==0
end%if str2double(get(handles.record_time_increment,'string'))-toc>.1
end%if str2double(get(handles.record_time_increment,'string'))-toc>0.1
%//////////////////////////////////////////////////////////////////////////
if mod(n,50)>=50%clear up the command window every 50 datapoints
clc
end% if mod(n,100)>=50
end%while get(handles.start,'value')==1
%//////////////////////////////////////////////////////////////////////////
%Write out chi values, f0, and gamma0 into spectra file
disp('Saving Data...');
set(handles.status,'string','Status: Saving data...','backgroundcolor','k','foregroundcolor','r');
drawnow;
reference=char(get(handles.reference_time,'string'),get(handles.wait_time,'string')...
,get(handles.num_datapoints,'string'),get(handles.record_time_increment,'string'));%records reference time
fg_values.reference=reference;