-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbraveheart_gui.m
More file actions
6135 lines (4476 loc) · 225 KB
/
braveheart_gui.m
File metadata and controls
6135 lines (4476 loc) · 225 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BRAVEHEART - Open source software for electrocardiographic and vectorcardiographic analysis
% braveheart_gui.m -- BRAVEHEART GUI
% Copyright 2016-2025 Hans F. Stabenau and Jonathan W. Waks
%
% Source code/executables: https://github.com/BIVectors/BRAVEHEART
% Contact: braveheart.ecg@gmail.com
%
% BRAVEHEART 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.
%
% BRAVEHEART 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 <https://www.gnu.org/licenses/>.
%
% This software is for research purposes only and is not intended to diagnose or treat any disease.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = braveheart_gui(varargin)
% braveheart_gui MATLAB code for braveheart_gui.fig
% braveheart_gui, by itself, creates a new braveheart_gui or raises the existing
% singleton*.
%
% H = braveheart_gui returns the handle to a new braveheart_gui or the handle to
% the existing singleton*.
%
% braveheart_gui('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in braveheart_gui.M with the given input arguments.
%
% braveheart_gui('Property','Value',...) creates a new braveheart_gui or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before braveheart_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to braveheart_gui_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 braveheart_gui
% Last Modified by GUIDE v2.5 06-Feb-2026 12:39:52
% Update the current L&F for mac button issues...
% Windows will use the normal Windows theme
if ismac
%originalLnF = javax.swing.UIManager.getLookAndFeel;
%newLnF = 'com.sun.java.swing.plaf.windows.WindowsLookAndFeel';
newLnF = 'javax.swing.plaf.metal.MetalLookAndFeel'; % Makes buttons more consistent on mac
javax.swing.UIManager.setLookAndFeel(newLnF);
end
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @braveheart_gui_OpeningFcn, ...
'gui_OutputFcn', @braveheart_gui_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 braveheart_gui is made visible.
function braveheart_gui_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 braveheart_gui (see VARARGIN)
% Choose default command line output for braveheart_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Clear all axes
clear_axes(hObject,eventdata,handles);
% Supress warning about GUI
warning('off','MATLAB:hg:uicontrol:StringMustBeNonEmpty');
% Load BIDMC logo
axes(handles.logo_axis)
logo = imread ('logo_t.bmp');
imshow(logo);
% Disable update beat buttons
listbox_buttons_onoff('Off', hObject, eventdata, handles)
% Show tab1 (VCG) and hide other results tabs
set(handles.tab1,'visible','on')
set(handles.tab2,'visible','off')
set(handles.tab3,'visible','off')
set(handles.tab4,'visible','off')
set(handles.tab5,'visible','off')
% Load neural network for median beat annotation
load('MedianAnnoNet')
handles.MedianAnnoNet = MedianAnnoNet;
handles.meanTrain = meanTrain;
handles.stdTrain = stdTrain;
handles.standardizeFun = standardizeFun;
guidata(hObject, handles); % Save to handles.
% Link face and vcg axes
hlink = linkprop([handles.vcg_axis, handles.face_axis],{'CameraPosition','CameraUpVector'});
handles.hlink = hlink;
guidata(hObject, handles); % Save to handles.
% Load fiducial point presets from excel spreadsheed 'search_presets.csv'
% folder with the preset file will be in different location if running from .m file or from standalone .exe
% Add executable folder if running off shortcut
currentdir = getcurrentdir();
% Load fiducial point presets from csv 'search_presets.csv'
A = readcell(fullfile(currentdir,'search_presets.csv')); % read in data from .csv file
preset_names = A(2:size(A,1), 1);
preset_values = cell2mat(A(2:size(A,1), 2:size(A,2)));
set(handles.preset_fidpts, 'String', preset_names(1:length(preset_names(:,1)))); % load names of presets into dropdown
handles.preset_names = preset_names(1:length(preset_names(:,1)));
handles.preset_values = preset_values;
guidata(hObject, handles); % Save to handles.
% Load default Annoparams into GUI
aps = Annoparams();
push_guiparams(aps, hObject, eventdata, handles)
% Load ECG file format text presets from csv 'ecg_formats.csv'
A = read_format_csv(fullfile(currentdir,'ecg_formats.csv'));
handles.ecg_source_hash = A;
set(handles.ecg_source, 'String', A(:,1))
guidata(hObject, handles); % Save to handles
% Load transformation matrix string presets from csv 'transform_mats.csv'
A = readcell(fullfile(currentdir,'transform_mats.csv'));
set(handles.transform_mat_dropdown, 'String', A);
guidata(hObject, handles); % Save to handles
% Update GUI title bar/logo with version from AnnoResult
v = AnnoResult().version{1};
if isdeployed
set(hObject, 'Name',sprintf('BRAVEHEART GUI v%s - Compiled',v))
else
set(hObject, 'Name',sprintf('BRAVEHEART GUI v%s',v))
end
set(handles.version_txt,'String',sprintf('Version %s',v));
% Get current version of MATLAB to deal with graphics changes after R2025a
currentVersion = char(matlabRelease.Release);
currentVersion = str2double(currentVersion(2:5));
if currentVersion >= 2025
% Fix GUI due to R2025 changes
r2025_GUI(handles);
else
% Adjust GUI appearance if on Mac and before R2025
if ismac
changeGUIfont(handles);
end
end
% GPU data
gpu_count = gpuDeviceCount;
if gpu_count > 0
set(handles.gpu_txt,'String','GPU Detected');
else
set(handles.gpu_txt,'String','No GPU Detected');
set(handles.gpu_options,'Enable','Off')
set(handles.exec_env_txt1,'Enable','Off')
set(handles.exec_env_txt2,'Enable','Off')
end
% Show About Information regarding License etc
% (automatically updates version number)
about_popup();
% UIWAIT makes braveheart_gui wait for user response (see UIRESUME)
% uiwait(handles.braveheart_gui);
% --- Outputs from this function are returned to the command line.
function varargout = braveheart_gui_OutputFcn(hObject, eventdata, 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;
function filename_txt_Callback(hObject, eventdata, handles)
% hObject handle to filename_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of filename_txt as text
% str2double(get(hObject,'String')) returns contents of filename_txt as a double
% --- Executes during object creation, after setting all properties.
function filename_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to filename_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in load_button.
function load_button_Callback(hObject, eventdata, handles)
% hObject handle to load_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Load button opens a file dialogue box and parses the filename
% appropriately. It then calls reload_Callback which does all the actual
% ECG processing. Once the filename is loaded in the file text box you do
% not have to use Load again unless you want to change the ECG file
% Open file dialog box
[filename_short, pathname] = uigetfile('*.*','Select ECG file');
if filename_short==0 % user pressed cancel
return
end
% pathname is the directory the file is in
% filename_short is the actual file name and extension
% filename is the directory and filename/ext of ECG combined - displayed in GUI
filename = strcat(pathname, filename_short);
% Store filename and filename_short to handles for use in other callbacks
handles.filename = filename; % Entire directory and file
handles.filename_short = filename_short; % Just filename
handles.pathname = pathname; % Just firectory
guidata(hObject, handles); % Save to handles.
% Set filename as the filename string in GUI
set(handles.filename_txt, 'String', filename);
set(handles.save_dir_txt, 'String', pathname(1:end-1));
clear_axes(hObject, eventdata, handles);
% If 'Load Dir' checkbox checked will load directory file list
% Default to file 1/1
set(handles.file_num_txt,'String', '# 1 / 1');
if get(handles.load_dir_checkbox,'Value')
% Load in all files from directory
% Folder file stucture
[~,~,ext] = fileparts(filename);
file_list_struct = dir(fullfile(pathname, strcat('*',ext)));
name_list_struct = {file_list_struct.name}';
name_list_struct(ismember(name_list_struct, {'.', '..'})) = [];
% Load ECGs from directory
num_files = length(name_list_struct);
file_list = cell(num_files, 1);
for i = 1:num_files
file_list{i} = char(fullfile(pathname,name_list_struct(i)));
end
% Want to alphebetize the file list so things are consistent over time
file_list = sortrows(file_list);
% file_list is now a column vector with cells for each filename of the
% correct extension - note that some non ECG files may be in there too!
% Need to find the index of the currently loaded ECG file
ind = cellfun(@(s) ~isempty(strfind(filename, s)), file_list);
ind = find(ind == 1);
handles.file_index = ind;
handles.file_list = file_list;
guidata(hObject, handles); % Save to handles.
% Update file number text box
set(handles.file_num_txt,'String', sprintf('# %i / %i',ind,length(handles.file_list)));
set(handles.file_num_txt,'FontSize', 8);
if length(handles.file_list) <= 999
set(handles.file_num_txt,'FontSize', 9);
end
if length(handles.file_list) >= 10000
set(handles.file_num_txt,'FontSize', 7);
end
% Enable/disable prev/next ECG button based on index
if handles.file_index == 1
set(handles.load_prev_ecg_button,'Enable','off')
else
set(handles.load_prev_ecg_button,'Enable','on')
end
if handles.file_index == length(handles.file_list)
set(handles.load_next_ecg_button,'Enable','off')
else
set(handles.load_next_ecg_button,'Enable','on')
end
else
% Disable next/prev file buttons if didn't load the list of files
set(handles.load_prev_ecg_button,'Enable','off')
set(handles.load_next_ecg_button,'Enable','off')
% Put single file in file_list since Reload uses this structure
handles.file_index = 1;
handles.file_list = char(fullfile(pathname,filename));
guidata(hObject, handles); % Save to handles.
end
% Reload Callback
reload_Callback(hObject, eventdata, handles);
function freq_txt_Callback(hObject, eventdata, handles)
% hObject handle to freq_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of freq_txt as text
% str2double(get(hObject,'String')) returns contents of freq_txt as a double
% --- Executes during object creation, after setting all properties.
function freq_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to freq_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function unitspermv_txt_Callback(hObject, eventdata, handles)
% hObject handle to unitspermv_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of unitspermv_txt as text
% str2double(get(hObject,'String')) returns contents of unitspermv_txt as a double
% --- Executes during object creation, after setting all properties.
function unitspermv_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to unitspermv_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function ecg_source_CreateFcn(hObject, eventdata, handles)
% hObject handle to ecg_source (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in ecg_source.
function ecg_source_Callback(hObject, eventdata, handles)
% hObject handle to ecg_source (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns ecg_source contents as cell array
% contents{get(hObject,'Value')} returns selected item from ecg_source
% Update the expected frequency and filtering textboxies in GUI when change
% the ECG format dropdown
% Set ecg_string appropriately
strlist = get(handles.ecg_source, 'String');
handles.ecg_string = strlist{get(handles.ecg_source,'Value')};
% Obtain the format string (source_str) based on GUI dropbox
% source_str is passed into batch_calc/ECG12
[source_str, source_ext, source_freq] = ecg_source_string(handles.ecg_string,handles.ecg_source_hash);
handles.source_str = source_str;
handles.source_ext = source_ext;
guidata(hObject, handles); % Save to handles.
% Default wavelet filtering levels based on format chosen
[~, wavelet_level_selection_val, wavelet_level_selection_lf_val] = ...
ecg_source_gui(source_freq);
set(handles.wavelet_level_selection, 'Value', wavelet_level_selection_val);
set(handles.wavelet_level_selection_lf, 'Value', wavelet_level_selection_lf_val);
% --- Executes on button press in about_help_button.
function about_help_button_Callback(hObject, eventdata, handles)
% hObject handle to about_help_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Load new custom popup
about_popup();
% --- Executes on button press in y_markers.
function y_markers_Callback(hObject, eventdata, handles)
% hObject handle to y_markers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of y_markers
% --- Executes on button press in x_markers.
function x_markers_Callback(hObject, eventdata, handles)
% hObject handle to x_markers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of x_markers
% --- Executes on button press in z_markers.
function z_markers_Callback(hObject, eventdata, handles)
% hObject handle to z_markers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of z_markers
% --- Executes on button press in vm_markers.
function vm_markers_Callback(hObject, eventdata, handles)
% hObject handle to vm_markers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of vm_markers
% --- Executes on button press in majorgrid_checkbox.
function majorgrid_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to majorgrid_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of majorgrid_checkbox
% --- Executes on button press in minorgrid_checkbox.
function minorgrid_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to minorgrid_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of minorgrid_checkbox
% --- Executes on button press in save_12lead_checkbox.
function save_12lead_checkbox_Callback(hObject, eventdata, handles)
% hObject handle to save_12lead_checkbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of save_12lead_checkbox
% --- Executes on button press in view_12lead_button.
% hObject handle to view_12lead_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in view_12lead_button.
function view_12lead_button_Callback(hObject, eventdata, handles)
% hObject handle to view_12lead_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ecg = handles.ecg;
filename = handles.filename_short;
save_folder = get(handles.save_dir_txt,'String');
grid_options = get(handles.grid_popup,'Value');
switch grid_options
case 1
minorgrid = 1;
majorgrid = 1;
case 2
minorgrid = 0;
majorgrid = 1;
case 3
minorgrid = 1;
majorgrid = 0;
case 4
minorgrid = 0;
majorgrid = 0;
end
% Get colors based on if in light/dark mode
[dm, dark_colors, light_colors] = check_darkmode(handles);
if dm == 1
colors = dark_colors;
else
colors = light_colors;
end
view_12lead_ecg(ecg, filename, save_folder, 0, 0, majorgrid, minorgrid, colors);
function qon_txt_Callback(hObject, eventdata, handles)
% hObject handle to qon_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of qon_txt as text
% str2double(get(hObject,'String')) returns contents of qon_txt as a double
% --- Executes during object creation, after setting all properties.
function qon_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to qon_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function qrs_txt_Callback(hObject, eventdata, handles)
% hObject handle to qrs_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of qrs_txt as text
% str2double(get(hObject,'String')) returns contents of qrs_txt as a double
% --- Executes during object creation, after setting all properties.
function qrs_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to qrs_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function qoff_txt_Callback(hObject, eventdata, handles)
% hObject handle to qoff_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of qoff_txt as text
% str2double(get(hObject,'String')) returns contents of qoff_txt as a double
% --- Executes during object creation, after setting all properties.
function qoff_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to qoff_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tpeak_txt_Callback(hObject, eventdata, handles)
% hObject handle to tpeak_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of tpeak_txt as text
% str2double(get(hObject,'String')) returns contents of tpeak_txt as a double
% --- Executes during object creation, after setting all properties.
function tpeak_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to tpeak_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function tend_txt_Callback(hObject, eventdata, handles)
% hObject handle to tend_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of tend_txt as text
% str2double(get(hObject,'String')) returns contents of tend_txt as a double
% --- Executes during object creation, after setting all properties.
function tend_txt_CreateFcn(hObject, eventdata, handles)
% hObject handle to tend_txt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function maxbpm_Callback(hObject, eventdata, handles)
% hObject handle to maxbpm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of maxbpm as text
% str2double(get(hObject,'String')) returns contents of maxbpm as a double
% --- Executes during object creation, after setting all properties.
function maxbpm_CreateFcn(hObject, eventdata, handles)
% hObject handle to maxbpm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function rswidth_Callback(hObject, eventdata, handles)
% hObject handle to rswidth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rswidth as text
% str2double(get(hObject,'String')) returns contents of rswidth as a double
% --- Executes during object creation, after setting all properties.
function rswidth_CreateFcn(hObject, eventdata, handles)
% hObject handle to rswidth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function ststart_Callback(hObject, eventdata, handles)
% hObject handle to ststart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of ststart as text
% str2double(get(hObject,'String')) returns contents of ststart as a double
% --- Executes during object creation, after setting all properties.
function ststart_CreateFcn(hObject, eventdata, handles)
% hObject handle to ststart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function qrwidth_Callback(hObject, eventdata, handles)
% hObject handle to qrwidth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of qrwidth as text
% str2double(get(hObject,'String')) returns contents of qrwidth as a double
% --- Executes during object creation, after setting all properties.
function qrwidth_CreateFcn(hObject, eventdata, handles)
% hObject handle to qrwidth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function stend_Callback(hObject, eventdata, handles)
% hObject handle to stend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of stend as text
% str2double(get(hObject,'String')) returns contents of stend as a double
% --- Executes during object creation, after setting all properties.
function stend_CreateFcn(hObject, eventdata, handles)
% hObject handle to stend (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% hObject handle to calculate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject); % load in handles variables
% Update success visibility
set(handles.success_txt,'Visible','Off')
% Clear the GUI values
clear_GEH_calculations_GUI(hObject, eventdata, handles);
clear_beat_listbox_GUI(hObject, eventdata, handles)
% Set filenames for output
handles.csv_filename = handles.filename_short(1:end-4);
% Load VCG/ECG, QRS, and Annoparams
aps = pull_guiparams(hObject, eventdata, handles); % Pull from GUI and update based on what is selected
handles.aps = aps;
% Load Qualparams
qps = Qualparams();
% To avoid endless outlier and PVC deletion issue due to more freedom with the GUI,
% need to NOT remomove outliers and PVCs via batch_calc, and instead call
% the PVC removal and outlier removal Callbacks that are part of the GUI.
% Save values for aps.pvc_removal and aps.outlier_removal
temp_pvc_removal = aps.pvc_removal;
temp_outlier_removal = aps.outlier_removal;
% Disable PVC and outlier removal for this run of batch_calc
aps.pvc_removal = 0;
aps.outlier_removal = 0;
if aps.debug
figure(figure('name',' Annotation Fiducial Point Debug','numbertitle','off'));
hold off;
%plotind = min([15*handles.vcg.hz, 100000, length(handles.vcg.VM)]);
plot(handles.vcg.VM, 'Color', '[ 0 0.8 0]');
set(gcf, 'Position', [100, 800, 1400, 300]) % set figure size
hold on;
end
% Run batch_calc
% This time dont recalc HR as this wont change
batchout = batch_calc(handles.ecg_raw, [], [], [], [], [], aps, qps, 0, "", []);
handles.beats = batchout.beats_final;
handles.quality = batchout.quality;
handles.correlation_test = batchout.correlation_test;
handles.median_vcg = batchout.medianvcg1;
handles.beatsig_vcg = batchout.beatsig_vcg;
handles.median_12L = batchout.median_12L;
handles.beatsig_12L = batchout.beatsig_12L;
handles.medianbeat = batchout.medianbeat;
handles.beat_stats = batchout.beat_stats;
handles.ecg_raw = batchout.ecg_raw;
handles.vcg_raw = batchout.vcg_raw;
handles.ecg = batchout.filtered_ecg;
handles.vcg = batchout.filtered_vcg;
handles.pacer_spikes = batchout.pacer_spikes;
handles.lead_ispaced = batchout.lead_ispaced;
handles.noise = batchout.noise;
handles.ecg_raw_postinterp = batchout.ecg_raw_postinterp;
% Get flags for processing different modules
vcg_calc_flag = get(handles.geh_option_checkbox,'Value');
lead_morph_flag = get(handles.lead_morphology_option_checkbox,'Value');
vcg_morph_flag = get(handles.vcg_morphology_option_checkbox,'Value');
% Create flags structure
flags = struct;
flags.vcg_calc_flag = vcg_calc_flag;
flags.lead_morph_flag = lead_morph_flag;
flags.vcg_morph_flag = vcg_morph_flag;
[handles.geh, handles.lead_morph, handles.vcg_morph] = module_output(handles.median_12L, handles.median_vcg, handles.medianbeat, aps, flags);
% Set PVC and outlier removal values back to what they were
% handles.aps is not affected by this.
aps.pvc_removal = temp_pvc_removal;
aps.outlier_removal = temp_outlier_removal;
% Update handles structure
guidata(hObject, handles);
% Finds outliers
handles.beats = handles.beats.find_outliers(handles.vcg,aps);
guidata(hObject, handles); % update handles
% Finds PVCs
handles.beats = handles.beats.find_pvcs(handles.vcg,handles.aps);
guidata(hObject, handles); % update handles
% Runs calc_plot to update the GUI
calc_plot(handles.vcg, handles.beats, handles.aps, hObject, eventdata, handles);
guidata(hObject, handles); % update handles
% disable rotation so can move lines to reannotate in selected beat viewer
rotate3d off
% Excecute PVC removal automatically if checkbox clicked
if get(handles.auto_pvc_removal_checkbox, 'Value') == 1
pvc_button_Callback(hObject, eventdata, handles);
handles = guidata(hObject);
end
% Execute outlier removal automatically if checkbox clicked
if get(handles.auto_remove_outliers_checkbox, 'Value') == 1
remove_outliers_button_Callback(hObject, eventdata, handles);
handles = guidata(hObject);
end
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Load default Annoparams
aps = Annoparams();
% Push default Annoparams to update GUI dropdowns/checkboxes
push_guiparams(aps, hObject, eventdata, handles)
% Toggle fields that activate/deactivate based on checkboxes
autocl_checkbox_Callback(hObject, eventdata, handles)
set(handles.preset_fidpts,'Value',1);
set(handles.ststart, 'Enable', 'on');
set(handles.stend, 'Enable', 'on');
set(handles.preset_fidpts, 'Enable', 'on');
set(handles.pacing_pkwidth_txt, 'Enable', 'on');
set(handles.pacing_thresh_txt, 'Enable', 'on');
set(handles.align_dropdown, 'Enable', 'on');
set(handles.tend_method_dropdown, 'Enable', 'on');
set(handles.autocl_checkbox, 'Enable', 'on');
% set(handles.cwt_pacing_remove_box, 'Enable', 'on');
% set(handles.spike_removal_old_checkbox, 'Enable', 'on');
% set(handles.all_auto_checkbox, 'Value', 1);
% set(handles.pacer_interpolation_button,'enable','on');
% set(handles.pacing_pkwidth_txt,'enable', 'on');
% set(handles.pacing_thresh_txt,'enable', 'on');
% set(handles.pacer_zpk_txtbox, 'enable', 'on');
% set(handles.pacer_zcut_txtbox, 'enable', 'on');
% set(handles.pacer_maxscale_txtbox, 'enable', 'on');
% set(handles.pacer_num_leads_txtbox, 'enable','on');
if aps.keep_pvc == 0
set(handles.pvc_button, 'String', 'Remove PVCs')
else
set(handles.pvc_button, 'String', 'Remove Native')
end
% Update handles structure
guidata(hObject, handles);
% Adjust spike removal fields being enabled or not
if get(handles.cwt_pacing_remove_box, 'Value') == 1
set(handles.spike_removal_old_checkbox,'value',0);
set(handles.pacer_interpolation_button,'enable','on');
set(handles.pacing_pkwidth_txt,'enable', 'off');
set(handles.pacing_thresh_txt,'enable', 'off');
set(handles.pacer_zpk_txtbox, 'enable', 'on');
set(handles.pacer_zcut_txtbox, 'enable', 'on');
set(handles.pacer_maxscale_txtbox, 'enable', 'on');
set(handles.pacer_num_leads_txtbox, 'enable','on');
else
set(handles.pacer_interpolation_button,'enable','off');
set(handles.pacing_pkwidth_txt,'enable', 'on');
set(handles.pacing_thresh_txt,'enable', 'on');
set(handles.pacer_zpk_txtbox, 'enable', 'off');
set(handles.pacer_zcut_txtbox, 'enable', 'off');
set(handles.pacer_maxscale_txtbox, 'enable', 'off');
set(handles.pacer_num_leads_txtbox, 'enable','off');
end
% --- Executes on selection change in activebeats_list.
function activebeats_list_Callback(hObject, eventdata, handles)
% hObject handle to activebeats_list (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns activebeats_list contents as cell array
% contents{get(hObject,'Value')} returns selected item from activebeats_list
% Pulls the selected beat into the edit beat text box and then displays the
% selected beat with current fiducial points
% Get colors based on if in light/dark mode
[dm, dark_colors, light_colors] = check_darkmode(handles);
if dm == 1
colors = dark_colors;
else
colors = light_colors;
end
handles = guidata(hObject); % load handles variables
% Disable rotation so can move lines to reannotate in selected beat viewer
rotate3d off
vcg = handles.vcg;
beatsig_vcg = handles.beatsig_vcg;
beats = handles.beats;
aps = pull_guiparams(hObject, eventdata, handles);
beatmatrix = beats.beatmatrix();
beatsigx = beatsig_vcg.X;