Commit d204fcaf authored by Julian Kosciessa's avatar Julian Kosciessa
Browse files

Merge branch 'bandpass'

parents c647b8f7 b6f9a130
...@@ -200,17 +200,21 @@ for s = 1:numel(timescales) % loop through timescales ...@@ -200,17 +200,21 @@ for s = 1:numel(timescales) % loop through timescales
case 'bp' case 'bp'
fs = data.fsample; fs = data.fsample;
nyquist = fs/2; nyquist = fs/2;
fcLowPass = (1/sc)*nyquist; fcLowPass = (1./sc).*nyquist + .05*((1./sc).*nyquist);
if fcLowPass == nyquist fcHighPass = (1./(sc+1)).*nyquist - .05*((1./(sc+1)).*nyquist);
fcLowPass = fcLowPass-1;
end if sc > 1 % don't define low-pass for first scale, as its upper frequency limit is specified anyway
if s == numel(timescales) if fcLowPass-fcHighPass > .05*nyquist
fcHighPass = 0.5; [B,A] = cheby1(4,1,fcLowPass/nyquist, 'low'); % define low-pass filter: https://de.mathworks.com/help/signal/ref/butter.html
[D,C] = cheby1(4,1,fcHighPass/nyquist,'high'); % define high-pass filter
else
[B,A]=butter(10,fcLowPass/nyquist, 'low'); % Lowpass
[D,C]=butter(10,fcHighPass/nyquist,'high'); % Highpass
end
else else
fcHighPass = (1/(timescales(s+1)))*nyquist; [D,C]= butter(10,fcHighPass/nyquist,'high'); % use Butterworth highpass
end fcLowPass = nyquist;
[B,A] = butter(6,fcLowPass/nyquist); % define low-pass filter: https://de.mathworks.com/help/signal/ref/butter.html end
[D,C] = butter(6,fcHighPass/nyquist, 'high'); % define high-pass filter
cfg.freq(1,s) = fcLowPass; cfg.freq(1,s) = fcLowPass;
cfg.freq(2,s) = fcHighPass; cfg.freq(2,s) = fcHighPass;
......
...@@ -165,34 +165,37 @@ for s = 1:numel(timescales) % loop through timescales ...@@ -165,34 +165,37 @@ for s = 1:numel(timescales) % loop through timescales
case 'bp' case 'bp'
fs = data.fsample; fs = data.fsample;
nyquist = fs/2; nyquist = fs/2;
fcLowPass = (1/sc)*nyquist; fcLowPass = (1./sc).*nyquist + .05*((1./sc).*nyquist);
if fcLowPass == nyquist fcHighPass = (1./(sc+1)).*nyquist - .05*((1./(sc+1)).*nyquist);
fcLowPass = fcLowPass-1;
end if sc > 1 % don't define low-pass for first scale, as its upper frequency limit is specified anyway
if s == numel(timescales) if fcLowPass-fcHighPass > .05*nyquist
fcHighPass = 0.5; [B,A] = cheby1(4,1,fcLowPass/nyquist, 'low'); % define low-pass filter: https://de.mathworks.com/help/signal/ref/butter.html
else [D,C] = cheby1(4,1,fcHighPass/nyquist,'high'); % define high-pass filter
fcHighPass = (1/(timescales(s+1)))*nyquist; else
end [B,A]=butter(10,fcLowPass/nyquist, 'low'); % Lowpass
[B,A] = butter(6,fcLowPass/nyquist); % define low-pass filter: https://de.mathworks.com/help/signal/ref/butter.html [D,C]=butter(10,fcHighPass/nyquist,'high'); % Highpass
[D,C] = butter(6,fcHighPass/nyquist, 'high'); % define high-pass filter end
else
[D,C]= butter(10,fcHighPass/nyquist,'high'); % use Butterworth highpass
fcLowPass = nyquist;
end
cfg.freq(1,s) = fcLowPass; cfg.freq(1,s) = fcLowPass;
cfg.freq(2,s) = fcHighPass; cfg.freq(2,s) = fcHighPass;
padlength = ceil(size(data.trial{1},2)./2); % use half the length of trial 1 as padding (JQK) padlength = ceil(size(data.trial{1},2)./2); % use half the length of trial 1 as padding (JQK)
x_pad = cellfun(@(a) ft_preproc_padding(a, 'mean', padlength), data.trial, 'UniformOutput', false ); % add padding x_pad = cellfun(@(a) ft_preproc_padding(a, 'mean', padlength), data.trial, 'UniformOutput', false ); % add padding
x_pad = cellfun(@transpose, x_pad, 'UniformOutput', false); % transpose for filtfilt: time x chan x_pad = cellfun(@transpose, x_pad, 'UniformOutput', false); % transpose for filtfilt: time x chan
resamp_x_pad = cellfun(@(x_pad) filtfilt(B,A,x_pad), x_pad, 'UniformOutput', false ); % low-pass filter data
if sc == 1 % only HPF if sc == 1 % only HPF
resamp_x_pad = cellfun(@(x_pad) filtfilt(D,C,x_pad), x_pad, 'UniformOutput', false ); % high-pass filter data resamp_x_pad = cellfun(@(x_pad) filtfilt(D,C,x_pad), x_pad, 'UniformOutput', false ); % high-pass filter data
else else % sequential application of low-pass and high-pass filter
resamp_x_pad = cellfun(@(x_pad) filtfilt(B,A,x_pad), x_pad, 'UniformOutput', false ); % low-pass filter data resamp_x_pad = cellfun(@(x_pad) filtfilt(B,A,x_pad), x_pad, 'UniformOutput', false ); % low-pass filter data
resamp_x_pad = cellfun(@(resamp_x_pad) filtfilt(D,C,resamp_x_pad), resamp_x_pad, 'UniformOutput', false ); % high-pass filter data resamp_x_pad = cellfun(@(resamp_x_pad) filtfilt(D,C,resamp_x_pad), resamp_x_pad, 'UniformOutput', false ); % high-pass filter data
end end
resamp_x_pad = cellfun(@transpose, resamp_x_pad, 'UniformOutput', false); % transpose back : chan x time again resamp_x_pad = cellfun(@transpose, resamp_x_pad, 'UniformOutput', false); % transpose back : chan x time again
resamp_x = cellfun(@(resamp_x_pad) ft_preproc_padding(resamp_x_pad, 'remove', padlength), ... % remove padding resamp_x = cellfun(@(resamp_x_pad) ft_preproc_padding(resamp_x_pad, 'remove', padlength), ... % remove padding
resamp_x_pad, 'UniformOutput', false ); resamp_x_pad, 'UniformOutput', false );
%figure; hold on; plot(resamp_x{1}(1,:)); plot(data.trial{1}(1,:)) %figure; hold on; plot(resamp_x{1}(15,:)); plot(data.trial{1}(15,:))
% create data_filt structure % create data_filt structure
data_filt = data; data_filt = data;
data_filt.trial = resamp_x; data_filt.trial = resamp_x;
...@@ -259,7 +262,7 @@ for s = 1:numel(timescales) % loop through timescales ...@@ -259,7 +262,7 @@ for s = 1:numel(timescales) % loop through timescales
end end
clear resamp_x; clear resamp_x;
case 'pointavg' % original point averaging coarse graining, no loop over starting points 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 cg_data{1} = data_sel.trial; %only keep trial data
nloops = 1; % no loop across starting points nloops = 1; % no loop across starting points
else % coarse-grain time series at this time scale else % coarse-grain time series at this time scale
......
File mode changed from 100644 to 100755
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