Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified doc/Tests_Current_Status.docx
Binary file not shown.
4 changes: 2 additions & 2 deletions src/pspm_cfg/pspm_cfg_convert_cardiac.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@
limit_upper.strtype = 'r';
limit_upper.num = [1 1];
limit_upper.val = {2};
limit_upper.help = pspm_cfg_help_format('pspm_convert_hb2hp', 'options.upper');
limit_upper.help = pspm_cfg_help_format('pspm_convert_hb2hp', 'options.limit_upper');

limit_lower = cfg_entry;
limit_lower.name = 'Lower limit';
limit_lower.tag = 'lower';
limit_lower.strtype = 'r';
limit_lower.num = [1 1];
limit_lower.val = {.2};
limit_lower.help = pspm_cfg_help_format('pspm_convert_hb2hp', 'options.lower');
limit_lower.help = pspm_cfg_help_format('pspm_convert_hb2hp', 'options.limit_lower');

limit = cfg_branch;
limit.name = 'Limit';
Expand Down
4 changes: 2 additions & 2 deletions src/pspm_cfg/pspm_cfg_ecg_editor.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
%% Limits
lim = cfg_branch;
lim.name = 'Limit';
lim.tag = 'limit';
lim.tag = 'limits';
lim.val = {ulim, llim};
lim.help = pspm_cfg_help_format('pspm_ecg_editor', 'options.limits');

Expand All @@ -58,7 +58,7 @@
factor.tag = 'factor';
factor.strtype = 'r';
factor.num = [1 1];
factor.val = {2};
factor.val = {1};
factor.help = pspm_cfg_help_format('pspm_ecg_editor', 'options.factor');

%% Faulty detection
Expand Down
3 changes: 2 additions & 1 deletion src/pspm_cfg/pspm_cfg_run_convert_cardiac.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
sr = job.pp_type{i}.hb2hp.sr;
options = struct();
options.channel = chan;
options.limit = job.pp_type{i}.hb2hp.limit;
options.limit_lower = job.pp_type{i}.hb2hp.limit.lower; % same convention as in pspm_options
options.limit_upper = job.pp_type{i}.hb2hp.limit.upper;
options = pspm_update_struct(options, job, 'channel_action');
[sts, outchannel] = pspm_convert_hb2hp(fn, sr, options);
case 'ecg2hp'
Expand Down
15 changes: 11 additions & 4 deletions src/pspm_cfg/pspm_cfg_run_ecg_editor.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
function pspm_cfg_run_ecg_editor(job)
% Updated on 18-12-2023 by Teddy
% Updated on 12-04-2026 by Bernhard von Raußendorf

options = struct();
fn = job.datafile{1};
ecg_chan = pspm_cfg_selector_channel('run', job.ecg_chan);
options.channel = pspm_cfg_selector_channel('run', job.hb_chan);
if isfield(job.artefact_epochs, 'artefact_file')
options.missing = job.artefact_epochs.artefact_file{1};
else
options.missing = 0;
options.missing = [];
end
options = pspm_update_struct(options, job.faulty_settings, {'factor',...
'limit.upper',...
'limit.lower'});

% options = pspm_update_struct(options, job.faulty_settings, {'factor',...
% 'limit.upper',...
% 'limit.lower'});

options = pspm_update_struct(options, job.faulty_settings, {'factor'});
options.limits = pspm_update_struct(options, job.faulty_settings.limits, {'upper','lower'});

pspm_ecg_editor(fn, ecg_chan, options);
2 changes: 1 addition & 1 deletion src/pspm_cfg/pspm_cfg_selector_channel_action.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
channel_action.values = {'add', 'replace'};
channel_action.labels = {'Add', 'Replace'};
channel_action.val = {'add'};
channel_action.help = {'Choose whether to add a new channel, or to replace the last existing channel of the same type and with the same units (if any).'};
channel_action.help = {'Choose whether to add a new channel, or to replace the processed channel.'};
23 changes: 15 additions & 8 deletions src/pspm_convert_au2unit.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
% input data if the recording method is area. This is performed to always
% return linear units.
% Using the given variables, the following calculations are performed:
% 0. Take square root of data if recording is 'area'.
% 0. Take 2*sqrt(data/pi) of data if recording is 'area'.
% 1. Let from unit to reference_unit converted recording distance be Dconv.
% 2. x ← A*(Dconv/Dref)*x
% 3. Convert x from ref_unit to unit.
Expand Down Expand Up @@ -163,25 +163,32 @@
[sts, channeldata, infos, pos_of_channel(i)] = pspm_load_channel(alldata, channel{i}, 'pupil');
if sts < 1, return; end
% recursive call to avoid the formula being stated twice in the same function
[sts, convert_data.data{i}] = pspm_convert_au2unit(channeldata.data, unit, distance, record_method, ...
[sts, convert_data{i}.data] = pspm_convert_au2unit(channeldata.data, unit, distance, record_method, ...
multiplicator, reference_distance, reference_unit, options);
if sts < 1, return; end
convert_data{i}.header = channeldata.header;
convert_data{i}.header.units = unit;
end
[f_sts, f_info] = pspm_write_channel(fn, convert_data, options.channel_action, struct('channel', pos_of_channel));
if f_sts < 1, return; end
[sts, f_info] = pspm_write_channel(fn, convert_data, options.channel_action, struct('channel', pos_of_channel));
if sts < 1, return; end
outchannel = f_info.channel;
% convert data
case 'data'
convert_data = data;
if strcmpi(record_method, 'area')
convert_data = sqrt(convert_data);
[f_sts, convert_data] = pspm_convert_area2diameter(convert_data);
if f_sts < 1, return; end
end
[~, distance] = pspm_convert_unit(distance, unit, reference_unit);

[f_sts, distance] = pspm_convert_unit(distance, unit, reference_unit);
if f_sts < 1, return; end
convert_data = multiplicator * (distance / reference_distance) * convert_data;

%% convert data from reference_unit to unit
[~, convert_data] = pspm_convert_unit(convert_data, reference_unit, unit);
[f_sts, convert_data] = pspm_convert_unit(convert_data, reference_unit, unit);
if f_sts < 1, return; end
outchannel = convert_data;
sts = 1;
end
sts = 1;

end
2 changes: 1 addition & 1 deletion src/pspm_convert_ecg2hb_amri.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
heartbeats{1}.header.chantype = 'hb';
heartbeats{1}.header.units = 'events';
o.msg.prefix = 'QRS detection using AMRI algorithm';
[lsts, infos] = pspm_write_channel(fn, heartbeats, options.channel_action);
[lsts, infos] = pspm_write_channel(fn, heartbeats, options.channel_action,o);
if lsts ~= 1; return; end
out_channel = infos.channel;
sts = 1;
10 changes: 5 additions & 5 deletions src/pspm_convert_hb2hp.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
% │ Specifies upper and lower limit for heart
% │ periods. If the limit is exceeded, the values will
% │ be ignored/removed and interpolated.
% ├─────────.upper: [numeric]
% ├───.limit_upper: [numeric]
% │ Specifies the upper limit of the
% │ heart periods in seconds. Default is 2.
% └─────────.lower: [numeric]
% └───.limit_lower: [numeric]
% Specifies the lower limit of the
% heart periods in seconds. Default is 0.2.
% ● Outputs
Expand Down Expand Up @@ -70,14 +70,14 @@
% get data
% -------------------------------------------------------------------------
[nsts, data, dinfos] = pspm_load_channel(fn, options.channel, 'hb');
if nsts == -1, return; end
if nsts < 1, return; end


% interpolate
% -------------------------------------------------------------------------
hb = data.data;
ibi = diff(hb);
idx = find(ibi > options.limit.lower & ibi < options.limit.upper);
idx = find(ibi > options.limit_lower & ibi < options.limit_upper);
hp = 1000 * ibi; % in ms
newt = (1/sr):(1/sr):dinfos.duration;
try
Expand All @@ -103,7 +103,7 @@
o.msg.prefix = 'Heart beat converted to heart period and';
try
[nsts,winfos] = pspm_write_channel(fn, newdata, options.channel_action, o);
if nsts == -1, return;
if nsts < 1, return;
end
catch
warning('ID:invalid_input', 'call of pspm_write_channel failed');
Expand Down
12 changes: 7 additions & 5 deletions src/pspm_convert_ppg2hb.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
% -------------------------------------------------------------------------
if nargin < 1
warning('ID:invalid_input', 'No input. Don''t know what to do.'); return;
elseif ~(ischar(fn) || isstruct(fn))
warning('ID:invalid_input', 'Need file name string or struct as first input.'); return;
elseif nargin < 2
options = struct();
options.channel = 'ppg';
Expand All @@ -84,7 +86,7 @@
% get data
% -------------------------------------------------------------------------
[nsts, data, infos, pos_of_channel] = pspm_load_channel(fn, options.channel, 'ppg');
if nsts == -1, return; end
if nsts < 1, return; end

ppg = data.data;
sr = data.header.sr;
Expand Down Expand Up @@ -245,13 +247,13 @@

write_options = struct();
write_options.msg = msg;
write_options.channel = pos_of_channel;
% write_options.channel = pos_of_channel;
write_options.channel = 0;

% Replace last existing channel or save as new channel
[nsts, nout] = pspm_write_channel(fn, newdata, options.channel_action, write_options);
if ~nsts
return
end
if nsts < 1; return; end

% user output
fprintf(' done.\n');
sts = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/pspm_write_channel.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
for iChannel = 1:numel(newdata)
warning off
[sts, ~, pos_of_channels] = pspm_select_channels(data, ...
newdata{iChannel}.header.chantype, newdata{iChannel}.header.units);
newdata{iChannel}.header.chantype);
warning on
if sts < 1
channeli(iChannel) = 0;
Expand All @@ -132,8 +132,7 @@
warning off
sts = pspm_select_channels( ...
data(options.channel(iChannel)), ...
newdata{iChannel}.header.chantype, ...
newdata{iChannel}.header.units);
newdata{iChannel}.header.chantype);
warning on
if sts < 1
channeli(iChannel) = 0;
Expand Down
20 changes: 20 additions & 0 deletions test/pspm_combine_markerchannels_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,25 @@ function test_combine_specific_channel_numbers(this)
this.verifyTrue(fstruct.numofchan == 7, 'the output has a different size');
delete(fn)
end
function test_combine_specific_channel_number_zero(this)
fn = pspm_find_free_fn(this.fn1, '.mat');
channels{1}.chantype = 'scr';
channels{2}.chantype = 'hb';
channels{3}.chantype = 'marker';
channels{4}.chantype = 'marker';
channels{5}.chantype = 'marker';
channels{6}.chantype = 'marker';
channels{7}.chantype = 'marker';
channels{8}.chantype = 'marker';
channels{9}.chantype = 'marker';
pspm_testdata_gen(channels, this.duration1, fn);
% test defaultly combining all marker channels
sts = pspm_combine_markerchannels(fn, struct('marker_chan_num', 0));
this.verifyTrue(sts == 1, 'the function run successfully');
[sts_out, ~, ~, fstruct] = pspm_load_data(fn, 'none');
this.verifyTrue(sts_out == 1, 'the processed file couldn''t be loaded');
this.verifyTrue(fstruct.numofchan == numel(channels)+1, 'the output has a different size');
delete(fn)
end
end
end
Loading
Loading