-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathcrossf.m
1457 lines (1345 loc) · 58.5 KB
/
crossf.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
% CROSSF - Returns estimates and plots event-related coherence (ERCOH)
% between two input data time series (X,Y). A lower panel (optionally)
% shows the coherence phase difference between the processes.
% In this panel, output by > crossf(X,Y,...);
% 90 degrees (orange) means X leads Y by a quarter cycle.
% -90 degrees (blue) means Y leads X by a quarter cycle.
% Coherence phase units may be radians, degrees, or msec.
% Click on any subplot to view separately and zoom in/out.
%
% Function description:
% Uses EITHER fixed-window, zero-padded FFTs (fastest) OR constant-Q
% 0-padded wavelet DFTs (more even sensitivity across frequencies),
% both Hanning-tapered. Output frequency spacing is the lowest
% frequency ('srate'/'winsize') divided by the 'padratio'.
%
% If an 'alpha' value is given, then bootstrap statistics are
% computed (from a distribution of 'naccu' {200} surrogate baseline
% data epochs) for the baseline epoch, and non-significant features
% of the output plots are zeroed (and shown in green). The baseline
% epoch is all windows with center latencies < the given 'baseline'
% value, or if 'baseboot' is 1, the whole epoch.
% Usage:
% >> [coh,mcoh,timesout,freqsout,cohboot,cohangles] ...
% = crossf(X,Y,frames,tlimits,srate,cycles, ...
% 'key1', 'val1', 'key2', val2' ...);
% Required inputs:
% X = first single-channel data set (1,frames*nepochs)
% Y = second single-channel data set (1,frames*nepochs)
% frames = frames per epoch {default: 750}
% tlimits = [mintime maxtime] (ms) epoch latency limits {def: [-1000 2000]}
% srate = data sampling rate (Hz) {default: 250}
% cycles = 0 -> Use FFTs (with constant window length)
% = >0 -> Number of cycles in each analysis wavelet
% = [cycles expfactor] -> if 0 < expfactor < 1, the number
% of wavelet cycles expands with frequency from cycles
% If expfactor = 1, no expansion; if = 0, constant
% window length (as in FFT) {default: 0}
% Optional Coherence Type:
% 'type' = ['coher'|'phasecoher'] Compute either linear coherence
% ('coher') or phase coherence ('phasecoher') also known
% as phase coupling factor' {default: 'phasecoher'}.
% 'subitc' = ['on'|'off'] subtract stimulus locked Inter-Trial Coherence
% from X and Y. This computes the 'intrinsic' coherence
% X and Y not arising from common synchronization to
% experimental events. See notes. {default: 'off'}
% 'shuffle' = integer indicating the number of estimates to compute
% bootstrap coherence based on shuffled trials. This estimates
% the coherence arising only from time locking of X and Y
% to experimental events (opposite of 'subitc') {default: 0}
% Optional Detrend:
% 'detret' = ['on'|'off'], Linearly detrend data within epochs {def: 'off'}
% 'detrep' = ['on'|'off'], Linearly detrend data across trials {def: 'off'}
%
% Optional FFT/DFT:
% 'winsize' = If cycles==0: data subwindow length (fastest, 2^n<frames);
% if cycles >0: *longest* window length to use. This
% determines the lowest output frequency {default: ~frames/8}
% 'timesout' = Number of output latencies (int<frames-winsize) {def: 200}
% 'padratio' = FFTlength/winsize (2^k) {default: 2}
% Multiplies the number of output frequencies by
% dividing their spacing. When cycles==0, frequency
% spacing is (low_frequency/padratio).
% 'maxfreq' = Maximum frequency (Hz) to plot (& output if cycles>0)
% If cycles==0, all FFT frequencies are output {default: 50}
% 'baseline' = Coherence baseline end latency (ms). NaN -> No baseline
% {default:NaN}
% 'powbase' = Baseline spectrum to log-subtract {default: from data}
%
% Optional Bootstrap:
% 'alpha' = If non-0, compute two-tailed bootstrap significance prob.
% level. Show non-signif output values as green. {def: 0}
% 'naccu' = Number of bootstrap replications to compute {def: 200}
% 'boottype' = ['times'|'timestrials'] Bootstrap type: Either shuffle
% windows ('times') or windows and trials ('timestrials')
% Option 'timestrials' requires more memory {default: 'times'}
% 'memory' = ['low'|'high'] 'low' -> decrease memory use {default: 'high'}
% 'baseboot' = Extent of bootstrap shuffling (0=to 'baseline'; 1=whole epoch)
% If no baseline is given (NaN), extent of bootstrap shuffling
% is the whole epoch {default: 0}
% 'rboot' = Input bootstrap coherence limits (e.g., from CROSSF)
% The bootstrap type should be identical to that used
% to obtain the input limits. {default: compute from data}
% Optional Scalp Map:
% 'topovec' = (2,nchans) matrix, plot scalp maps to plot {default: []}
% ELSE (c1,c2), plot two cartoons showing channel locations.
% 'elocs' = Electrode location structure or file for scalp map
% {default: none}
% 'chaninfo' = Electrode location additional information (nose position...)
% {default: none}
%
% Optional Plot and Compute Features:
% 'compute' = ['matlab'|'c'] Use C subroutines to speed up the
% computation (currently unimplemented) {def: 'matlab'}
% 'savecoher' - [0|1] 1 --> Accumulate the individual trial coherence
% vectors; output them as cohangles {default: 0 = off}
% 'plotamp' = ['on'|'off'], Plot coherence magnitude {def: 'on'}
% 'maxamp' = [real] Set the maximum for the amp. scale {def: auto}
% 'plotphase' = ['on'|'off'], Plot coherence phase angle {def: 'on'}
% 'angleunit' = Phase units: 'ms' -> msec, 'deg' -> degrees,
% or 'rad' -> radians {default: 'deg'}
% 'title' = Optional figure title {default: none}
% 'vert' = Latencies to mark with a dotted vertical line
% {default: none}
% 'linewidth' = Line width for marktimes traces (thick=2, thin=1)
% {default: 2}
% 'cmax' = Maximum amplitude for color scale {def: data limits}
% 'axesfont' = Axes font size {default: 10}
% 'titlefont' = Title font size {default: 8}
%
% Outputs:
% coh = Matrix (nfreqs,timesout) of coherence magnitudes
% mcoh = Vector of mean baseline coherence at each frequency
% timesout = Vector of output latencies (window centers) (ms).
% freqsout = Vector of frequency bin centers (Hz).
% cohboot = Matrix (nfreqs,2) of [lower;upper] coher signif. limits
% if 'boottype' is 'trials', (nfreqs,timesout, 2)
% cohangle = (nfreqs,timesout) matrix of coherence angles (in radians)
% cohangles = (nfreqs,timesout,trials) matrix of single-trial coherence
% angles (in radians), saved and output only if 'savecoher',1
%
% Plot description:
% Assuming both 'plotamp' and 'plotphase' options are 'on' (=default), the upper panel
% presents the magnitude of either phase coherence or linear coherence, depending on
% the 'type' parameter (above). The lower panel presents the coherence phase difference
% (in degrees). Click on any plot to pop up a new window (using 'axcopy()').
% -- The upper left marginal panel shows mean coherence during the baseline period
% (blue), and when significance is set, the significance threshold (dotted black-green).
% -- The horizontal panel under the coherence magnitude image indicates the maximum
% (green) and minimum (blue) coherence values across all frequencies. When significance
% is set (using option 'trials' for 'boottype'), an additional curve indicates the
% significance threshold (dotted black-green).
%
% Notes: 1) When cycles==0, nfreqs is total number of FFT frequencies.
% 2) As noted above: 'blue' coherence angle -> X leads Y; 'red' -> Y leads X
% 3) The 'boottype' should be ideally 'timesframes', but this creates high
% memory demands, so the 'times' method must be used in many cases.
% 4) If 'boottype' is 'trials', the average of the complex bootstrap
% is subtracted from the coherence to compensate for phase differences
% (the average is also subtracted from the bootstrap distribution).
% For other bootstraps, this is not necessary since the phase is random.
% 5) If baseline is non-NaN, the baseline is subtracted from
% the complex coherence. On the left hand side of the coherence
% amplitude image, the baseline is displayed as a magenta line
% (if no baseline is selected, this curve represents the average
% coherence at every given frequency).
% 6) If a out-of-memory error occurs, set the 'memory' option to 'low'
% (Makes computation time slower; Only the 'times' bootstrap method
% can be used in this mode).
%
% Authors: Arnaud Delorme, Sigurd Enghoff & Scott Makeig
% CNL/Salk Institute 1998-2001; SCCN/INC/UCSD, La Jolla, 2002-
%
% See also: TIMEF
% Copyright (C) 8/1/98 Arnaud Delorme, Sigurd Enghoff & Scott Makeig, SCCN/INC/UCSD
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
% 11-20-98 defined g.linewidth constant -sm
% 04-01-99 made number of frequencies consistent -se
% 06-29-99 fixed constant-Q freq indexing -se
% 08-13-99 added cohangle plotting -sm
% 08-20-99 made bootstrap more efficient -sm
% 08-24-99 allow nan values introduced by possible EVENTLOCK preproc. -sm
% 03-05-2007 eventlock.m deprecated to eegalign.m. -tf
% 03-16-00 added lead/lag interpretation to help msg - sm & eric visser
% 03-16-00 added AXCOPY feature -sm & tpj
% 04-20-00 fixed Rangle sign for wavelets, added verts array -sm
% 01-22-01 corrected help msg when nargin<2 -sm & arno delorme
% 01-25-02 reformated help & license, added links -ad
% 03-09-02 function restructuration -ad
% add 'key', val arguments (+ external baseboot, baseline, color axis, angleunit...)
% add detrending (across time and trials) + 'coher' option for amplitude coherence
% significance only if alpha is given, plotting options in 'plotamp' and 'plotphase'
% 03-16-02 timeout automatically adjusted if too high -ad
% 04-03-02 added new options for bootstrap -ad
% Note: 3 "objects" (Tf, Coher and Boot) are handled by specific functions under Matlab
% (Tf) function Tf = tfinit(...) - create object Time Frequency (Tf) associated with some data
% (Tf) function [Tf, itcvals] = tfitc(...) - compute itc for the selected data
% (Tf) function [Tf, itcvals] = tfitcpost(Tf, trials) - itc normalisation
% (Tf) function [Tf, tmpX] = tfcomp(Tf, trials, times) - compute time freq. decomposition
% (Coher) function Coher = coherinit(...) - initialize coherence object
% (Coher) function Coher = cohercomp(Coher, tmpX, tmpY, trial, time) - compute coherence
% (Coher) function Coher = cohercomppost(Coher, trials) - coherence normalization
% (Boot) function Boot = bootinit(...) - initialize bootstrap object
% (Boot) function Boot = bootcomp(...) - compute bootstrap
% (Boot) function [Boot, Rbootout] = bootcomppost(...) - bootstrap normalization
% and by real objects under C++ (C++ code, incomplete)
function [R,mbase,times,freqs,Rbootout,Rangle, trialcoher, Tfx, Tfy] = crossf(X, Y, frame, tlimits, Fs, varwin, varargin)
%varwin,winsize,nwin,oversmp,maxfreq,alpha,verts,caxmax)
% ------------------------
% Commandline arg defaults:
% ------------------------
DEFAULT_ANGLEUNIT = 'deg'; % angle plotting units - 'rad', 'ms', or 'deg'
DEFAULT_EPOCH = 750; % Frames per epoch
DEFAULT_TIMELIM = [-1000 2000]; % Time range of epochs (ms)
DEFAULT_FS = 250; % Sampling frequency (Hz)
DEFAULT_NWIN = 200; % Number of windows = horizontal resolution
DEFAULT_VARWIN = 0; % Fixed window length or base on cycles.
% =0: fix window length to nwin
% >0: set window length equal varwin cycles
% bounded above by winsize, also determines
% the min. freq. to be computed.
DEFAULT_OVERSMP = 2; % Number of times to oversample = vertical resolution
DEFAULT_MAXFREQ = 50; % Maximum frequency to display (Hz)
DEFAULT_TITLE = 'Event-Related Coherence'; % Figure title
DEFAULT_ALPHA = NaN; % Default two-sided significance probability threshold
if (nargin < 2)
help crossf
return
end
if ~iscell(X)
if (min(size(X))~=1 || length(X)<2)
fprintf('crossf(): X must be a row or column vector.\n');
return
elseif (min(size(Y))~=1 || length(Y)<2)
fprintf('crossf(): Y must be a row or column vector.\n');
return
elseif (length(X) ~= length(Y))
fprintf('crossf(): X and Y must have same length.\n');
return
end
end
if (nargin < 3)
frame = DEFAULT_EPOCH;
elseif (~isnumeric(frame) || length(frame)~=1 || frame~=round(frame))
fprintf('crossf(): Value of frames must be an integer.\n');
return
elseif (frame <= 0)
fprintf('crossf(): Value of frames must be positive.\n');
return
elseif ~iscell(X) && (rem(length(X),frame) ~= 0)
fprintf('crossf(): Length of data vectors must be divisible by frames.\n');
return
end
if (nargin < 4)
tlimits = DEFAULT_TIMELIM;
elseif (~isnumeric(tlimits) || sum(size(tlimits))~=3)
error('crossf(): Value of tlimits must be a vector containing two numbers.');
elseif (tlimits(1) >= tlimits(2))
error('crossf(): tlimits interval must be [min,max].');
end
if (nargin < 5)
Fs = DEFAULT_FS;
elseif (~isnumeric(Fs) || length(Fs)~=1)
error('crossf(): Value of srate must be a number.');
elseif (Fs <= 0)
error('crossf(): Value of srate must be positive.');
end
if (nargin < 6)
varwin = DEFAULT_VARWIN;
elseif (~isnumeric(varwin) || length(varwin)>2)
error('crossf(): Value of cycles must be a number or a (1,2) vector.');
elseif (varwin < 0)
error('crossf(): Value of cycles must be either zero or positive.');
end
% consider structure for these arguments
% --------------------------------------
vararginori = varargin;
for index=1:length(varargin)
if iscell(varargin{index}), varargin{index} = { varargin{index} }; end
end
if ~isempty(varargin)
try, g = struct(varargin{:});
catch, error('Argument error in the {''param'', value} sequence'); end;
else
g = [];
end
try, g.shuffle; catch, g.shuffle = 0; end
try, g.title; catch, g.title = DEFAULT_TITLE; end
try, g.winsize; catch, g.winsize = max(pow2(nextpow2(frame)-3),4); end
try, g.pad; catch, g.pad = max(pow2(nextpow2(g.winsize)),4); end
try, g.timesout; catch, g.timesout = DEFAULT_NWIN; end
try, g.padratio; catch, g.padratio = DEFAULT_OVERSMP; end
try, g.maxfreq; catch, g.maxfreq = DEFAULT_MAXFREQ; end
try, g.topovec; catch, g.topovec = []; end
try, g.elocs; catch, g.elocs = ''; end
try, g.alpha; catch, g.alpha = DEFAULT_ALPHA; end;
try, g.marktimes; catch, g.marktimes = []; end; % default no vertical lines
try, g.marktimes = g.vert; catch, g.vert = []; end; % default no vertical lines
try, g.powbase; catch, g.powbase = nan; end
try, g.rboot; catch, g.rboot = nan; end
try, g.plotamp; catch, g.plotamp = 'on'; end
try, g.plotphase; catch, g.plotphase = 'on'; end
try, g.plotbootsub; catch, g.plotbootsub = 'on'; end
try, g.detrep; catch, g.detrep = 'off'; end
try, g.detret; catch, g.detret = 'off'; end
try, g.baseline; catch, g.baseline = NaN; end
try, g.baseboot; catch, g.baseboot = 0; end
try, g.linewidth; catch, g.linewidth = 2; end
try, g.naccu; catch, g.naccu = 200; end
try, g.angleunit; catch, g.angleunit = DEFAULT_ANGLEUNIT; end
try, g.cmax; catch, g.cmax = 0; end; % 0=use data limits
try, g.type; catch, g.type = 'phasecoher'; end;
try, g.boottype; catch, g.boottype = 'times'; end;
try, g.subitc; catch, g.subitc = 'off'; end
try, g.memory; catch, g.memory = 'high'; end
try, g.compute; catch, g.compute = 'matlab'; end
try, g.maxamp; catch, g.maxamp = []; end
try, g.savecoher; catch, g.savecoher = 0; end
try, g.noinput; catch, g.noinput = 'no'; end
try, g.chaninfo; catch, g.chaninfo = []; end
allfields = fieldnames(g);
for index = 1:length(allfields)
switch allfields{index}
case { 'shuffle' 'title' 'winsize' 'pad' 'timesout' 'padratio' 'maxfreq' 'topovec' 'elocs' 'alpha' ...
'marktimes' 'vert' 'powbase' 'rboot' 'plotamp' 'plotphase' 'plotbootsub' 'detrep' 'detret' ...
'baseline' 'baseboot' 'linewidth' 'naccu' 'angleunit' 'cmax' 'type' 'boottype' 'subitc' ...
'memory' 'compute' 'maxamp' 'savecoher' 'noinput' 'chaninfo' };
case {'plotersp' 'plotitc' }, disp(['crossf warning: timef option ''' allfields{index} ''' ignored']);
otherwise disp(['crossf error: unrecognized option ''' allfields{index} '''']); beep; return;
end
end
g.tlimits = tlimits;
g.frame = frame;
g.srate = Fs;
g.cycles = varwin(1);
if length(varwin)>1
g.cyclesfact = varwin(2);
else
g.cyclesfact = 1;
end
g.type = lower(g.type);
g.boottype = lower(g.boottype);
g.detrep = lower(g.detrep);
g.detret = lower(g.detret);
g.plotphase = lower(g.plotphase);
g.plotbootsub = lower(g.plotbootsub);
g.subitc = lower(g.subitc);
g.plotamp = lower(g.plotamp);
g.shuffle = lower(g.shuffle);
g.compute = lower(g.compute);
g.AXES_FONT = 10;
g.TITLE_FONT = 14;
% testing arguments consistency
% -----------------------------
if (~ischar(g.title))
error('Title must be a string.');
end
if (~isnumeric(g.winsize) || length(g.winsize)~=1 || g.winsize~=round(g.winsize))
error('Value of winsize must be an integer number.');
elseif (g.winsize <= 0)
error('Value of winsize must be positive.');
elseif (g.cycles == 0 && pow2(nextpow2(g.winsize)) ~= g.winsize)
error('Value of winsize must be an integer power of two [1,2,4,8,16,...]');
elseif (g.winsize > g.frame)
error('Value of winsize must be less than frame length.');
end
if (~isnumeric(g.timesout) || length(g.timesout)~=1 || g.timesout~=round(g.timesout))
error('Value of timesout must be an integer number.');
elseif (g.timesout <= 0)
error('Value of timesout must be positive.');
end
if (g.timesout > g.frame-g.winsize)
g.timesout = g.frame-g.winsize;
disp(['Value of timesout must be <= frame-winsize, timeout adjusted to ' int2str(g.timesout) ]);
end
if (~isnumeric(g.padratio) || length(g.padratio)~=1 || g.padratio~=round(g.padratio))
error('Value of padratio must be an integer.');
elseif (g.padratio <= 0)
error('Value of padratio must be positive.');
elseif (pow2(nextpow2(g.padratio)) ~= g.padratio)
error('Value of padratio must be an integer power of two [1,2,4,8,16,...]');
end
if (~isnumeric(g.maxfreq) || length(g.maxfreq)~=1)
error('Value of g.maxfreq must be a number.');
elseif (g.maxfreq <= 0)
error('Value of g.maxfreq must be positive.');
elseif (g.maxfreq > Fs/2)
fprintf('Warning: input value of g.maxfreq larger that Nyquist frequency %3.4 Hz\n\n',Fs/2);
end
if isempty(g.topovec)
g.topovec = [];
elseif min(size(g.topovec))==1
g.topovec = g.topovec(:);
if size(g.topovec,1)~=2
error('topovec must be a row or column vector.');
end
end
if isempty(g.elocs)
g.elocs = '';
elseif (~ischar(g.elocs)) && ~isstruct(g.elocs)
error('Channel location file must be a valid text file.');
end
if (~isnumeric(g.alpha) || length(g.alpha)~=1)
error('timef(): Value of g.alpha must be a number.\n');
elseif (round(g.naccu*g.alpha) < 2)
fprintf('Value of g.alpha is out of the normal range [%g,0.5]\n',2/g.naccu);
g.naccu = round(2/g.alpha);
fprintf(' Increasing the number of bootstrap iterations to %d\n',g.naccu);
end
if g.alpha>0.5 || g.alpha<=0
error('Value of g.alpha is out of the allowed range (0.00,0.5).');
end
if ~isnan(g.alpha)
if g.baseboot > 0
fprintf('Bootstrap analysis will use data in baseline (pre-0) subwindows only.\n')
else
fprintf('Bootstrap analysis will use data in all subwindows.\n')
end
end
switch g.angleunit
case { 'rad', 'ms', 'deg' },;
otherwise error('Angleunit must be either ''rad'', ''deg'', or ''ms''');
end;
switch g.type
case { 'coher', 'phasecoher' 'phasecoher2' },;
otherwise error('Type must be either ''coher'' or ''phasecoher''');
end;
switch g.boottype
case { 'times' 'timestrials' 'trials'},;
otherwise error('Boot type must be either ''times'', ''trials'' or ''timestrials''');
end;
if (~isnumeric(g.shuffle))
error('Shuffle argument type must be numeric');
end
switch g.memory
case { 'low', 'high' },;
otherwise error('memory must be either ''low'' or ''high''');
end
if strcmp(g.memory, 'low') && ~strcmp(g.boottype, 'times')
error(['Bootstrap type ''' g.boottype ''' cannot be used in low memory mode']);
end
switch g.compute
case { 'matlab', 'c' },;
otherwise error('compute must be either ''matlab'' or ''c''');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compare 2 conditions
%%%%%%%%%%%%%%%%%%%%%%%%%%%
if iscell(X)
if length(X) ~= 2 || length(Y) ~= 2
error('crossf: to compare conditions, X and Y input must be 2-elements cell arrays');
end
if ~strcmp(g.boottype, 'times')
disp('crossf warning: The significance bootstrap type is irrelevant when comparing conditions');
end
for index = 1:2:length(vararginori)
if index<=length(vararginori) % needed: if elements are deleted
%if strcmp(vararginori{index}, 'alpha'), vararginori(index:index+1) = [];
if strcmp(vararginori{index}, 'title'), vararginori(index:index+1) = [];
end
end
end
if iscell(g.title)
if length(g.title) <= 2,
g.title{3} = 'Condition 2 - condition 1';
end
else
g.title = { 'Condition 1', 'Condition 2', 'Condition 2 - condition 1' };
end
fprintf('Running crossf on condition 1 *********************\n');
fprintf('Note: If an out-of-memory error occurs, try reducing the\n');
fprintf(' number of time points or number of frequencies\n');
if ~strcmp(g.type, 'coher')
fprintf('Note: Type ''coher'' takes 3 times as much memory as other options!)\n');
end
figure;
subplot(1,3,1); title(g.title{1});
if ~strcmp(g.type, 'coher')
[R1,mbase,times,freqs,Rbootout1,Rangle1, savecoher1] = crossf(X{1}, Y{1}, ...
frame, tlimits, Fs, varwin, 'savecoher', 1, 'title', ' ',vararginori{:});
else
[R1,mbase,times,freqs,Rbootout1,Rangle1, savecoher1, Tfx1, Tfy1] = crossf(X{1}, Y{1}, ...
frame, tlimits, Fs, varwin, 'savecoher', 1,'title', ' ',vararginori{:});
end
R1 = R1.*exp(j*Rangle1); % output Rangle is in radians
% Asking user for memory limitations
% if ~strcmp(g.noinput, 'yes')
% tmp = whos('Tfx1');
% fprintf('This function will require an additional %d bytes, do you wish\n', ...
% tmp.bytes*6+size(savecoher1,1)*size(savecoher1,2)*g.naccu*8);
% res = input('to continue (y/n) (use the ''noinput'' option to disable this message):', 's');
% if res == 'n', return; end
% end
fprintf('\nRunning crossf on condition 2 *********************\n');
subplot(1,3,2); title(g.title{2});
if ~strcmp(g.type, 'coher')
[R2,mbase,times,freqs,Rbootout2,Rangle2, savecoher2] = crossf(X{2}, Y{2}, ...
frame, tlimits, Fs, varwin,'savecoher', 1, 'title', ' ',vararginori{:});
else
[R2,mbase,times,freqs,Rbootout2,Rangle2, savecoher2, Tfx2, Tfy2] = crossf(X{2}, Y{2}, ...
frame, tlimits, Fs, varwin,'savecoher', 1, 'title', ' ',vararginori{:});
end
R2 = R2.*exp(j*Rangle2); % output Rangle is in radians
subplot(1,3,3); title(g.title{3});
if isnan(g.alpha)
plotall(R2-R1, [], [], times, freqs, mbase, find(freqs <= g.maxfreq), g);
else
% accumulate coherence images (all arrays [nb_points * timesout * trials])
% ---------------------------
allsavedcoher = zeros(size(savecoher1,1), ...
size(savecoher1,2), ...
size(savecoher1,3)+size(savecoher2,3));
allsavedcoher(:,:,1:size(savecoher1,3)) = savecoher1;
allsavedcoher(:,:,size(savecoher1,3)+1:end) = savecoher2;
clear savecoher1 savecoher2;
if strcmp(g.type, 'coher')
alltfx = zeros(size(Tfx1,1), size(Tfx2,2), size(Tfx1,3)+size(Tfx2,3));
alltfx(:,:,1:size(Tfx1,3)) = Tfx1;
alltfx(:,:,size(Tfx1,3)+1:end) = Tfx2;
clear Tfx1 Tfx2;
alltfy = zeros(size(Tfy1,1), size(Tfy2,2), size(Tfy1,3)+size(Tfy2,3));
alltfy(:,:,1:size(Tfy1,3)) = Tfy1;
alltfy(:,:,size(Tfy1,3)+1:end) = Tfy2;
clear Tfy1 Tfy2;
end
coherimages = zeros(size(allsavedcoher,1), size(allsavedcoher,2), g.naccu);
cond1trials = length(X{1})/g.frame;
cond2trials = length(X{2})/g.frame;
alltrials = [1:cond1trials+cond2trials];
fprintf('Accumulating bootstrap:');
% preprocess data
% ---------------
switch g.type
case 'coher', % take the square of alltfx and alltfy
alltfx = alltfx.^2;
alltfy = alltfy.^2;
case 'phasecoher', % normalize
allsavedcoher = allsavedcoher ./ abs(allsavedcoher);
case 'phasecoher2', % don't do anything
end
if strcmp(g.type, 'coher')
[coherdiff coher1 coher2] = coher2conddiff( allsavedcoher, alltrials, ...
cond1trials, g.type, alltfx, alltfy);
else
[coherdiff coher1 coher2] = coher2conddiff( allsavedcoher, alltrials, ...
cond1trials, g.type);
end
%figure; g.alpha = NaN; & to check that the new images are the same as the original
%subplot(1,3,1); plotall(coher1, [], [], times, freqs, mbase, find(freqs <= g.maxfreq), g);
%subplot(1,3,2); plotall(coher2, [], [], times, freqs, mbase, find(freqs <= g.maxfreq), g);
%return;
for index=1:g.naccu
if rem(index,10) == 0, fprintf(' %d',index); end
if rem(index,120) == 0, fprintf('\n'); end
if strcmp(g.type, 'coher')
coherimages(:,:,index) = coher2conddiff( allsavedcoher, shuffle(alltrials), ...
cond1trials, g.type, alltfx, alltfy);
else
coherimages(:,:,index) = coher2conddiff( allsavedcoher, shuffle(alltrials), ...
cond1trials, g.type);
end
end
fprintf('\n');
% create articially a Bootstrap object to compute significance
Boot = bootinit( [], size(allsavedcoher,1), g.timesout, g.naccu, 0, g.baseboot, ...
'noboottype', g.alpha, g.rboot);
Boot.Coherboot.R = coherimages;
Boot = bootcomppost(Boot, [], [], []);
g.title = '';
plotall(coherdiff, Boot.Coherboot.R, Boot.Rsignif, times, freqs, mbase, ...
find(freqs <= g.maxfreq), g);
end
return; % ********************************** END PROCESSING TWO CONDITIONS
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% shuffle trials if necessary
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if g.shuffle ~= 0
fprintf('x and y data trials being shuffled %d times\n',g.shuffle);
XX = reshape(X, 1, frame, length(X)/g.frame);
YY = Y;
X = [];
Y = [];
for index = 1:g.shuffle
XX = shuffle(XX,3);
X = [X XX(:,:)];
Y = [Y YY];
end
end
% detrend over epochs (trials) if requested
% -----------------------------------------
switch g.detrep
case 'on'
X = reshape(X, g.frame, length(X)/g.frame);
X = X - mean(X,2)*ones(1, length(X(:))/g.frame);
Y = reshape(Y, g.frame, length(Y)/g.frame);
Y = Y - mean(Y,2)*ones(1, length(Y(:))/g.frame);
end;
% time limits
wintime = 500*g.winsize/g.srate;
times = [g.tlimits(1)+wintime:(g.tlimits(2)-g.tlimits(1)-2*wintime)/(g.timesout-1):g.tlimits(2)-wintime];
%%%%%%%%%%
% baseline
%%%%%%%%%%
if ~isnan(g.baseline)
baseln = find(times < g.baseline); % subtract means of pre-0 (centered) windows
if isempty(baseln)
baseln = 1:length(times); % use all times as baseline
disp('Bootstrap baseline empty, using the whole epoch.');
end
baselength = length(baseln);
else
baseln = 1:length(times); % use all times as baseline
baselength = length(times); % used for bootstrap
end
%%%%%%%%%%%%%%%%%%%%
% Initialize objects
%%%%%%%%%%%%%%%%%%%%
tmpsaveall = (~isnan(g.alpha) & isnan(g.rboot) & strcmp(g.memory, 'high')) ...
| (strcmp(g.subitc, 'on') & strcmp(g.memory, 'high'));
trials = length(X)/g.frame;
if ~strcmp(g.compute, 'c')
Tfx = tfinit(X, g.timesout, g.winsize, g.cycles, g.frame, g.padratio, g.detret, ...
g.srate, g.maxfreq, g.subitc, g.type, g.cyclesfact, tmpsaveall);
Tfy = tfinit(Y, g.timesout, g.winsize, g.cycles, g.frame, g.padratio, g.detret, ...
g.srate, g.maxfreq, g.subitc, g.type, g.cyclesfact, tmpsaveall);
Coher = coherinit(Tfx.nb_points, trials, g.timesout, g.type);
Coherboot = coherinit(Tfx.nb_points, trials, g.naccu , g.type);
Boot = bootinit( Coherboot, Tfx.nb_points, g.timesout, g.naccu, baselength, ...
g.baseboot, g.boottype, g.alpha, g.rboot);
freqs = Tfx.freqs;
dispf = find(freqs <= g.maxfreq);
freqs = freqs(dispf);
else
freqs = g.srate*g.cycles/g.winsize*[2:2/g.padratio:g.winsize]/2;
end
dispf = find(Tfx.freqs <= g.maxfreq);
%-------------
% Reserve space
%-------------
% R = zeros(tfx.nb_points,g.timesout); % mean coherence
% RR = repmat(nan,tfx.nb_points,g.timesout); % initialize with nans
% Rboot = zeros(tfx.nb_points,g.naccu); % summed bootstrap coher
% switch g.type
% case 'coher',
% cumulXY = zeros(tfx.nb_points,g.timesout);
% cumulXYboot = zeros(tfx.nb_points,g.naccu);
% end;
% if g.bootsub > 0
% Rboottrial = zeros(tfx.nb_points, g.timesout, g.bootsub); % summed bootstrap coher
% cumulXYboottrial = zeros(tfx.nb_points, g.timesout, g.bootsub);
% end
% if ~isnan(g.alpha) & isnan(g.rboot)
% tf.tmpalltimes = repmat(nan,tfx.nb_points,g.timesout);
% end
% --------------------
% Display text to user
% --------------------
fprintf('\nComputing Event-Related ');
switch g.type
case 'phasecoher', fprintf('Phase Coherence (ITC) images for %d trials.\n',length(X)/g.frame);
case 'phasecoher2', fprintf('Phase Coherence 2 (ITC) images for %d trials.\n',length(X)/g.frame);
case 'coher', fprintf('Linear Coherence (ITC) images for %d trials.\n',length(X)/g.frame);
end
fprintf('The trial latency range is from %4.5g ms before to %4.5g ms after\n the time-locking event.\n', g.tlimits(1),g.tlimits(2));
fprintf('The frequency range displayed will be %g-%g Hz.\n',min(freqs),g.maxfreq);
if ~isnan(g.baseline)
if length(baseln) == length(times)
fprintf('Using the full trial latency range as baseline.\n');
else
fprintf('Using trial latencies from %4.5g ms to %4.5g ms as baseline.\n', g.tlimits,g.baseline);
end
else
fprintf('No baseline time range was specified.\n');
end
if g.cycles==0
fprintf('The data window size will be %d samples (%g ms).\n',g.winsize,2*wintime);
fprintf('The FFT length will be %d samples\n',g.winsize*g.padratio);
else
fprintf('The window size will be %2.3g cycles.\n',g.cycles);
fprintf('The maximum window size will be %d samples (%g ms).\n',g.winsize,2*wintime);
end
fprintf('The window will be applied %d times\n',g.timesout);
fprintf(' with an average step size of %2.2g samples (%2.4g ms).\n', Tfx.stp,1000*Tfx.stp/g.srate);
fprintf('Results will be oversampled %d times.\n',g.padratio);
if ~isnan(g.alpha)
fprintf('Bootstrap confidence limits will be computed based on alpha = %g\n', g.alpha);
else
fprintf('Bootstrap confidence limits will NOT be computed.\n');
end
switch g.plotphase
case 'on',
if strcmp(g.angleunit,'deg')
fprintf(['Coherence angles will be imaged in degrees.\n']);
elseif strcmp(g.angleunit,'rad')
fprintf(['Coherence angles will be imaged in radians.\n']);
elseif strcmp(g.angleunit,'ms')
fprintf(['Coherence angles will be imaged in ms.\n']);
end
end
fprintf('\nProcessing trial (of %d): ',trials);
% firstboot = 1;
% Rn=zeros(trials,g.timesout);
% X = X(:)'; % make X and Y column vectors
% Y = Y(:)';
% tfy = tfx;
if strcmp(g.compute, 'c')
% C PART
filename = [ 'tmpcrossf' num2str(round(rand(1)*1000)) ];
f = fopen([ filename '.in'], 'w');
fwrite(f, tmpsaveall, 'int32');
fwrite(f, g.detret, 'int32');
fwrite(f, g.srate, 'int32');
fwrite(f, g.maxfreq, 'int32');
fwrite(f, g.padratio, 'int32');
fwrite(f, g.cycles, 'int32');
fwrite(f, g.winsize, 'int32');
fwrite(f, g.timesout, 'int32');
fwrite(f, g.subitc, 'int32');
fwrite(f, g.type, 'int32');
fwrite(f, trials, 'int32');
fwrite(f, g.naccu, 'int32');
fwrite(f, length(X), 'int32');
fwrite(f, X, 'double');
fwrite(f, Y, 'double');
fclose(f);
command = [ '!cppcrosff ' filename '.in ' filename '.out' ];
eval(command);
f = fopen([ filename '.out'], 'r');
size1 = fread(f, 'int32', 1);
size2 = fread(f, 'int32', 1);
Rreal = fread(f, 'double', [size1 size2]);
Rimg = fread(f, 'double', [size1 size2]);
Coher.R = Rreal + j*Rimg;
Boot.Coherboot.R = [];
Boot.Rsignif = [];
else
% ------------------------
% MATLAB PART
% compute ITC if necessary
% ------------------------
if strcmp(g.subitc, 'on')
for t=1:trials
if rem(t,10) == 0, fprintf(' %d',t); end
if rem(t,120) == 0, fprintf('\n'); end
Tfx = tfitc( Tfx, t, 1:g.timesout);
Tfy = tfitc( Tfy, t, 1:g.timesout);
end;
fprintf('\n');
Tfx = tfitcpost( Tfx, trials);
Tfy = tfitcpost( Tfy, trials);
end
% ---------
% Main loop
% ---------
if g.savecoher,
trialcoher = zeros(Tfx.nb_points, g.timesout, trials);
else
trialcoher = [];
end
for t=1:trials
if rem(t,10) == 0, fprintf(' %d',t); end
if rem(t,120) == 0, fprintf('\n'); end
Tfx = tfcomp( Tfx, t, 1:g.timesout);
Tfy = tfcomp( Tfy, t, 1:g.timesout);
if g.savecoher
[Coher trialcoher(:,:,t)] = cohercomp( Coher, Tfx.tmpalltimes, ...
Tfy.tmpalltimes, t, 1:g.timesout);
else
Coher = cohercomp( Coher, Tfx.tmpalltimes, Tfy.tmpalltimes, t, 1:g.timesout);
end
Boot = bootcomp( Boot, Coher.Rn(t,:), Tfx.tmpalltimes, Tfy.tmpalltimes);
end % t = trial
[Boot Rbootout] = bootcomppost(Boot, Coher.Rn, Tfx.tmpall, Tfy.tmpall);
% Note that the bootstrap thresholding is actually performed
% in the display subfunction plotall()
Coher = cohercomppost(Coher, trials);
end
% ----------------------------------
% If coherence, perform the division
% ----------------------------------
% switch g.type
% case 'coher',
% R = R ./ cumulXY;
% if ~isnan(g.alpha) & isnan(g.rboot)
% Rboot = Rboot ./ cumulXYboot;
% end
% if g.bootsub > 0
% Rboottrial = Rboottrial ./ cumulXYboottrial;
% end
% case 'phasecoher',
% Rn = sum(Rn, 1);
% R = R ./ (ones(size(R,1),1)*Rn); % coherence magnitude
% if ~isnan(g.alpha) & isnan(g.rboot)
% Rboot = Rboot / trials;
% end
% if g.bootsub > 0
% Rboottrial = Rboottrial / trials;
% end
% end
% ----------------
% Compute baseline
% ----------------
mbase = mean(abs(Coher.R(:,baseln)')); % mean baseline coherence magnitude
% ---------------
% Plot everything
% ---------------
plotall(Coher.R, Boot.Coherboot.R, Boot.Rsignif, times, freqs, mbase, dispf, g);
% --------------------------------------
% Convert output Rangle to degrees or ms - Disabled to keep original default: radians output
% --------------------------------------
% Rangle = angle(Coher.R); % returns radians
% if strcmp(g.angleunit,'ms') % convert to ms
% Rangle = (Rangle/(2*pi)).*repmat(1000./freqs(dispf)',1,length(times));
% elseif strcmp(g.angleunit,'deg') % convert to deg
% Rangle = Rangle*180/pi; % convert to degrees
% else % angleunit is 'rad'
% % Rangle = Rangle;
% end
% Rangle(find(Rraw==0)) = 0; % mask for significance - set angle at non-signif coher points to 0
R = abs(Coher.R);
Rsignif = Boot.Rsignif;
Tfx = permute(Tfx.tmpall, [3 2 1]); % from [trials timesout nb_points]
% to [nb_points timesout trials]
Tfy = permute(Tfy.tmpall, [3 2 1]);
return; % end crossf() *************************************************
%
% CROSSF plotting functions
% ----------------------------------------------------------------------
function plotall(R, Rboot, Rsignif, times, freqs, mbase, dispf, g)
switch lower(g.plotphase)
case 'on',
switch lower(g.plotamp),
case 'on', ordinate1 = 0.67; ordinate2 = 0.1; height = 0.33; g.plot = 1;
case 'off', ordinate2 = 0.1; height = 0.9; g.plot = 1;
end;
case 'off', ordinate1 = 0.1; height = 0.9;
switch lower(g.plotamp),
case 'on', ordinate1 = 0.1; height = 0.9; g.plot = 1;
case 'off', g.plot = 0;
end;
end;
%
% Compute cross-spectral angles
% -----------------------------
Rangle = angle(R); % returns radians
%
% Optionally convert Rangle to degrees or ms
% ------------------------------------------
if strcmp(g.angleunit,'ms') % convert to ms
Rangle = (Rangle/(2*pi)).*repmat(1000./freqs(dispf)',1,length(times));
maxangle = max(max(abs(Rangle)));
elseif strcmp(g.angleunit,'deg') % convert to degrees
Rangle = Rangle*180/pi; % convert to degrees
maxangle = 180; % use full-cycle plotting
else
maxangle = pi; % radians
end
R = abs(R);
% if ~isnan(g.baseline)
% R = R - repmat(mbase',[1 g.timesout]); % remove baseline mean
% end
Rraw = R; % raw coherence (e.g., coherency) magnitude values output
if g.plot
fprintf('\nNow plotting...\n');
set(gcf,'DefaultAxesFontSize',g.AXES_FONT)
colormap(jet(256));
pos = get(gca,'position'); % plot relative to current axes
q = [pos(1) pos(2) 0 0];
s = [pos(3) pos(4) pos(3) pos(4)];
axis('off')
end
switch lower(g.plotamp)
case 'on'
%
% Image the coherence [% perturbations]
%
RR = R;
if ~isnan(g.alpha) % zero out (and 'green out') nonsignif. R values
RR(find(RR < repmat(Rboot(:),[1 g.timesout]))) = 0;
Rraw(find(repmat(Rsignif(:),[1,size(Rraw,2)])>=Rraw))=0;
end
if g.cmax == 0
coh_caxis = max(max(R(dispf,:)))*[-1 1];
else
coh_caxis = g.cmax*[-1 1];
end
h(6) = axes('Units','Normalized', 'Position',[.1 ordinate1 .8 height].*s+q);
map=hsv(300); % install circular color map - green=0, yellow, orng, red, violet = max
% cyan, blue, violet = min
map = flipud([map(251:end,:);map(1:250,:)]);
map(151,:) = map(151,:)*0.9; % tone down the (0=) green!
colormap(map);
imagesc(times,freqs(dispf),RR(dispf,:),coh_caxis); % plot the coherence image
if ~isempty(g.maxamp)
caxis([-g.maxamp g.maxamp]);
end
tmpscale = caxis;
hold on
plot([0 0],[0 freqs(max(dispf))],'--m','LineWidth',g.linewidth)
for i=1:length(g.marktimes)
plot([g.marktimes(i) g.marktimes(i)],[0 freqs(max(dispf))],'--m','LineWidth',g.linewidth);
end
hold off
set(h(6),'YTickLabel',[],'YTick',[])
set(h(6),'XTickLabel',[],'XTick',[])
%title('Event-Related Coherence')
h(8) = axes('Position',[.95 ordinate1 .05 height].*s+q);
cbar(h(8),151:300, [0 tmpscale(2)]); % use only positive colors (gyorv)
%
% Plot delta-mean min and max coherence at each time point on bottom of image
%
h(10) = axes('Units','Normalized','Position',[.1 ordinate1-0.1 .8 .1].*s+q);
% plot marginal means below
Emax = max(R(dispf,:)); % mean coherence at each time point
Emin = min(R(dispf,:)); % mean coherence at each time point
plot(times,Emin, times, Emax, 'LineWidth',g.linewidth); hold on;
plot([times(1) times(length(times))],[0 0],'LineWidth',0.7);
plot([0 0],[-500 500],'--m','LineWidth',g.linewidth);