0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 function [tmpall, freqs, timesout, itcvals] = timefreq(data, srate, varargin)
0140
0141 if nargin < 2
0142 help timefreq;
0143 return;
0144 end;
0145
0146 [chan frame trials]= size(data);
0147 if trials == 1 && chan ~= 1
0148 trials = frame;
0149 frame = chan;
0150 chan = 1;
0151 end;
0152 g = finputcheck(varargin, ...
0153 { 'ntimesout' 'integer' [] []; ...
0154 'timesout' 'real' [] []; ...
0155 'winsize' 'integer' [0 Inf] []; ...
0156 'tlimits' 'real' [] []; ...
0157 'detrend' 'string' {'on' 'off'} 'off'; ...
0158 'causal' 'string' {'on' 'off'} 'off'; ...
0159 'verbose' 'string' {'on' 'off'} 'on'; ...
0160 'freqs' 'real' [0 Inf] []; ...
0161 'nfreqs' 'integer' [0 Inf] []; ...
0162 'freqscale' 'string' { 'linear' 'log' '' } 'linear'; ...
0163 'ffttaper' 'string' { 'hanning' 'hamming' 'blackmanharris' 'none' } 'hanning';
0164 'wavelet' 'real' [0 Inf] 0; ...
0165 'cycles' {'real','integer'} [0 Inf] 0; ...
0166 'padratio' 'integer' [1 Inf] 2; ...
0167 'itctype' 'string' {'phasecoher' 'phasecoher2' 'coher'} 'phasecoher'; ...
0168 'subitc' 'string' {'on' 'off'} 'off'; ...
0169 'timestretch' 'cell' [] {}; ...
0170 'wletmethod' 'string' {'dftfilt2' 'dftfilt3'} 'dftfilt3'; ...
0171 });
0172 if isstr(g), error(g); end;
0173 if isempty(g.freqscale), g.freqscale = 'linear'; end;
0174 if isempty(g.winsize), g.winsize = max(pow2(nextpow2(frame)-3),4); end;
0175 if isempty(g.ntimesout), g.ntimesout = 200; end;
0176 if isempty(g.freqs), g.freqs = [0 srate/2]; end;
0177 if isempty(g.tlimits), g.tlimits = [0 frame/srate*1000]; end;
0178
0179
0180
0181
0182
0183 if g.cycles == 0
0184 g.cycles = g.wavelet;
0185 end
0186
0187 if (g.winsize > frame)
0188 error('Value of winsize must be less than frame length.');
0189 end
0190 if (pow2(nextpow2(g.padratio)) ~= g.padratio)
0191 error('Value of padratio must be an integer power of two [1,2,4,8,16,...]');
0192 end
0193
0194
0195
0196 if g.cycles(1) ~= 0 & g.freqs(1) == 0, g.freqs(1) = srate*g.cycles(1)/g.winsize; end;
0197
0198
0199
0200 if length(g.freqs) == 2
0201
0202
0203
0204 if g.freqs(1) == 0 & g.cycles(1) ~= 0
0205 g.freqs(1) = srate*g.cycles(1)/g.winsize;
0206 end;
0207
0208
0209
0210 if isempty(g.nfreqs)
0211 g.nfreqs = g.winsize/2*g.padratio+1;
0212
0213 tmpfreqs = linspace(0, srate/2, g.nfreqs);
0214 tmpfreqs = tmpfreqs(2:end);
0215
0216
0217 if g.cycles(1) == 0 & ~strcmpi(g.freqscale, 'log')
0218 if ~any(tmpfreqs == g.freqs(1))
0219 [tmp minind] = min(abs(tmpfreqs-g.freqs(1)));
0220 g.freqs(1) = tmpfreqs(minind);
0221 verboseprintf(g.verbose, 'Adjust min freq. to %3.2f Hz to match FFT output frequencies\n', g.freqs(1));
0222 end;
0223 if ~any(tmpfreqs == g.freqs(2))
0224 [tmp minind] = min(abs(tmpfreqs-g.freqs(2)));
0225 g.freqs(2) = tmpfreqs(minind);
0226 verboseprintf(g.verbose, 'Adjust max freq. to %3.2f Hz to match FFT output frequencies\n', g.freqs(2));
0227 end;
0228 end;
0229
0230
0231
0232 g.nfreqs = length(tmpfreqs( intersect( find(tmpfreqs >= g.freqs(1)), find(tmpfreqs <= g.freqs(2)))));
0233 if g.freqs(1)==g.freqs(2), g.nfreqs = 1; end;
0234 end;
0235
0236
0237
0238 if strcmpi(g.freqscale, 'log')
0239 g.freqs = linspace(log(g.freqs(1)), log(g.freqs(end)), g.nfreqs);
0240 g.freqs = exp(g.freqs);
0241 else
0242 g.freqs = linspace(g.freqs(1), g.freqs(2), g.nfreqs);
0243
0244 end;
0245 end;
0246 g.nfreqs = length(g.freqs);
0247
0248
0249
0250 if (g.cycles(1) == 0)
0251 freqs = linspace(0, srate/2, g.winsize*g.padratio/2+1);
0252 freqs = freqs(2:end);
0253
0254 verboseprintf(g.verbose, 'Using %s FFT tapering\n', g.ffttaper);
0255 switch g.ffttaper
0256 case 'hanning', g.win = hanning(g.winsize);
0257 case 'hamming', g.win = hamming(g.winsize);
0258 case 'blackmanharris', g.win = blackmanharris(g.winsize);
0259 case 'none', g.win = ones(g.winsize,1);
0260 end;
0261 else
0262
0263
0264
0265 freqs = g.freqs;
0266 if length(g.cycles) == 2
0267 if g.cycles(2) < 1
0268 g.cycles = [ g.cycles(1) g.cycles(1)*g.freqs(end)/g.freqs(1)*(1-g.cycles(2))];
0269 end
0270 verboseprintf(g.verbose, 'Using %g cycles at lowest frequency to %g at highest.\n', g.cycles(1), g.cycles(2));
0271 elseif length(g.cycles) == 1
0272 verboseprintf(g.verbose, 'Using %d cycles at all frequencies.\n',g.cycles);
0273 else
0274 verboseprintf(g.verbose, 'Using user-defined cycle for each frequency\n');
0275 end
0276 if strcmp(g.wletmethod, 'dftfilt2')
0277 g.win = dftfilt2(g.freqs,g.cycles,srate, g.freqscale);
0278 elseif strcmp(g.wletmethod, 'dftfilt3')
0279 g.win = dftfilt3(g.freqs,g.cycles,srate, 'cycleinc', g.freqscale);
0280 else return
0281 end
0282 g.winsize = 0;
0283 for index = 1:length(g.win)
0284 g.winsize = max(g.winsize,length(g.win{index}));
0285 end;
0286 end;
0287
0288
0289
0290 [ g.timesout g.indexout ] = gettimes(frame, g.tlimits, g.timesout, g.winsize, g.ntimesout, g.causal, g.verbose);
0291
0292
0293
0294
0295 verboseprintf(g.verbose, 'The window size used is %d samples (%g ms) wide.\n',g.winsize, 1000/srate*g.winsize);
0296 if strcmpi(g.freqscale, 'log')
0297 scaletoprint = 'log';
0298 else scaletoprint = 'linear';
0299 end
0300 verboseprintf(g.verbose, 'Estimating %d %s-spaced frequencies from %2.1f Hz to %3.1f Hz.\n', length(g.freqs), ...
0301 scaletoprint, g.freqs(1), g.freqs(end));
0302
0303
0304
0305 if g.cycles(1) == 0
0306 if 1
0307
0308
0309 indices = repmat([-g.winsize/2+1:g.winsize/2]', [1 length(g.indexout) trials]);
0310 indices = indices + repmat(g.indexout, [size(indices,1) 1 trials]);
0311 indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,trials), [size(indices,1) length(g.indexout) 1]);
0312 if chan > 1
0313 tmpall = repmat(nan,[chan length(freqs) length(g.timesout) trials]);
0314 tmpX = reshape(data(:,indices), [ size(data,1) size(indices)]);
0315 tmpX = bsxfun(@minus, tmpX, mean( tmpX, 2));
0316 tmpX = bsxfun(@times, tmpX, g.win');
0317 tmpX = fft(tmpX,g.padratio*g.winsize,2);
0318 tmpall = squeeze(tmpX(:,2:g.padratio*g.winsize/2+1,:,:));
0319 else
0320 tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]);
0321 tmpX = data(indices);
0322 tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1));
0323 tmpX = bsxfun(@times, tmpX, g.win);
0324
0325
0326 tmpX = fft(tmpX,g.padratio*g.winsize);
0327 tmpall = tmpX(2:g.padratio*g.winsize/2+1,:,:);
0328 end;
0329 else
0330 tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]);
0331 verboseprintf(g.verbose, 'Processing trial (of %d):',trials);
0332 for trial = 1:trials
0333 if rem(trial,10) == 0, verboseprintf(g.verbose, ' %d',trial); end
0334 if rem(trial,120) == 0, verboseprintf(g.verbose, '\n'); end
0335 for index = 1:length(g.indexout)
0336 if strcmpi(g.causal, 'off')
0337 tmpX = data([-g.winsize/2+1:g.winsize/2]+g.indexout(index)+(trial-1)*frame);
0338 else
0339 tmpX = data([-g.winsize+1:0]+g.indexout(index)+(trial-1)*frame);
0340 end;
0341
0342 tmpX = tmpX - mean(tmpX);
0343 if strcmpi(g.detrend, 'on'),
0344 tmpX = detrend(tmpX);
0345 end;
0346
0347 tmpX = g.win .* tmpX(:);
0348 tmpX = fft(tmpX,g.padratio*g.winsize);
0349 tmpX = tmpX(2:g.padratio*g.winsize/2+1);
0350 tmpall(:,index, trial) = tmpX(:);
0351 end;
0352 end;
0353 end;
0354 else
0355 if chan > 1
0356
0357
0358
0359
0360 tmpall = repmat(nan,[chan length(freqs) length(g.timesout) trials]);
0361 wt = [ 1 find(diff(cellfun(@length,g.win)))+1 length(g.win)+1];
0362 verboseprintf(g.verbose, 'Computing of %d:', length(wt));
0363 for ind = 1:length(wt)-1
0364 verboseprintf(g.verbose, '.');
0365 wavarray = reshape([ g.win{wt(ind):wt(ind+1)-1} ], [ length(g.win{wt(ind)}) wt(ind+1)-wt(ind) ]);
0366 sizewav = size(wavarray,1)-1;
0367 indices = repmat([-sizewav/2:sizewav/2]', [1 size(wavarray,2) length(g.indexout) trials]);
0368 indices = indices + repmat(reshape(g.indexout, 1,1,length(g.indexout)), [size(indices,1) size(indices,2) 1 trials]);
0369 indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,1,trials), [size(indices,1) size(indices,2) size(indices,3) 1]);
0370 szfreqdata = [ size(data,1) size(indices) ];
0371 tmpX = reshape(data(:,indices), szfreqdata);
0372 tmpX = bsxfun(@minus, tmpX, mean( tmpX, 2));
0373 wavarray = reshape(wavarray, [1 size(wavarray,1) size(wavarray,2)]);
0374 tmpall(:,wt(ind):wt(ind+1)-1,:,:,:) = reshape(sum(bsxfun(@times, tmpX, wavarray),2), [szfreqdata(1) szfreqdata(3:end)]);
0375 end;
0376 verboseprintf(g.verbose, '\n');
0377
0378 elseif 0
0379 tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]);
0380
0381
0382
0383
0384
0385 wt = [ 1 find(diff(cellfun(@length,g.win)))+1 length(g.win)+1];
0386 for ind = 1:length(wt)-1
0387 wavarray = reshape([ g.win{wt(ind):wt(ind+1)-1} ], [ length(g.win{wt(ind)}) wt(ind+1)-wt(ind) ]);
0388 sizewav = size(wavarray,1)-1;
0389 indices = repmat([-sizewav/2:sizewav/2]', [1 size(wavarray,2) length(g.indexout) trials]);
0390 indices = indices + repmat(reshape(g.indexout, 1,1,length(g.indexout)), [size(indices,1) size(indices,2) 1 trials]);
0391 indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,1,trials), [size(indices,1) size(indices,2) size(indices,3) 1]);
0392 tmpX = data(indices);
0393 tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1));
0394 tmpall(wt(ind):wt(ind+1)-1,:,:) = squeeze(sum(bsxfun(@times, tmpX, wavarray),1));
0395 end;
0396 elseif 0
0397
0398
0399 tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]);
0400 sizewav = length(g.win{1})-1;
0401 mainc = sizewav/2;
0402 indices = repmat([-sizewav/2:sizewav/2]', [1 length(g.indexout) trials]);
0403 indices = indices + repmat(g.indexout, [size(indices,1) 1 trials]);
0404 indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,trials), [size(indices,1) length(g.indexout) 1]);
0405
0406 for freqind = 1:length(g.win)
0407 winc = (length(g.win{freqind})-1)/2;
0408 wins = length(g.win{freqind})-1;
0409 wini = [-wins/2:wins/2]+winc+mainc-winc+1;
0410 tmpX = data(indices(wini,:,:));
0411 tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1));
0412 tmpX = sum(bsxfun(@times, tmpX, g.win{freqind}'),1);
0413 tmpall(freqind,:,:) = tmpX;
0414 end;
0415 else
0416
0417
0418 for index = 1:length(g.win)
0419 g.win{index} = transpose(repmat(g.win{index}, [trials 1]));
0420 end;
0421
0422
0423
0424 verboseprintf(g.verbose, 'Processing time point (of %d):',length(g.timesout));
0425 for index = 1:length(g.indexout)
0426 if rem(index,10) == 0, verboseprintf(g.verbose, ' %d',index); end
0427 if rem(index,120) == 0, verboseprintf(g.verbose, '\n'); end
0428 for freqind = 1:length(g.win)
0429 wav = g.win{freqind};
0430 sizewav = size(wav,1)-1;
0431
0432 if strcmpi(g.causal, 'off')
0433 tmpX = data([-sizewav/2:sizewav/2]+g.indexout(index),:);
0434 else
0435 tmpX = data([-sizewav:0]+g.indexout(index),:);
0436 end;
0437
0438 tmpX = tmpX - ones(size(tmpX,1),1)*mean(tmpX);
0439 if strcmpi(g.detrend, 'on'),
0440 for trial = 1:trials
0441 tmpX(:,trial) = detrend(tmpX(:,trial));
0442 end;
0443 end;
0444
0445 tmpX = sum(wav .* tmpX);
0446 tmpall( freqind, index, :) = tmpX;
0447 end;
0448 end;
0449 end;
0450 end;
0451 verboseprintf(g.verbose, '\n');
0452
0453
0454
0455 if ~isempty(g.timestretch) && length(g.timestretch{1}) > 0
0456
0457 timemarks = g.timestretch{1}';
0458 if isempty(g.timestretch{2}) | length(g.timestretch{2}) == 0
0459 timerefs = median(g.timestretch{1}',2);
0460 else
0461 timerefs = g.timestretch{2};
0462 end
0463 trials = size(tmpall,3);
0464
0465
0466
0467
0468 [dummy refsPos] = min(transpose(abs( ...
0469 repmat(timerefs, [1 length(g.indexout)]) - repmat(g.indexout, [length(timerefs) 1]))));
0470 refsPos(end+1) = 1;
0471 refsPos(end+1) = length(g.indexout);
0472 refsPos = sort(refsPos);
0473
0474 for t=1:trials
0475
0476
0477
0478
0479
0480
0481 outOfTimeRangeTimeWarpMarkers = find(timemarks(:,t) < min(g.indexout) | timemarks(:,t) > max(g.indexout));
0482
0483
0484
0485
0486
0487 [dummy marksPos] = min(transpose( ...
0488 abs( ...
0489 repmat(timemarks(:,t), [1 length(g.indexout)]) ...
0490 - repmat(g.indexout, [size(timemarks,1) 1]) ...
0491 ) ...
0492 ));
0493
0494
0495 marksPos(end+1) = 1;
0496 marksPos(end+1) = length(g.indexout);
0497 marksPos = sort(marksPos);
0498
0499
0500 mytmpall = tmpall(:,:,t);
0501 r = sqrt(mytmpall.*conj(mytmpall));
0502 theta = angle(mytmpall);
0503
0504
0505
0506
0507 M = timeWarp(marksPos, refsPos);
0508
0509 TSr = transpose(M*r');
0510 TStheta = zeros(size(theta,1), size(theta,2));
0511
0512 for freqInd=1:size(TStheta,1)
0513 TStheta(freqInd, :) = angTimeWarp(marksPos, refsPos, theta(freqInd, :));
0514 end
0515 TStmpall = TSr.*exp(i*TStheta);
0516
0517
0518
0519 tmpall(:,:,t) = TStmpall;
0520 end
0521 end
0522
0523
0524
0525
0526 if nargout > 3 || strcmpi(g.subitc, 'on')
0527 itcvals = tfitc(tmpall, g.itctype);
0528 end;
0529 if strcmpi(g.subitc, 'on')
0530
0531 if ndims(tmpall) <= 3
0532 tmpall = (tmpall - abs(tmpall) .* repmat(itcvals, [1 1 trials])) ./ abs(tmpall);
0533 else tmpall = (tmpall - abs(tmpall) .* repmat(itcvals, [1 1 1 trials])) ./ abs(tmpall);
0534 end;
0535 end;
0536
0537
0538
0539 if length(g.freqs) ~= length(freqs) || any(g.freqs ~= freqs)
0540 allindices = zeros(1,length(g.freqs));
0541 for index = 1:length(g.freqs)
0542 [dum ind] = min(abs(freqs-g.freqs(index)));
0543 allindices(index) = ind;
0544 end;
0545 verboseprintf(g.verbose, 'finding closest frequencies: %d freqs removed\n', length(freqs)-length(allindices));
0546 freqs = freqs(allindices);
0547 if ndims(tmpall) <= 3
0548 tmpall = tmpall(allindices,:,:);
0549 else tmpall = tmpall(:,allindices,:,:);
0550 end;
0551 if nargout > 3 | strcmpi(g.subitc, 'on')
0552 if ndims(tmpall) <= 3
0553 itcvals = itcvals(allindices,:,:);
0554 else itcvals = itcvals(:,allindices,:,:);
0555 end;
0556 end;
0557 end;
0558
0559 timesout = g.timesout;
0560
0561
0562 return;
0563
0564
0565
0566 function [itcvals] = tfitc(tfdecomp, itctype);
0567
0568 nd = max(3,ndims(tfdecomp));
0569 switch itctype
0570 case 'coher',
0571 try,
0572 itcvals = sum(tfdecomp,nd) ./ sqrt(sum(tfdecomp .* conj(tfdecomp),nd) * size(tfdecomp,nd));
0573 catch,
0574 for index =1:size(tfdecomp,1)
0575 itcvals(index,:,:) = sum(tfdecomp(index,:,:,:),nd) ./ sqrt(sum(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:)),nd) * size(tfdecomp,nd));
0576 end;
0577 end;
0578 case 'phasecoher2',
0579 try,
0580 itcvals = sum(tfdecomp,nd) ./ sum(sqrt(tfdecomp .* conj(tfdecomp)),nd);
0581 catch,
0582 for index =1:size(tfdecomp,1)
0583 itcvals(index,:,:) = sum(tfdecomp(index,:,:,:),nd) ./ sum(sqrt(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:))),nd);
0584 end;
0585 end;
0586 case 'phasecoher',
0587 try,
0588 itcvals = sum(tfdecomp ./ sqrt(tfdecomp .* conj(tfdecomp)) ,nd) / size(tfdecomp,nd);
0589 catch,
0590 for index =1:size(tfdecomp,1)
0591 itcvals(index,:,:) = sum(tfdecomp(index,:,:,:) ./ sqrt(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:))) ,nd) / size(tfdecomp,nd);
0592 end;
0593 end;
0594 end
0595 return;
0596
0597 function w = hanning(n)
0598 if ~rem(n,2)
0599 w = .5*(1 - cos(2*pi*(1:n/2)'/(n+1)));
0600 w = [w; w(end:-1:1)];
0601 else
0602 w = .5*(1 - cos(2*pi*(1:(n+1)/2)'/(n+1)));
0603 w = [w; w(end-1:-1:1)];
0604 end
0605
0606
0607
0608 function [ timevals, timeindices ] = gettimes(frames, tlimits, timevar, winsize, ntimevar, causal, verbose);
0609 timevect = linspace(tlimits(1), tlimits(2), frames);
0610 srate = 1000*(frames-1)/(tlimits(2)-tlimits(1));
0611
0612 if isempty(timevar)
0613 if ntimevar(1) > 0
0614
0615
0616 if (ntimevar > frames-winsize)
0617 ntimevar = frames-winsize;
0618 if ntimevar < 0
0619 error('Not enough data points, reduce the window size or lowest frequency');
0620 end;
0621 verboseprintf(verbose, ['Value of ''timesout'' must be <= frame-winsize, ''timesout'' adjusted to ' int2str(ntimevar) '\n']);
0622 end
0623 npoints = ntimevar(1);
0624 wintime = 500*winsize/srate;
0625 if strcmpi(causal, 'on')
0626 timevals = linspace(tlimits(1)+2*wintime, tlimits(2), npoints);
0627 else timevals = linspace(tlimits(1)+wintime, tlimits(2)-wintime, npoints);
0628 end;
0629 verboseprintf(verbose, 'Generating %d time points (%1.1f to %1.1f ms)\n', npoints, min(timevals), max(timevals));
0630 else
0631
0632
0633 nsub = -ntimevar(1);
0634 if strcmpi(causal, 'on')
0635 timeindices = [ceil(winsize+nsub):nsub:length(timevect)];
0636 else timeindices = [ceil(winsize/2+nsub/2):nsub:length(timevect)-ceil(winsize/2)-1];
0637 end;
0638 timevals = timevect( timeindices );
0639 verboseprintf(verbose, 'Subsampling by %d (%1.1f to %1.1f ms)\n', nsub, min(timevals), max(timevals));
0640 end;
0641 else
0642 timevals = timevar;
0643
0644
0645 wintime = 500*winsize/srate;
0646 if strcmpi(causal, 'on')
0647 tmpind = find( (timevals >= tlimits(1)+2*wintime-0.0001) & (timevals <= tlimits(2)) );
0648 else tmpind = find( (timevals >= tlimits(1)+wintime-0.0001) & (timevals <= tlimits(2)-wintime+0.0001) );
0649 end;
0650
0651 if isempty(tmpind)
0652 error('No time points. Reduce time window or minimum frequency.');
0653 end;
0654 if length(timevals) ~= length(tmpind)
0655 verboseprintf(verbose, 'Warning: %d out of %d time values were removed (now %3.2f to %3.2f ms) so the lowest\n', ...
0656 length(timevals)-length(tmpind), length(timevals), timevals(tmpind(1)), timevals(tmpind(end)));
0657 verboseprintf(verbose, ' frequency could be computed with the requested accuracy\n');
0658 end;
0659 timevals = timevals(tmpind);
0660 end;
0661
0662
0663
0664 timeindices = round(eeg_lat2point(timevals, 1, srate, tlimits, 1E-3));
0665 if length(timeindices) < length(unique(timeindices))
0666 timeindices = unique(timeindices)
0667 verboseprintf(verbose, 'Warning: duplicate times, reduce the number of output times\n');
0668 end;
0669 if length(unique(timeindices(2:end)-timeindices(1:end-1))) > 1
0670 verboseprintf(verbose, 'Finding closest points for time variable');
0671 verboseprintf(verbose, 'Time values for time/freq decomposition is not perfectly uniformly distributed\n');
0672 else
0673 verboseprintf(verbose, 'Distribution of data point for time/freq decomposition is perfectly uniform\n');
0674 end;
0675 timevals = timevect(timeindices);
0676
0677
0678 function nofunction()
0679
0680 filename = [ 'tmpcrossf' num2str(round(rand(1)*1000)) ];
0681 f = fopen([ filename '.in'], 'w');
0682 fwrite(f, tmpsaveall, 'int32');
0683 fwrite(f, g.detret, 'int32');
0684 fwrite(f, g.srate, 'int32');
0685 fwrite(f, g.maxfreq, 'int32');
0686 fwrite(f, g.padratio, 'int32');
0687 fwrite(f, g.cycles, 'int32');
0688 fwrite(f, g.winsize, 'int32');
0689 fwrite(f, g.timesout, 'int32');
0690 fwrite(f, g.subitc, 'int32');
0691 fwrite(f, g.type, 'int32');
0692 fwrite(f, trials, 'int32');
0693 fwrite(f, g.naccu, 'int32');
0694 fwrite(f, length(X), 'int32');
0695 fwrite(f, X, 'double');
0696 fwrite(f, Y, 'double');
0697 fclose(f);
0698
0699 command = [ '!cppcrosff ' filename '.in ' filename '.out' ];
0700 eval(command);
0701
0702 f = fopen([ filename '.out'], 'r');
0703 size1 = fread(f, 'int32', 1);
0704 size2 = fread(f, 'int32', 1);
0705 Rreal = fread(f, 'double', [size1 size2]);
0706 Rimg = fread(f, 'double', [size1 size2]);
0707 Coher.R = Rreal + j*Rimg;
0708 Boot.Coherboot.R = [];
0709 Boot.Rsignif = [];
0710
0711 function verboseprintf(verbose, varargin)
0712 if strcmpi(verbose, 'on')
0713 fprintf(varargin{:});
0714 end;
0715