Commit 758633dc authored by Julian Kosciessa's avatar Julian Kosciessa
Browse files

Update old HPF sections from JQK into NAK's code

parents 0f34b119 467916ec
......@@ -127,6 +127,10 @@ filtmethod = ft_getopt(cfg, 'filtmethod', 'lp');
mem_available = ft_getopt(cfg, 'mem_available', 8e9); % 8 GB
allowgpu = ft_getopt(cfg, 'allowgpu', 1); % 8 GB
if strcmp(cfg.coarsegrainmethod, 'pointavg')
filtmethod = 'no'; % no filtering for point averaging
end
gpuavailable = gpuDeviceCount;
if allowgpu && gpuavailable
fprintf('GPU device found. Running things there\n')
......@@ -316,29 +320,22 @@ for s = 1:numel(timescales) % loop through timescales
nchan = size(data_sel.trial{1},1);
end
% do point skipping for scales > 1, non-HP option
% do point skipping
cg_data = {};
switch coarsegrainmethod
case 'filtskip'
if strcmp(filtmethod, 'hp')
nloops = 1; % keep original sampling rate
stepSize = 1;
else
nloops = sc;
stepSize = sc;
end
cg_data = cell(nloops,1); % make cell: cg_data{istart}{trials}(chan-by-time)
resamp_x = data_sel.trial;
for is = 1:nloops % loop over starting points here!
cg_data{is} = cellfun(@(resamp_x) resamp_x(:, is:(stepSize-1+1):end), resamp_x, 'UniformOutput', false ); % downsample data
cg_data{is} = cellfun(@(resamp_x) resamp_x(:, is:(sc-1+1):end), resamp_x, 'UniformOutput', false ); % add padding% Filter
end
clear resamp_x;
case 'pointavg' % original point averaging coarse graining, no loop over starting points
if sc == 1 || strcmp(filtmethod, 'hp') % no coarse graining for native sampling rate or high-pass entropy
nloops = 1; % no starting points loop for point avg
if sc == 1 % no coarse graining for native sampling rate
cg_data{1} = data_sel.trial; %only keep trial data
nloops = 1; % no loop across starting points
else % coarse-grain time series at this time scale
nloops = 1; % no loop across starting points
nchan = size(data_sel.trial{1},1);
for itrial = 1:length(data_sel.trial)
num_cg_tpts = floor(length(data_sel.trial{itrial})/sc); % number of coarse-grained time points
......@@ -385,10 +382,20 @@ for s = 1:numel(timescales) % loop through timescales
% keep the estimated r parameter
r_estimate(:, s, itoi, istart) = r_new; % dimord chan nsc ntoi nstartingpts
% chunk y to keep memory usage in check
max_numel = mem_available/4; % single = 4 bytes
chunk_size = round(max_numel/numel(y));
% chunk y to keep memory usage in check OLD
% max_numel = mem_available/4; % single = 4 bytes
% chunk_size = round(max_numel/numel(y));
% n_chunks = ceil(size(y,2)/chunk_size);
% chunk y to keep memory usage in check NEW
num_avail_netto = mem_available * 1/4 - numel(y) - numel(r_new) - numel(trl_mask); % save space for y itself, cont?
% max_numel = num_avail_netto/4; % single = 4 bytes
if num_avail_netto > intmax('int32') && allowgpu && gpuavailable % max numel allowed on gpu
num_avail_netto = double(intmax('int32') - numel(y) - numel(r_new));
end
chunk_size = floor(num_avail_netto / numel(y));
n_chunks = ceil(size(y,2)/chunk_size);
n_chunks = ceil((size(y,2)+n_chunks)/chunk_size); % account for needed overlap
temp = 1;
chunk_borders = zeros(n_chunks,2);
for ic = 1:n_chunks
......
......@@ -246,25 +246,18 @@ for s = 1:numel(timescales) % loop through timescales
break % subsequent time points will also not work
end
% do point skipping for scales > 1, non-HP option
cg_data = {};
switch coarsegrainmethod
case 'filtskip'
if strcmp(filtmethod, 'hp')
nloops = 1; % keep original sampling rate for hp option
stepSize = 1;
else
nloops = sc;
stepSize = sc;
end
cg_data = cell(nloops,1); % make cell: cg_data{istart}{trials}(chan-by-time)
for is = 1:nloops % loop over starting points here!
resamp_x = data_sel.trial;
cg_data{is} = cellfun(@(resamp_x) resamp_x(:, is:(stepSize-1+1):end), resamp_x, 'UniformOutput', false ); % add padding% Filter
cg_data{is} = cellfun(@(resamp_x) resamp_x(:, is:(sc-1+1):end), resamp_x, 'UniformOutput', false ); % add padding% Filter
end
clear resamp_x;
case 'pointavg' % original point averaging coarse graining, no loop over starting points
if sc == 1 || strcmp(filtmethod, 'hp') % no coarse graining for native sampling rate or high-pass entropy
if sc == 1 % no coarse graining for native sampling rate
cg_data{1} = data_sel.trial; %only keep trial data
nloops = 1; % no loop across starting points
else % coarse-grain time series at this time scale
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment