| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| function [tmpall, freqs, timesout, itcvals] = timefreq(data, srate, varargin) |
|
|
| if nargin < 2 |
| help timefreq; |
| return; |
| end; |
|
|
| [chan frame trials]= size(data); |
| if trials == 1 && chan ~= 1 |
| trials = frame; |
| frame = chan; |
| chan = 1; |
| end; |
| g = finputcheck(varargin, ... |
| { 'ntimesout' 'integer' [] []; ... |
| 'timesout' 'real' [] []; ... |
| 'winsize' 'integer' [0 Inf] []; ... |
| 'tlimits' 'real' [] []; ... |
| 'detrend' 'string' {'on','off'} 'off'; ... |
| 'causal' 'string' {'on','off'} 'off'; ... |
| 'verbose' 'string' {'on','off'} 'on'; ... |
| 'freqs' 'real' [0 Inf] []; ... |
| 'nfreqs' 'integer' [0 Inf] []; ... |
| 'freqscale' 'string' { 'linear','log','' } 'linear'; ... |
| 'ffttaper' 'string' { 'hanning','hamming','blackmanharris','none' } 'hanning'; |
| 'wavelet' 'real' [0 Inf] 0; ... |
| 'cycles' {'real','integer'} [0 Inf] 0; ... |
| 'padratio' 'integer' [1 Inf] 2; ... |
| 'itctype' 'string' {'phasecoher','phasecoher2','coher'} 'phasecoher'; ... |
| 'subitc' 'string' {'on','off'} 'off'; ... |
| 'timestretch' 'cell' [] {}; ... |
| 'wletmethod' 'string' {'dftfilt2','dftfilt3'} 'dftfilt3'; ... |
| }); |
| if isstr(g), error(g); end; |
| if isempty(g.freqscale), g.freqscale = 'linear'; end; |
| if isempty(g.winsize), g.winsize = max(pow2(nextpow2(frame)-3),4); end; |
| if isempty(g.ntimesout), g.ntimesout = 200; end; |
| if isempty(g.freqs), g.freqs = [0 srate/2]; end; |
| if isempty(g.tlimits), g.tlimits = [0 frame/srate*1000]; end; |
|
|
| |
| |
|
|
| |
| if g.cycles == 0 |
| g.cycles = g.wavelet; |
| end |
|
|
| if (g.winsize > frame) |
| error('Value of winsize must be less than frame length.'); |
| end |
| if (pow2(nextpow2(g.padratio)) ~= g.padratio) |
| error('Value of padratio must be an integer power of two [1,2,4,8,16,...]'); |
| end |
|
|
| |
| |
| if g.cycles(1) ~= 0 & g.freqs(1) == 0, g.freqs(1) = srate*g.cycles(1)/g.winsize; end; |
|
|
| |
| |
| if length(g.freqs) == 2 |
|
|
| |
| |
| if g.freqs(1) == 0 & g.cycles(1) ~= 0 |
| g.freqs(1) = srate*g.cycles(1)/g.winsize; |
| end; |
|
|
| |
| |
| if isempty(g.nfreqs) |
| g.nfreqs = g.winsize/2*g.padratio+1; |
| |
| tmpfreqs = linspace(0, srate/2, g.nfreqs); |
| tmpfreqs = tmpfreqs(2:end); |
|
|
| |
| if g.cycles(1) == 0 & ~strcmpi(g.freqscale, 'log') |
| if ~any(tmpfreqs == g.freqs(1)) |
| [tmp minind] = min(abs(tmpfreqs-g.freqs(1))); |
| g.freqs(1) = tmpfreqs(minind); |
| verboseprintf(g.verbose, 'Adjust min freq. to %3.2f Hz to match FFT output frequencies\n', g.freqs(1)); |
| end; |
| if ~any(tmpfreqs == g.freqs(2)) |
| [tmp minind] = min(abs(tmpfreqs-g.freqs(2))); |
| g.freqs(2) = tmpfreqs(minind); |
| verboseprintf(g.verbose, 'Adjust max freq. to %3.2f Hz to match FFT output frequencies\n', g.freqs(2)); |
| end; |
| end; |
|
|
| |
| |
| g.nfreqs = length(tmpfreqs( intersect( find(tmpfreqs >= g.freqs(1)), find(tmpfreqs <= g.freqs(2))))); |
| if g.freqs(1)==g.freqs(2), g.nfreqs = 1; end; |
| end; |
|
|
| |
| |
| if strcmpi(g.freqscale, 'log') |
| g.freqs = linspace(log(g.freqs(1)), log(g.freqs(end)), g.nfreqs); |
| g.freqs = exp(g.freqs); |
| else |
| g.freqs = linspace(g.freqs(1), g.freqs(2), g.nfreqs); |
| |
| end; |
| end; |
| g.nfreqs = length(g.freqs); |
|
|
| |
| |
| if (g.cycles(1) == 0) |
| freqs = linspace(0, srate/2, g.winsize*g.padratio/2+1); |
| freqs = freqs(2:end); |
| |
| verboseprintf(g.verbose, 'Using %s FFT tapering\n', g.ffttaper); |
| switch g.ffttaper |
| case 'hanning', g.win = hanning(g.winsize); |
| case 'hamming', g.win = hamming(g.winsize); |
| case 'blackmanharris', g.win = blackmanharris(g.winsize); |
| case 'none', g.win = ones(g.winsize,1); |
| end; |
| else |
| |
| |
|
|
| freqs = g.freqs; |
| if length(g.cycles) == 2 |
| if g.cycles(2) < 1 |
| g.cycles = [ g.cycles(1) g.cycles(1)*g.freqs(end)/g.freqs(1)*(1-g.cycles(2))]; |
| end |
| verboseprintf(g.verbose, 'Using %g cycles at lowest frequency to %g at highest.\n', g.cycles(1), g.cycles(2)); |
| elseif length(g.cycles) == 1 |
| verboseprintf(g.verbose, 'Using %d cycles at all frequencies.\n',g.cycles); |
| else |
| verboseprintf(g.verbose, 'Using user-defined cycle for each frequency\n'); |
| end |
| if strcmp(g.wletmethod, 'dftfilt2') |
| g.win = dftfilt2(g.freqs,g.cycles,srate, g.freqscale); |
| elseif strcmp(g.wletmethod, 'dftfilt3') |
| g.win = dftfilt3(g.freqs,g.cycles,srate, 'cycleinc', g.freqscale); |
| else return |
| end |
| g.winsize = 0; |
| for index = 1:length(g.win) |
| g.winsize = max(g.winsize,length(g.win{index})); |
| end; |
| end; |
|
|
| |
| |
| [ g.timesout g.indexout ] = gettimes(frame, g.tlimits, g.timesout, g.winsize, g.ntimesout, g.causal, g.verbose); |
|
|
| |
| |
| |
| verboseprintf(g.verbose, 'The window size used is %d samples (%g ms) wide.\n',g.winsize, 1000/srate*g.winsize); |
| if strcmpi(g.freqscale, 'log') |
| scaletoprint = 'log'; |
| else scaletoprint = 'linear'; |
| end |
| verboseprintf(g.verbose, 'Estimating %d %s-spaced frequencies from %2.1f Hz to %3.1f Hz.\n', length(g.freqs), ... |
| scaletoprint, g.freqs(1), g.freqs(end)); |
| |
| |
|
|
| if g.cycles(1) == 0 |
| if 1 |
| |
| |
| indices = repmat([-g.winsize/2+1:g.winsize/2]', [1 length(g.indexout) trials]); |
| indices = indices + repmat(g.indexout, [size(indices,1) 1 trials]); |
| indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,trials), [size(indices,1) length(g.indexout) 1]); |
| if chan > 1 |
| tmpall = repmat(nan,[chan length(freqs) length(g.timesout) trials]); |
| tmpX = reshape(data(:,indices), [ size(data,1) size(indices)]); |
| tmpX = bsxfun(@minus, tmpX, mean( tmpX, 2)); % avoids repmat - faster than tmpX = tmpX - repmat(mean(tmpX), [size(tmpX,1) 1 1]); |
| tmpX = bsxfun(@times, tmpX, g.win'); |
| tmpX = fft(tmpX,g.padratio*g.winsize,2); |
| tmpall = squeeze(tmpX(:,2:g.padratio*g.winsize/2+1,:,:)); |
| else |
| tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]); |
| tmpX = data(indices); |
| tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1)); |
| tmpX = bsxfun(@times, tmpX, g.win); |
| |
| |
| tmpX = fft(tmpX,g.padratio*g.winsize); |
| tmpall = tmpX(2:g.padratio*g.winsize/2+1,:,:); |
| end; |
| else |
| tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]); |
| verboseprintf(g.verbose, 'Processing trial (of %d):',trials); |
| for trial = 1:trials |
| if rem(trial,10) == 0, verboseprintf(g.verbose, ' %d',trial); end |
| if rem(trial,120) == 0, verboseprintf(g.verbose, '\n'); end |
| for index = 1:length(g.indexout) |
| if strcmpi(g.causal, 'off') |
| tmpX = data([-g.winsize/2+1:g.winsize/2]+g.indexout(index)+(trial-1)*frame); |
| else |
| tmpX = data([-g.winsize+1:0]+g.indexout(index)+(trial-1)*frame); |
| end; |
|
|
| tmpX = tmpX - mean(tmpX); |
| if strcmpi(g.detrend, 'on'), |
| tmpX = detrend(tmpX); |
| end; |
|
|
| tmpX = g.win .* tmpX(:); |
| tmpX = fft(tmpX,g.padratio*g.winsize); |
| tmpX = tmpX(2:g.padratio*g.winsize/2+1); |
| tmpall(:,index, trial) = tmpX(:); |
| end; |
| end; |
| end; |
| else |
| if chan > 1 |
| |
| |
| |
| |
| tmpall = repmat(nan,[chan length(freqs) length(g.timesout) trials]); |
| wt = [ 1 find(diff(cellfun(@length,g.win)))+1 length(g.win)+1]; |
| verboseprintf(g.verbose, 'Computing of %d:', length(wt)); |
| for ind = 1:length(wt)-1 |
| verboseprintf(g.verbose, '.'); |
| wavarray = reshape([ g.win{wt(ind):wt(ind+1)-1} ], [ length(g.win{wt(ind)}) wt(ind+1)-wt(ind) ]); |
| sizewav = size(wavarray,1)-1; |
| indices = repmat([-sizewav/2:sizewav/2]', [1 size(wavarray,2) length(g.indexout) trials]); |
| indices = indices + repmat(reshape(g.indexout, 1,1,length(g.indexout)), [size(indices,1) size(indices,2) 1 trials]); |
| indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,1,trials), [size(indices,1) size(indices,2) size(indices,3) 1]); |
| szfreqdata = [ size(data,1) size(indices) ]; |
| tmpX = reshape(data(:,indices), szfreqdata); |
| tmpX = bsxfun(@minus, tmpX, mean( tmpX, 2)); % avoids repmat - faster than tmpX = tmpX - repmat(mean(tmpX), [size(tmpX,1) 1 1]); |
| wavarray = reshape(wavarray, [1 size(wavarray,1) size(wavarray,2)]); |
| tmpall(:,wt(ind):wt(ind+1)-1,:,:,:) = reshape(sum(bsxfun(@times, tmpX, wavarray),2), [szfreqdata(1) szfreqdata(3:end)]); |
| end; |
| verboseprintf(g.verbose, '\n'); |
| %tmpall = squeeze(tmpall(1,:,:,:)); |
| elseif 0 |
| tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]); |
| % wavelets are processed in groups of the same size |
| % to speed up computation. Wavelet of groups of different size |
| % can be processed together but at a cost of a lot of RAM and |
| % a lot of extra computation -> not faster than the regular |
| % iterative method |
| wt = [ 1 find(diff(cellfun(@length,g.win)))+1 length(g.win)+1]; |
| for ind = 1:length(wt)-1 |
| wavarray = reshape([ g.win{wt(ind):wt(ind+1)-1} ], [ length(g.win{wt(ind)}) wt(ind+1)-wt(ind) ]); |
| sizewav = size(wavarray,1)-1; |
| indices = repmat([-sizewav/2:sizewav/2]', [1 size(wavarray,2) length(g.indexout) trials]); |
| indices = indices + repmat(reshape(g.indexout, 1,1,length(g.indexout)), [size(indices,1) size(indices,2) 1 trials]); |
| indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,1,trials), [size(indices,1) size(indices,2) size(indices,3) 1]); |
| tmpX = data(indices); |
| tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1)); |
| tmpall(wt(ind):wt(ind+1)-1,:,:) = squeeze(sum(bsxfun(@times, tmpX, wavarray),1)); |
| end; |
| elseif 0 |
| |
| |
| tmpall = repmat(nan,[length(freqs) length(g.timesout) trials]); |
| sizewav = length(g.win{1})-1; |
| mainc = sizewav/2; |
| indices = repmat([-sizewav/2:sizewav/2]', [1 length(g.indexout) trials]); |
| indices = indices + repmat(g.indexout, [size(indices,1) 1 trials]); |
| indices = indices + repmat(reshape(([1:trials]-1)*frame,1,1,trials), [size(indices,1) length(g.indexout) 1]); |
| |
| for freqind = 1:length(g.win) |
| winc = (length(g.win{freqind})-1)/2; |
| wins = length(g.win{freqind})-1; |
| wini = [-wins/2:wins/2]+winc+mainc-winc+1; |
| tmpX = data(indices(wini,:,:)); |
| tmpX = bsxfun(@minus, tmpX, mean( tmpX, 1)); % avoids repmat - faster than tmpX = tmpX - repmat(mean(tmpX), [size(tmpX,1) 1 1]); |
| tmpX = sum(bsxfun(@times, tmpX, g.win{freqind}'),1); |
| tmpall(freqind,:,:) = tmpX; |
| end; |
| else |
| |
| |
| for index = 1:length(g.win) |
| g.win{index} = transpose(repmat(g.win{index}, [trials 1])); |
| end; |
|
|
| |
| |
| verboseprintf(g.verbose, 'Processing time point (of %d):',length(g.timesout)); |
| tmpall = zeros(length(g.win), length(g.indexout), size(data,2)); |
| for index = 1:length(g.indexout) |
| if rem(index,10) == 0, verboseprintf(g.verbose, ' %d',index); end |
| if rem(index,120) == 0, verboseprintf(g.verbose, '\n'); end |
| for freqind = 1:length(g.win) |
| wav = g.win{freqind}; |
| sizewav = size(wav,1)-1; |
| |
| if strcmpi(g.causal, 'off') |
| tmpX = data([-sizewav/2:sizewav/2]+g.indexout(index),:); |
| else |
| tmpX = data([-sizewav:0]+g.indexout(index),:); |
| end; |
|
|
| tmpX = tmpX - ones(size(tmpX,1),1)*mean(tmpX); |
| if strcmpi(g.detrend, 'on'), |
| for trial = 1:trials |
| tmpX(:,trial) = detrend(tmpX(:,trial)); |
| end; |
| end; |
|
|
| tmpX = sum(wav .* tmpX); |
| tmpall( freqind, index, :) = tmpX; |
| end; |
| end; |
| end; |
| end; |
| verboseprintf(g.verbose, '\n'); |
|
|
| |
| |
| if ~isempty(g.timestretch) && length(g.timestretch{1}) > 0 |
|
|
| timemarks = g.timestretch{1}'; |
| if isempty(g.timestretch{2}) | length(g.timestretch{2}) == 0 |
| timerefs = median(g.timestretch{1}',2); |
| else |
| timerefs = g.timestretch{2}; |
| end |
| trials = size(tmpall,3); |
|
|
| |
| |
|
|
| [dummy refsPos] = min(transpose(abs( ... |
| repmat(timerefs, [1 length(g.indexout)]) - repmat(g.indexout, [length(timerefs) 1])))); |
| refsPos(end+1) = 1; |
| refsPos(end+1) = length(g.indexout); |
| refsPos = sort(refsPos); |
|
|
| for t=1:trials |
|
|
| |
| |
|
|
| |
|
|
| outOfTimeRangeTimeWarpMarkers = find(timemarks(:,t) < min(g.indexout) | timemarks(:,t) > max(g.indexout)); |
| |
| |
| |
| |
| |
| [dummy marksPos] = min(transpose( ... |
| abs( ... |
| repmat(timemarks(:,t), [1 length(g.indexout)]) ... |
| - repmat(g.indexout, [size(timemarks,1) 1]) ... |
| ) ... |
| )); |
| |
|
|
| marksPos(end+1) = 1; |
| marksPos(end+1) = length(g.indexout); |
| marksPos = sort(marksPos); |
|
|
| |
| mytmpall = tmpall(:,:,t); |
| r = sqrt(mytmpall.*conj(mytmpall)); |
| theta = angle(mytmpall); |
|
|
| |
| |
|
|
| M = timewarp(marksPos, refsPos); |
| |
| TSr = transpose(M*r'); |
| TStheta = zeros(size(theta,1), size(theta,2)); |
| |
| for freqInd=1:size(TStheta,1) |
| TStheta(freqInd, :) = angtimewarp(marksPos, refsPos, theta(freqInd, :)); |
| end |
| TStmpall = TSr.*exp(i*TStheta); |
| |
| % $$$ keyboard; |
| |
| tmpall(:,:,t) = TStmpall; |
| end |
| end |
| %time-warp ends |
| zerovals = tmpall == 0; |
| if any(reshape(zerovals, 1, prod(size(zerovals)))) |
| tmpall(zerovals) = Inf; |
| minval = min(tmpall(:)); % remove bug |
| tmpall(zerovals) = minval; |
| end; |
| |
| % compute and subtract ITC |
| % ------------------------ |
| if nargout > 3 || strcmpi(g.subitc, 'on') |
| itcvals = tfitc(tmpall, g.itctype); |
| end; |
| if strcmpi(g.subitc, 'on') |
| %a = gcf; figure; imagesc(abs(itcvals)); cbar; figure(a); |
| if ndims(tmpall) <= 3 |
| tmpall = (tmpall - abs(tmpall) .* repmat(itcvals, [1 1 trials])) ./ abs(tmpall); |
| else tmpall = (tmpall - abs(tmpall) .* repmat(itcvals, [1 1 1 trials])) ./ abs(tmpall); |
| end; |
| end; |
| |
| % find closest output frequencies |
| % ------------------------------- |
| if length(g.freqs) ~= length(freqs) || any(g.freqs ~= freqs) |
| allindices = zeros(1,length(g.freqs)); |
| for index = 1:length(g.freqs) |
| [dum ind] = min(abs(freqs-g.freqs(index))); |
| allindices(index) = ind; |
| end; |
| verboseprintf(g.verbose, 'finding closest frequencies: |
| freqs = freqs(allindices); |
| if ndims(tmpall) <= 3 |
| tmpall = tmpall(allindices,:,:); |
| else tmpall = tmpall(:,allindices,:,:); |
| end; |
| if nargout > 3 | strcmpi(g.subitc, 'on') |
| if ndims(tmpall) <= 3 |
| itcvals = itcvals(allindices,:,:); |
| else itcvals = itcvals(:,allindices,:,:); |
| end; |
| end; |
| end; |
|
|
| timesout = g.timesout; |
|
|
| |
| return; |
|
|
| |
| |
| function [itcvals] = tfitc(tfdecomp, itctype); |
| |
| nd = max(3,ndims(tfdecomp)); |
| switch itctype |
| case 'coher', |
| try, |
| itcvals = sum(tfdecomp,nd) ./ sqrt(sum(tfdecomp .* conj(tfdecomp),nd) * size(tfdecomp,nd)); |
| catch, |
| for index =1:size(tfdecomp,1) |
| itcvals(index,:,:) = sum(tfdecomp(index,:,:,:),nd) ./ sqrt(sum(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:)),nd) * size(tfdecomp,nd)); |
| end; |
| end; |
| case 'phasecoher2', |
| try, |
| itcvals = sum(tfdecomp,nd) ./ sum(sqrt(tfdecomp .* conj(tfdecomp)),nd); |
| catch, |
| for index =1:size(tfdecomp,1) |
| itcvals(index,:,:) = sum(tfdecomp(index,:,:,:),nd) ./ sum(sqrt(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:))),nd); |
| end; |
| end; |
| case 'phasecoher', |
| try, |
| itcvals = sum(tfdecomp ./ sqrt(tfdecomp .* conj(tfdecomp)) ,nd) / size(tfdecomp,nd); |
| catch, |
| for index =1:size(tfdecomp,1) |
| itcvals(index,:,:) = sum(tfdecomp(index,:,:,:) ./ sqrt(tfdecomp(index,:,:,:) .* conj(tfdecomp(index,:,:,:))) ,nd) / size(tfdecomp,nd); |
| end; |
| end; |
| end |
| return; |
|
|
| function w = hanning(n) |
| if ~rem(n,2) |
| w = .5*(1 - cos(2*pi*(1:n/2)'/(n+1))); |
| w = [w; w(end:-1:1)]; |
| else |
| w = .5*(1 - cos(2*pi*(1:(n+1)/2)'/(n+1))); |
| w = [w; w(end-1:-1:1)]; |
| end |
|
|
| |
| |
| function [ timevals, timeindices ] = gettimes(frames, tlimits, timevar, winsize, ntimevar, causal, verbose); |
| timevect = linspace(tlimits(1), tlimits(2), frames); |
| srate = 1000*(frames-1)/(tlimits(2)-tlimits(1)); |
|
|
| if isempty(timevar) |
| if ntimevar(1) > 0 |
| |
| |
| if (ntimevar > frames-winsize) |
| ntimevar = frames-winsize; |
| if ntimevar < 0 |
| error('Not enough data points, reduce the window size or lowest frequency'); |
| end; |
| verboseprintf(verbose, ['Value of ''timesout'' must be <= frame-winsize, ''timesout'' adjusted to ' int2str(ntimevar) '\n']); |
| end |
| npoints = ntimevar(1); |
| wintime = 500*winsize/srate; |
| if strcmpi(causal, 'on') |
| timevals = linspace(tlimits(1)+2*wintime, tlimits(2), npoints); |
| else timevals = linspace(tlimits(1)+wintime, tlimits(2)-wintime, npoints); |
| end; |
| verboseprintf(verbose, 'Generating %d time points (%1.1f to %1.1f ms)\n', npoints, min(timevals), max(timevals)); |
| else |
| |
| |
| nsub = -ntimevar(1); |
| if strcmpi(causal, 'on') |
| timeindices = [ceil(winsize+nsub):nsub:length(timevect)]; |
| else timeindices = [ceil(winsize/2+nsub/2):nsub:length(timevect)-ceil(winsize/2)-1]; |
| end; |
| timevals = timevect( timeindices ); |
| verboseprintf(verbose, 'Subsampling by %d (%1.1f to %1.1f ms)\n', nsub, min(timevals), max(timevals)); |
| end; |
| else |
| timevals = timevar; |
| |
| |
| wintime = 500*winsize/srate; |
| if strcmpi(causal, 'on') |
| tmpind = find( (timevals >= tlimits(1)+2*wintime-0.0001) & (timevals <= tlimits(2)) ); |
| else tmpind = find( (timevals >= tlimits(1)+wintime-0.0001) & (timevals <= tlimits(2)-wintime+0.0001) ); |
| end; |
| |
| if isempty(tmpind) |
| error('No time points. Reduce time window or minimum frequency.'); |
| end; |
| if length(timevals) ~= length(tmpind) |
| verboseprintf(verbose, 'Warning: %d out of %d time values were removed (now %3.2f to %3.2f ms) so the lowest\n', ... |
| length(timevals)-length(tmpind), length(timevals), timevals(tmpind(1)), timevals(tmpind(end))); |
| verboseprintf(verbose, ' frequency could be computed with the requested accuracy\n'); |
| end; |
| timevals = timevals(tmpind); |
| end; |
|
|
| |
| |
| timeindices = round(eeg_lat2point(timevals, 1, srate, tlimits, 1E-3)); |
| if length(timeindices) < length(unique(timeindices)) |
| timeindices = unique_bc(timeindices) |
| verboseprintf(verbose, 'Warning: duplicate times, reduce the number of output times\n'); |
| end; |
| if length(unique(timeindices(2:end)-timeindices(1:end-1))) > 1 |
| verboseprintf(verbose, 'Finding closest points for time variable\n'); |
| verboseprintf(verbose, 'Time values for time/freq decomposition is not perfectly uniformly distributed\n'); |
| else |
| verboseprintf(verbose, 'Distribution of data point for time/freq decomposition is perfectly uniform\n'); |
| end; |
| timevals = timevect(timeindices); |
|
|
| |
| function nofunction() |
| |
| 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 = []; |
|
|
| function verboseprintf(verbose, varargin) |
| if strcmpi(verbose, 'on') |
| fprintf(varargin{:}); |
| end; |
|
|
|
|