-
Notifications
You must be signed in to change notification settings - Fork 0
/
hera.m
2274 lines (1668 loc) · 85.2 KB
/
hera.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
%----------------------------------------------------------------
%HERA: Heart Rate Analysis v0.07 beta April 2020
%
%(c) 2008-2020 Erno Hermans & Thijs vd Laar
%----------------------------------------------------------------
%v0.02: fixed check for wavelet manager
% fixed use of nanmean (statistics toolbox): replaced by selfmade
%v0.03: fixed samplerate error on line 364 (read SR from file, not
% defaults) 20110303 EJH
%v0.04: Added marker channel to visualize scanner triggers,
% eg for Brainamp converted files. (20130310)
%v0.05: Changed behavior of peak correction. Now puts in and removes peaks
% at the center of the figure, and does so much faster.
%v0.06: Added transparency to the red rectangles that indicate
% the rejection period.
%v0.07: Added root median square of successive differences (rMedSSD) as a
% potentially more robust measure of HRV. Updated "collect for output
% to work also with incomplete data.
%v0.08: Replaced root median square of successive differences by root
% truncated mean of successive differences (rtMSSD), because the low sampling
% frequency caused the median to jump.
function varargout = hera(varargin)
% HERA M-file for hera.fig
% HERA, by itself, creates a new HERA or raises the existing
% singleton*.
%
% H = HERA returns the handle to a new HERA or the handle to
% the existing singleton*.
%
% HERA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HERA.M with the given input arguments.
%
% HERA('Property','Value',...) creates a new HERA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hera_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hera_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 hera
% Last Modified by GUIDE v2.5 02-Jun-2020 19:27:34
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hera_OpeningFcn, ...
'gui_OutputFcn', @hera_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 hera is made visible.
function hera_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 hera (see VARARGIN)
% Choose default command line output for hera
handles.output = hObject;
%------------------------------------------------------------------------
%Enter variables that need to be shared by subs and put them in "handles"
%------------------------------------------------------------------------
%Load Defaults
hera_defaults;
handles.hera_def=hera_def; %these are default settings
handles.currentfile.matfile.settings = handles.hera_def; %current settings
handles.currentfile.open = false; %currently no file open
handles.currentfile.saved = true;
clear hera_def;
%Check if complex wavelet (cmrl) has been added in wavemanager
cwavs = wavemngr('read');
cwavs = cwavs';
if isempty(strfind(cwavs(:)','cmrl'))
%Add complex wavelet toolbox
wavemngr('add', 'CMorlet', 'cmrl', 5, '', 'cmorwavf', [-3, 3]);
end
%Empty the matfile structure
handles = emptyMatfile(handles);
handles = drawgui(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hera wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hera_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;
%----------------------------------------------------------------
%Open a file
%----------------------------------------------------------------
% --- Executes on button press in hera_openfile.
function hera_openfile_Callback(hObject, eventdata, handles)
% hObject handle to hera_openfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~handles.currentfile.saved & handles.currentfile.open
%Give a warning if current file has not been saved
answ=questdlg('Current datafile has not been saved. Continue?');
if isempty(strmatch('Yes',answ))
%User cancelled, go back to gui
return
end
end
%Open a dialog box for opening a file
[pulsfilename,pulsdir,nocancel]=uigetfile({['*.',handles.hera_def.pulsefile_extension,';*.',upper(handles.hera_def.pulsefile_extension)],'Pulse files'},'Please specify the ".puls" file to work on.');
%If user pushes cancel, go back to gui
if ~nocancel
return
end
%Empty possible current matfile structure
handles = emptyMatfile(handles);
%Load the pulse file: only read the first line of the file and convert to
%a vector
fid = fopen(fullfile(pulsdir,pulsfilename));
pulsfile = fread(fid);
%Find end of lines (ascii 13, 10)
eol = find((pulsfile(1:end-1)==13) & pulsfile(2:end)==10);
if numel(eol)>0
eol = eol(1);
pulsfile = pulsfile(1:eol-1);
end
%Now convert to numerical
handles.currentfile.pulsfile = str2num(char(pulsfile'));
handles.currentfile.pulsdir = pulsdir;
handles.currentfile.pulsfilename =pulsfilename;
handles.currentfile.open = true;
%Copy the pulsfile to the matfile (will later be edited)
handles.currentfile.matfile.rawpulsedata = handles.currentfile.pulsfile;
%Check if there already is a '.mat' file associated with this file.
%if so, load it.
extloc = strfind(handles.currentfile.pulsfilename,['.',handles.hera_def.pulsefile_extension]);
handles.currentfile.matfilename = [handles.currentfile.pulsfilename(1:extloc(length(extloc))),'mat'];
if exist(fullfile(handles.currentfile.pulsdir,handles.currentfile.matfilename))
%Load the matfile and put it in the handles structure
matfile = load(fullfile(handles.currentfile.pulsdir,handles.currentfile.matfilename));
handles.currentfile.matfile = matfile.matfile;
else
%Perform the first simple calculations on the pulse data
%in case a pre-peak setting is present, use this to make an
%ibichannel based on existing peak detection
if handles.hera_def.prepeak > 0
prepeakbool = handles.currentfile.matfile.rawpulsedata==handles.hera_def.prepeak;
prepeaklocs = find(prepeakbool);
if ~isempty(prepeaklocs)
%Correct for Siemens-inserted sample points per peak
prepeaklocs = prepeaklocs - [0:length(prepeaklocs)-1];
%Correct for peak detection delay in Siemens scanner data,
%according to setting in defaults
prepeaklocs = prepeaklocs - handles.hera_def.prepeakdelay;
%Store the pre-peak locations for later use
handles.currentfile.matfile.prepeaklocs = prepeaklocs;
%Now delete all peaks from the pulse data
handles.currentfile.matfile.rawpulsedata = ...
handles.currentfile.matfile.rawpulsedata(~prepeakbool);
%Loop over all peaks, if any, and delete all the peaks from the raw
%data
% if ~isempty(prepeaklocs)
% for cpeak = 1:length(prepeaklocs)
%Interpolate the datapoint
% if prepeaklocs(cpeak) >1 & prepeaklocs(cpeak)<length(handles.currentfile.matfile.rawpulsedata)
%Simply interpolate from neighbors
% handles.currentfile.matfile.rawpulsedata(prepeaklocs(cpeak)) = mean ([...
% handles.currentfile.matfile.rawpulsedata(prepeaklocs(cpeak)-1), ...
% handles.currentfile.matfile.rawpulsedata(prepeaklocs(cpeak)+1)]);
% elseif prepeaklocs(cpeak) ==1
%If it's the first datapoint, copy the second
% handles.currentfile.matfile.rawpulsedata(1) = handles.currentfile.matfile.rawpulsedata(2);
% elseif prepeaklocs(cpeak) == length(handles.currentfile.matfile.rawpulsedata)
%If it's the last datapoint, copy the previous
% handles.currentfile.matfile.rawpulsedata(length(handles.currentfile.matfile.rawpulsedata)) = ...
% handles.currentfile.matfile.rawpulsedata(length(handles.currentfile.matfile.rawpulsedata)-1);
% end
% end
%Now filter the data according to the filter settings, in
%this case the default settings because no file is open
handles.currentfile.matfile.bpf_pulsedata = ...
hera_bpf(handles.currentfile.matfile.rawpulsedata, ...
handles.currentfile.matfile.settings.samplerate, ...
handles.currentfile.matfile.settings.hpd, ...
handles.currentfile.matfile.settings.lpd);
%Define time-axis
handles.currentfile.matfile.sampleTime = ...
(1/handles.currentfile.matfile.settings.samplerate) * ...
(0:length(handles.currentfile.matfile.bpf_pulsedata) - 1);
%Determine the time (in sec) at which beats were detected
handles.currentfile.matfile.prepeakTimes = ...
handles.currentfile.matfile.sampleTime(prepeaklocs);
%Call other function to calculate IBI timeseries and channels
handles = CalcIBIs(handles);
%Calculate rMSSD and BPM measures, use BPM as pre-setting for
%wavelet peak tracing.
handles = CalcPreOutMeasures(handles);
end
end
end
handles = drawgui(handles);
guidata(hObject, handles);
%----------------------------------------------------------------
%Save a file
%----------------------------------------------------------------
% --- Executes on button press in hera_save.
function hera_save_Callback(hObject, eventdata, handles)
% hObject handle to hera_save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Check if there is a datafile open
if handles.currentfile.open
%Save everything in the matfile structure
matfile = handles.currentfile.matfile;
save(fullfile(handles.currentfile.pulsdir,handles.currentfile.matfilename),'matfile');
handles.currentfile.saved = true;
else
msgbox('No file has been opened. Nothing to save.');
return
end
guidata(hObject, handles);
%----------------------------------------------------------------
%Draw the GUI
%----------------------------------------------------------------
function handles = drawgui(handles)
%Calculate BPM/rMSSD measures
handles = CalcIBIs(handles);
handles = CalcPreOutMeasures(handles);
%Fill in all settings/results fields; these fields contain defaults
%when no file is open (or are empty)
set(handles.hera_lowpassfilter, 'String',handles.currentfile.matfile.settings.lpd);
set(handles.hera_highpassfilter, 'String',handles.currentfile.matfile.settings.hpd);
set(handles.hera_avgHeartbeat, 'String',handles.currentfile.matfile.settings.avgHeartbeat);
set(handles.hera_ballmobilityrange, 'String',handles.currentfile.matfile.settings.ballmobilityrange);
set(handles.hera_startCutout, 'String',handles.currentfile.matfile.settings.startCutout);
set(handles.hera_endCutout, 'String',handles.currentfile.matfile.settings.endCutout);
set(handles.hera_lowerboundLF, 'String',handles.currentfile.matfile.settings.lowerboundLF);
set(handles.hera_upperboundLF, 'String',handles.currentfile.matfile.settings.upperboundLF);
set(handles.hera_lowerboundHF, 'String',handles.currentfile.matfile.settings.lowerboundHF);
set(handles.hera_upperboundHF, 'String',handles.currentfile.matfile.settings.upperboundHF);
set(handles.hera_preBPM, 'String',handles.currentfile.matfile.outmeasures.preBPM);
set(handles.hera_prerMSSD, 'String',handles.currentfile.matfile.outmeasures.rMSSD);
set(handles.hera_prertMSSD, 'String',handles.currentfile.matfile.outmeasures.rtMSSD);
set(handles.hera_postBPM, 'String',handles.currentfile.matfile.outmeasures.postBPM);
set(handles.hera_LFHFrat, 'String',handles.currentfile.matfile.outmeasures.LFHFratio);
set(handles.hera_LFpower, 'String',handles.currentfile.matfile.outmeasures.LFPower);
set(handles.hera_HFpower, 'String',handles.currentfile.matfile.outmeasures.HFPower);
%Ylabel X popsition
Ylx = -15;
%Reset progress bar
cposition = get(handles.hera_redprogressbar,'Position');
cposition(3) = 0.001;
set(handles.hera_redprogressbar,'Position',cposition);
%Reset the progress bar text
set(handles.hera_progressbartext,'String','');
%Draw the raw data
if handles.currentfile.open
%Set the filename
set(handles.figure1,'Name',['HeRA - ',handles.currentfile.pulsfilename]);
%Select upper graph
set(gcf,'CurrentAxes',handles.axes1);
%If there's a pre-IBIchannel, plot in upper graph
if ~isempty(handles.currentfile.matfile.preibichannel)
%Rescale the pulsfile to fit in the same graph as the IBI channel
minibi = min(handles.currentfile.matfile.preibichannel);
maxibi = max(handles.currentfile.matfile.preibichannel);
%20130316: set max to 2000 if artefacts are in the data
if maxibi>2000
maxibi=2000;
end
%Rescale the band pass filtered pulsefile
rspulsfile = handles.currentfile.matfile.bpf_pulsedata;
rspulsfile = rspulsfile.*((maxibi-minibi)/(max(rspulsfile) - min(rspulsfile)));
rspulsfile = rspulsfile - min(rspulsfile);
rspulsfile = rspulsfile + minibi;
xaxis = ((1:length(rspulsfile))-1)./handles.currentfile.matfile.settings.samplerate; %20110303 changed to samplerate read from the file
%Keep the x axis (20130316)
handles.xaxis = xaxis;
cYLim = [minibi-((maxibi-minibi)*.05),maxibi+((maxibi-minibi)*.05)];
%Store the X limits so zooming can be checked later
handles.currentfile.matfile.prepulsezoom = get(handles.axes1,'XLim');
%20130316: should this be done later?
plot(xaxis,rspulsfile,'k','linewidth',1)
%Align Y axis labels
% ylpos = get(get(handles.axes1,'YLabel'),'Position');
% ylpos(1) = Ylx;
% set(get(handles.axes1,'YLabel'),'Position',ylpos);
hold on
%Draw in detected peaks
handles.plothandle_peaks=[];
for peak = 1:length(handles.currentfile.matfile.prepeakTimes)
%Draw in vertical lines at peaks
xPos = handles.currentfile.matfile.prepeakTimes(peak);
%20130316: Keep handles to peaks in the figure
handles.plothandle_peaks(peak) = ...
plot([xPos,xPos],cYLim,'Color',[.8,.8,.8],'linewidth',.5);
end
%Draw in marker channel if present (added 20130310)
if isfield(handles.currentfile.matfile,'markerlocs')
markerYLim = [cYLim(1),cYLim(1)+((cYLim(2)-cYLim(1))/40)];
for cmarkerloc=1:numel(handles.currentfile.matfile.markerlocs)
xPos = handles.currentfile.matfile.markerlocs(cmarkerloc)/...
handles.currentfile.matfile.settings.samplerate;
plot([xPos,xPos],markerYLim,'Color',[.5,.5,1],'linewidth',4)
end
end
handles.plothandle_rspulsfile = plot(xaxis,rspulsfile,'k','linewidth',1);
%Added 20131316: keep a handle to the preibichannel trace in the
%plot so that it can be redrawn more easily
handles.plothandle_preibichannel = plot(xaxis,handles.currentfile.matfile.preibichannel,'r','linewidth',1);
set(get(gcf,'CurrentAxes'),'YLim',cYLim);
% %added 20130316: return to previous zoom if available (EJH)
% if isfield(handles,'keepzoom') && numel(handles.keepzoom)>0
% set(get(gcf,'CurrentAxes'),'XLim',handles.keepzoom(1,:));
% set(get(gcf,'CurrentAxes'),'YLim',handles.keepzoom(2,:));
% handles.keepzoom=[];
% else
% set(get(gcf,'CurrentAxes'),'YLim',cYLim);
% end
%Draw in rejected areas
handles.plothandle_rejected=[];
for rej = 1:length(handles.currentfile.matfile.prereject)
%Draw in a rectangle to indicate rejection
crej = handles.currentfile.matfile.prereject{rej};
%20180201: added transparency to the red rectangles that indicate
%the rejection period.
handles.plothandle_rejected(rej) = ...
patch(...
[crej(1) ,crej(2) ,crej(2) , crej(1)],...
[cYLim(1),cYLim(1),cYLim(2),cYLim(2)],...
[1,.7,.7]);
set(handles.plothandle_rejected(rej),'FaceAlpha',.5);
set(handles.plothandle_rejected(rej),'LineStyle','none');
%old: using a rectangle which cannot be transparent:
% handles.plothandle_rejected(rej) = ...
% rectangle('Position',...
% [crej(1),cYLim(1),crej(2)-crej(1),cYLim(2)-cYLim(1)]);
% set(handles.plothandle_rejected(rej),'FaceColor',[1,.7,.7]);
% set(handles.plothandle_rejected(rej),'LineStyle','none');
%old: Draw in red vertical lines in rejected period
%crej = handles.currentfile.matfile.prereject{rej};
%for xPos = crej(1):.04:crej(2)
% plot([xPos,xPos],cYLim,'Color',[1,.7,.7])
%end
end
hold off
xlabel('Time(s)'), ylabel('InterBeat Interval(ms)')
else
%Rescale the raw pulsefile to 0-100
rspulsfile = handles.currentfile.matfile.bpf_pulsedata;
rspulsfile = rspulsfile.*(100/(max(rspulsfile) - min(rspulsfile)));
rspulsfile = rspulsfile - min(rspulsfile);
plot(handles.currentfile.matfile.sampleTime,rspulsfile,'k','linewidth',1.5)
end
%If there's a wavelet transform available, draw it
if ~isempty(handles.currentfile.matfile.CWT)
set(gcf,'CurrentAxes',handles.axes2);
imagesc(handles.currentfile.matfile.sampleTime, ... %Plot CWT against frequency and time
handles.currentfile.matfile.scalFreq, ...
handles.currentfile.matfile.CWT)
xlabel('Time(s)'), ylabel('Frequency(Hz)'); %Proper labeling
%Align Y axis labels
% ylpos = get(get(handles.axes2,'YLabel'),'Position');
% ylpos(1) = Ylx;
% set(get(handles.axes2,'YLabel'),'Position',ylpos);
else
set(gcf,'CurrentAxes',handles.axes2);
cla
end
%If there's a top-trace available, draw it in
if ~isempty(handles.currentfile.matfile.topTrace)
hold on
plot(handles.currentfile.matfile.sampleTime, ...
handles.currentfile.matfile.topTrace, 'k');
hold off
xlabel('Time(s)'), ylabel('Frequency(Hz)'); %Proper labeling
end
if ~isempty(handles.currentfile.matfile.spectrumPower)
startFreqIndex = round(handles.currentfile.matfile.lowerboundLFIndex - (handles.currentfile.matfile.upperboundHFIndex - handles.currentfile.matfile.lowerboundLFIndex)*.1);
if startFreqIndex<1; startFreqIndex = 1; end
endFreqIndex = round(handles.currentfile.matfile.upperboundHFIndex + (handles.currentfile.matfile.upperboundHFIndex - handles.currentfile.matfile.lowerboundLFIndex)*.1);
if endFreqIndex>length(handles.currentfile.matfile.spectrumFrequencies)
endFreqIndex = length(handles.currentfile.matfile.spectrumFrequencies);
end
sF = handles.currentfile.matfile.spectrumFrequencies(startFreqIndex:endFreqIndex);
sP = handles.currentfile.matfile.spectrumPower(startFreqIndex:endFreqIndex);
set(gcf,'CurrentAxes',handles.axes3);
plot(sF, sP,'k','linewidth',2)
%Align Y axis labels
% ylpos = get(get(handles.axes3,'YLabel'),'Position');
% ylpos(1) = -.049;
% set(get(handles.axes3,'YLabel'),'Position',ylpos);
%Put in lines to see LF and HF boundaries
lLF = handles.currentfile.matfile.settings.lowerboundLF;
uLF = handles.currentfile.matfile.settings.upperboundLF;
lHF = handles.currentfile.matfile.settings.lowerboundHF;
uHF = handles.currentfile.matfile.settings.upperboundHF;
cYLim = get(handles.axes3,'YLim');
hold on
for xPos = lLF:.001:uLF
plot([xPos,xPos],cYLim,'Color',[.7,.7,1])
end
for xPos = lHF:.001:uHF
plot([xPos,xPos],cYLim,'Color',[.7,1,.7])
end
plot(sF, sP,'k','linewidth',2)
hold off
xlabel('Frequency(Hz)'), ylabel('Power spectral density (W/Hz)');
end
else %if no file open, clear all graphs
%Select graphs and clear
set(gcf,'CurrentAxes',handles.axes1);
cla
set(gcf,'CurrentAxes',handles.axes2);
cla
set(gcf,'CurrentAxes',handles.axes3);
cla
end
%----------------------------------------------------------------
%Close a file
%----------------------------------------------------------------
% --- Executes on button press in hera_closefile.
function hera_closefile_Callback(hObject, eventdata, handles)
% hObject handle to hera_closefile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Check if there is a datafile open
if handles.currentfile.open
%Check if file has been saved
if ~handles.currentfile.saved
%Give a warning if current file has not been saved
answ=questdlg('Current datafile has not been saved. Continue?');
if isempty(strmatch('Yes',answ))
%User cancelled, go back to gui
return
end
end
%Close the file and redraw
handles.currentfile.open = false;
handles = emptyMatfile(handles);
set(handles.figure1,'Name','HeRA');
handles = drawgui(handles);
guidata(hObject, handles);
end
%----------------------------------------------------------------
%Close a file and clear/delete the matfile
%----------------------------------------------------------------
% --- Executes on button press in hera_clearmatfile.
function hera_clearmatfile_Callback(hObject, eventdata, handles)
% hObject handle to hera_clearmatfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Only do something if a file is open
if handles.currentfile.open
answ = questdlg('This will delete all changes, calculations, and the ".mat"-file of the currently opened file, and then close it. Are you sure?');
if ~strmatch(answ,'Yes')
return
end
%Close the file and delete the mat-file
handles.currentfile.open = false;
handles = emptyMatfile(handles);
%Delete the matfile
warning off;
delete(handles.currentfile.matfilename);
warning on;
set(handles.figure1,'Name','HeRA');
handles = drawgui(handles);
guidata(hObject, handles);
end
%---------------------------------------------------
%Emptymatfile: create the empty matfile structure
function handles = emptyMatfile(handles)
handles.currentfile.matfile.settings = handles.hera_def; %go back to default settings
handles.currentfile.matfile.rawpulsedata = [];
handles.currentfile.matfile.preibitimeseries = [];
handles.currentfile.matfile.preibichannel = [];
handles.currentfile.matfile.prepeaklocs = [];
handles.currentfile.matfile.prepeakTimes = [];
handles.currentfile.matfile.prereject = [];
handles.currentfile.matfile.prepulsezoom = [];
handles.currentfile.matfile.postibichannel = [];
handles.currentfile.matfile.sampleTime = [];
handles.currentfile.matfile.scalFreq = [];
handles.currentfile.matfile.aBin = [];
handles.currentfile.matfile.CWT = [];
handles.currentfile.matfile.topTrace = [];
handles.currentfile.matfile.bpf_pulsedata = [];
handles.currentfile.matfile.spectrumFrequencies = [];
handles.currentfile.matfile.spectrumPower = [];
handles.currentfile.matfile.lowerboundLFIndex = [];
handles.currentfile.matfile.upperboundLFIndex = [];
handles.currentfile.matfile.lowerboundHFIndex = [];
handles.currentfile.matfile.upperboundHFIndex = [];
handles.currentfile.matfile.outmeasures.preBPM = [];
handles.currentfile.matfile.outmeasures.rMSSD = [];
handles.currentfile.matfile.outmeasures.rtMSSD = [];
handles.currentfile.matfile.outmeasures.LFPower = [];
handles.currentfile.matfile.outmeasures.HFPower = [];
handles.currentfile.matfile.outmeasures.LFHFratio = [];
handles.currentfile.matfile.outmeasures.postBPM = [];
%---------------------------------------------------
%------------------------------------------------------------------
%Change initial low pass filter
%------------------------------------------------------------------
function hera_lowpassfilter_Callback(hObject, eventdata, handles)
% hObject handle to hera_lowpassfilter (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 hera_lowpassfilter as text
% str2double(get(hObject,'String')) returns contents of hera_lowpassfilter as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_lowpassfilter, 'String',handles.currentfile.matfile.settings.lpd);
return
end
cset = get(handles.hera_lowpassfilter, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.lpd = str2num(cset);
%Refilter the raw pulse data
handles.currentfile.matfile.bpf_pulsedata = ...
hera_bpf(handles.currentfile.matfile.rawpulsedata, ...
handles.currentfile.matfile.settings.samplerate, ...
handles.currentfile.matfile.settings.hpd, ...
handles.currentfile.matfile.settings.lpd);
%Redraw the GUI
handles = drawgui(handles);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_lowpassfilter, 'String',handles.currentfile.matfile.settings.lpd);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_lowpassfilter_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_lowpassfilter (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
%------------------------------------------------------------------
%Change initial high pass filter
%------------------------------------------------------------------
function hera_highpassfilter_Callback(hObject, eventdata, handles)
% hObject handle to hera_highpassfilter (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 hera_highpassfilter as text
% str2double(get(hObject,'String')) returns contents of hera_highpassfilter as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_highpassfilter, 'String',handles.currentfile.matfile.settings.hpd);
return
end
cset = get(handles.hera_highpassfilter, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.hpd = str2num(cset);
%Refilter the raw pulse data
handles.currentfile.matfile.bpf_pulsedata = ...
hera_bpf(handles.currentfile.matfile.rawpulsedata, ...
handles.currentfile.matfile.settings.samplerate, ...
handles.currentfile.matfile.settings.hpd, ...
handles.currentfile.matfile.settings.lpd);
%Redraw the GUI
handles = drawgui(handles);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_highpassfilter, 'String',handles.currentfile.matfile.settings.hpd);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_highpassfilter_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_highpassfilter (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
%------------------------------------------------------------------
%Change average heartbeat setting
%------------------------------------------------------------------
function hera_avgHeartbeat_Callback(hObject, eventdata, handles)
% hObject handle to hera_avgHeartbeat (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 hera_avgHeartbeat as text
% str2double(get(hObject,'String')) returns contents of hera_avgHeartbeat as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_avgHeartbeat, 'String',handles.currentfile.matfile.settings.avgHeartbeat);
return
end
cset = get(handles.hera_avgHeartbeat, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.avgHeartbeat = str2num(cset);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_avgHeartbeat, 'String',handles.currentfile.matfile.settings.avgHeartbeat);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_avgHeartbeat_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_avgHeartbeat (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
%------------------------------------------------------------------
%Change ball mobility range setting
%------------------------------------------------------------------
function hera_ballmobilityrange_Callback(hObject, eventdata, handles)
% hObject handle to hera_ballmobilityrange (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 hera_ballmobilityrange as text
% str2double(get(hObject,'String')) returns contents of hera_ballmobilityrange as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_ballmobilityrange, 'String',handles.currentfile.matfile.settings.ballmobilityrange);
return
end
cset = get(handles.hera_ballmobilityrange, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.ballmobilityrange = str2num(cset);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_ballmobilityrange, 'String',handles.currentfile.matfile.settings.ballmobilityrange);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_ballmobilityrange_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_ballmobilityrange (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
%------------------------------------------------------------------
%Change start cutout setting
%------------------------------------------------------------------
function hera_startCutout_Callback(hObject, eventdata, handles)
% hObject handle to hera_startCutout (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 hera_startCutout as text
% str2double(get(hObject,'String')) returns contents of hera_startCutout as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_startCutout, 'String',handles.currentfile.matfile.settings.startCutout);
return
end
cset = get(handles.hera_startCutout, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.startCutout = str2num(cset);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_startCutout, 'String',handles.currentfile.matfile.settings.startCutout);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_startCutout_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_startCutout (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
%------------------------------------------------------------------
%Change end cutout setting
%------------------------------------------------------------------
function hera_endCutout_Callback(hObject, eventdata, handles)
% hObject handle to hera_endCutout (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 hera_endCutout as text
% str2double(get(hObject,'String')) returns contents of hera_endCutout as a double
if ~handles.currentfile.open
msgbox('No file has been opened. Cannot change this setting now.')
set(handles.hera_endCutout, 'String',handles.currentfile.matfile.settings.endCutout);
return
end
cset = get(handles.hera_endCutout, 'String');
if ~isempty(str2num(cset))
%Set the filter setting in the matfile
handles.currentfile.matfile.settings.endCutout = str2num(cset);
%Set the saved setting to "no" to avoid losing changes
handles.currentfile.saved = false;
else
msgbox('Invalid setting. Value set back to previous setting.')
set(handles.hera_endCutout, 'String',handles.currentfile.matfile.settings.endCutout);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function hera_endCutout_CreateFcn(hObject, eventdata, handles)
% hObject handle to hera_endCutout (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