diff --git a/.github/workflows/clone.yml b/.github/workflows/clone.yml
new file mode 100644
index 00000000..239b0999
--- /dev/null
+++ b/.github/workflows/clone.yml
@@ -0,0 +1,63 @@
+name: Clone Count Update
+
+on:
+ schedule:
+ - cron: "10 0 * * SUN"
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+ with:
+ ref: clone_count
+
+ - name: gh login
+ run: echo "${{ secrets.SECRET_TOKEN }}" | gh auth login --with-token
+
+ - name: parse latest clone count
+ run: |
+ curl --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
+ -H "Accept: application/vnd.github.v3+json" \
+ https://api.github.com/repos/${{ github.repository }}/traffic/clones \
+ > clone.json
+
+ - name: create gist and download previous count
+ id: set_id
+ run: |
+ if gh secret list | grep -q "GIST_ID"
+ then
+ echo "GIST_ID found"
+ echo "GIST=${{ secrets.GIST_ID }}" >> $GITHUB_OUTPUT
+ curl https://gist.githubusercontent.com/${{ github.actor }}/${{ secrets.GIST_ID }}/raw/clone.json > clone_before.json
+ if cat clone_before.json | grep '404: Not Found'; then
+ echo "GIST_ID not valid anymore. Creating another gist..."
+ gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')
+ echo $gist_id | gh secret set GIST_ID
+ echo "GIST=$gist_id" >> $GITHUB_OUTPUT
+ cp clone.json clone_before.json
+ git rm --ignore-unmatch CLONE.md
+ fi
+ else
+ echo "GIST_ID not found. Creating a gist..."
+ gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')
+ echo $gist_id | gh secret set GIST_ID
+ echo "GIST=$gist_id" >> $GITHUB_OUTPUT
+ cp clone.json clone_before.json
+ fi
+
+ - name: update clone.json
+ run: |
+ curl https://raw.githubusercontent.com/MShawon/github-clone-count-badge/master/main.py > main.py
+ python3 main.py
+
+ - name: Update gist with latest count
+ run: |
+ content=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "clone.json" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
+ echo '{"description": "${{ github.repository }} clone statistics", "files": {"clone.json": {"content": "'"$content"'"}}}' > post_clone.json
+ curl -s -X PATCH \
+ --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
+ -H "Content-Type: application/json" \
+ -d @post_clone.json https://api.github.com/gists/${{ steps.set_id.outputs.GIST }} > /dev/null 2>&1
\ No newline at end of file
diff --git a/PhysIO/examples/tapas_physio_example_bids_cpulse3t_spm_job.m b/PhysIO/examples/tapas_physio_example_bids_cpulse3t_spm_job.m
new file mode 100644
index 00000000..84e3314e
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_bids_cpulse3t_spm_job.m
@@ -0,0 +1,39 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'BIDS';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'sub-s998_task-random_run-99_physio.tsv'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {''};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = [];
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'first';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 16;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 1.45;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 474;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 9;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = 0.090625;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.load_from_logfile = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.05 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.yes.method = 'hilbert';
+matlabbatch{1}.spm.tools.physio.model.rvt.yes.delays = 0;
+matlabbatch{1}.spm.tools.physio.model.hrv.yes.delays = 0;
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = 'physio.jpeg';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_bids_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_bids_ppu3t_spm_job.m
new file mode 100644
index 00000000..a16245db
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_bids_ppu3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'BIDS';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'sub-s999_task-random_run-99_physio.tsv.gz'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {''};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'first';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 16;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 1.45;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 408;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 9;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_biopac_txt_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_biopac_txt_ppu3t_spm_job.m
new file mode 100644
index 00000000..8d60c7c9
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_biopac_txt_ppu3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Biopac_Txt';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'Biopac_Physio_Data_Export.txt'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'Biopac_Physio_Data_Export.txt'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {'Biopac_Physio_Data_Export.txt'};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 36;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 3;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 100;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 18;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'ECG';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_ge_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_ge_ppu3t_spm_job.m
new file mode 100644
index 00000000..a2a900b8
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_ge_ppu3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'GE';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'ECGData_epiRT_phys_0921201215_38_08'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'RespData_epiRT_phys_0921201215_38_08'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = 0.025;
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 35;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = 35;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 1.925;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 434;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 17;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.nominal = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_multi_subjects.m b/PhysIO/examples/tapas_physio_example_multi_subjects.m
new file mode 100644
index 00000000..e76a5ef7
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_multi_subjects.m
@@ -0,0 +1,82 @@
+% Script tapas_physio_example_multi_subjects(input)
+% Shows how to generalize single-subject batch for all subjects
+%
+%
+% See also tapas_physio_new
+
+% Author: Lars Kasper
+% Created: 2015-07-31
+% Copyright (C) 2015 TNU, Institute for Biomedical Engineering,
+% University of Zurich and ETH Zurich.
+%
+% This file is part of the TAPAS PhysIO Toolbox, which is released under the terms of the GNU General Public
+% License (GPL), version 3. You can redistribute it and/or modify it under the terms of the GPL
+% (either version 3 or, at your option, any later version). For further details, see the file
+% COPYING or .
+
+
+%% # MOD - Change parameters to your needs in this section %%%%%%%%%%%%%%%%
+
+% set 1 to look at batch, to 0 for running it for all subjects
+doReviewBatch = false;
+
+pathStudy = '/Users/kasperla/studies/physiotest';
+
+dirSubjectArray = {
+ 'subject10'
+ 'subject11'
+ };
+
+pathStudy = '/Users/kasperla/Documents/code/matlab/smoothing_trunk/PhysIOToolbox/examples/Philips';
+dirSubjectArray = {
+ 'ECG3T'
+ 'ECG3T'
+ };
+
+% folder, where multiple_regressors, physio.mat and output figures are saved,
+% typically analysis folder of the subject
+dirOutput = 'glm';
+
+filePhysCardiac = 'SCANPHYSLOG.log';
+filePhysRespiratory = 'SCANPHYSLOG.log';
+fileRealignmentPar = 'rp_fmri.txt';
+jobfile = 'tapas_physio_example_spm_job_ECG3T.m';
+
+
+
+%% # END MOD Loop over subjects, filling in subject-specific data
+
+nSubjects = numel(dirSubjectArray);
+spm('defaults', 'FMRI');
+
+for iSubject = 1:nSubjects
+
+ % load template matlabbatch
+ clear matlabbatch
+ run(jobfile);
+ physio = matlabbatch{1}.spm.tools.physio;
+
+ % construct subject-specific data
+ pathSubject = fullfile(pathStudy, dirSubjectArray{nSubjects});
+ fullpathFilePhysCardiac = fullfile(pathSubject, filePhysCardiac);
+ fullpathFilePhysRespiratory = fullfile(pathSubject, filePhysRespiratory);
+ fullpathFileRealignment = fullfile(pathSubject, fileRealignmentPar);
+
+ % overwrite matlabbatch structure parameters
+ physio.save_dir = {pathSubject};
+ physio.log_files.cardiac = {fullpathFilePhysCardiac};
+ physio.log_files.respiration = {fullpathFilePhysRespiratory};
+ physio.log_files.scan_timing = {};
+
+ physio.model.movement.yes.file_realignment_parameters = ...
+ {fullpathFileRealignment};
+
+ % run/examine job for this subject
+ matlabbatch{1}.spm.tools.physio = physio;
+
+ if doReviewBatch
+ spm_jobman('interactive', matlabbatch);
+ else
+ spm_jobman('run', matlabbatch);
+ end
+end
diff --git a/PhysIO/examples/tapas_physio_example_philips_ecg3t_spm_job.m b/PhysIO/examples/tapas_physio_example_philips_ecg3t_spm_job.m
new file mode 100644
index 00000000..d992ebaa
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_philips_ecg3t_spm_job.m
@@ -0,0 +1,45 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 37;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 2.5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 3;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 495;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 19;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.grad_direction = 'y';
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.zero = 0.4;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.slice = 0.45;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol_spacing = [];
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'ECG';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.load_from_logfile = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.yes.file_realignment_parameters = {'rp_fMRI.txt'};
+matlabbatch{1}.spm.tools.physio.model.movement.yes.order = 6;
+matlabbatch{1}.spm.tools.physio.model.movement.yes.censoring_method = 'MAXVAL';
+matlabbatch{1}.spm.tools.physio.model.movement.yes.censoring_threshold = [3 Inf];
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = 'PhysIO_output.fig';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_philips_ecg3t_v2_spm_job.m b/PhysIO/examples/tapas_physio_example_philips_ecg3t_v2_spm_job.m
new file mode 100644
index 00000000..09cedb1d
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_philips_ecg3t_v2_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 32;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 2.5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 305;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 16;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.nominal = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU_Wifi';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_philips_ecg7t_spm_job.m b/PhysIO/examples/tapas_physio_example_philips_ecg7t_spm_job.m
new file mode 100644
index 00000000..db83ddb6
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_philips_ecg7t_spm_job.m
@@ -0,0 +1,47 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 36;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 2;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 3;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 230;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 18;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.grad_direction = 'y';
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.zero = 1500;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.slice = 2200;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol_spacing = 0.09;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'ECG';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.yes.file_realignment_parameters = {'rp_fMRI.txt'};
+matlabbatch{1}.spm.tools.physio.model.movement.yes.order = 6;
+matlabbatch{1}.spm.tools.physio.model.movement.yes.censoring_method = 'MAXVAL';
+matlabbatch{1}.spm.tools.physio.model.movement.yes.censoring_threshold = [3 Inf];
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = 'PhysIO_output.fig';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_philips_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_philips_ppu3t_spm_job.m
new file mode 100644
index 00000000..62bb64d3
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_philips_ppu3t_spm_job.m
@@ -0,0 +1,45 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 32;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 2;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 180;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 17;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.grad_direction = 'y';
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.zero = 700;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.slice = 1800;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol_spacing = [];
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.yes.method = 'hilbert';
+matlabbatch{1}.spm.tools.physio.model.rvt.yes.delays = 0;
+matlabbatch{1}.spm.tools.physio.model.hrv.yes.delays = 0;
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = 'PhysIO_output_level2.jpg';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_philips_ppu7t_spm_job.m b/PhysIO/examples/tapas_physio_example_philips_ppu7t_spm_job.m
new file mode 100644
index 00000000..e2a51861
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_philips_ppu7t_spm_job.m
@@ -0,0 +1,44 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'SCANPHYSLOG.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 36;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 3.128;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 1;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 165;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 18;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.grad_direction = 'z';
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.zero = 1500;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.slice = 1800;
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.gradient_log.vol_spacing = [];
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_siemens_hcp_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_siemens_hcp_ppu3t_spm_job.m
new file mode 100644
index 00000000..605dd6ce
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_siemens_hcp_ppu3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Siemens_HCP';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'tfMRI_MOTOR_LR_Physio_log.txt'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'tfMRI_MOTOR_LR_Physio_log.txt'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 91;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 0.72;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 284;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 46;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.nominal = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_siemens_vb_ecg3t_spm_job.m b/PhysIO/examples/tapas_physio_example_siemens_vb_ecg3t_spm_job.m
new file mode 100644
index 00000000..32dfd883
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_siemens_vb_ecg3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Siemens';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'siemens_PAV.ecg'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {''};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = 0.0025;
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 20;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 2.41;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 400;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 11;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.nominal = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'ECG';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = 'physio.fig';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_first_spm_job.m b/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_first_spm_job.m
new file mode 100644
index 00000000..8b416006
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_first_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Siemens';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'20191023_V02.puls'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'20191023_V02.resp'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {'MR.27842.1230'};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = 0.0025;
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = [];
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'first';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 24;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 1.5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 382;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = 0.0625;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 120;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_last_spm_job.m b/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_last_spm_job.m
new file mode 100644
index 00000000..fb4df6ae
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_siemens_vb_ppu3t_sync_last_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Siemens';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'20191023_V02.puls'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'20191023_V02.resp'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {'MR.27842.1611'};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = 0.0025;
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = [];
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 24;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 1.5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 382;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 5;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = 0.0625;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 120;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_siemens_vd_ppu3t_spm_job.m b/PhysIO/examples/tapas_physio_example_siemens_vd_ppu3t_spm_job.m
new file mode 100644
index 00000000..35cbc8df
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_siemens_vd_ppu3t_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Siemens_Tics';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = {'Physio_20180101_120001_pppppppp-hhhh-yyyy-ssss-ioioioioioio_PULS.log'};
+matlabbatch{1}.spm.tools.physio.log_files.respiration = {'Physio_20180101_120001_pppppppp-hhhh-yyyy-ssss-ioioioioioio_RESP.log'};
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {'Physio_20180101_120001_pppppppp-hhhh-yyyy-ssss-ioioioioioio_Info.log'};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = 48;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = 0.995;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = 0;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = 30;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = 1;
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.scan_timing_log = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'PPU';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/PhysIO/examples/tapas_physio_example_template_spm_job.m b/PhysIO/examples/tapas_physio_example_template_spm_job.m
new file mode 100644
index 00000000..6053f1e8
--- /dev/null
+++ b/PhysIO/examples/tapas_physio_example_template_spm_job.m
@@ -0,0 +1,40 @@
+matlabbatch{1}.spm.tools.physio.save_dir = {'physio_out'};
+matlabbatch{1}.spm.tools.physio.log_files.vendor = 'Philips';
+matlabbatch{1}.spm.tools.physio.log_files.cardiac = '';
+matlabbatch{1}.spm.tools.physio.log_files.respiration = '';
+matlabbatch{1}.spm.tools.physio.log_files.scan_timing = {''};
+matlabbatch{1}.spm.tools.physio.log_files.sampling_interval = [];
+matlabbatch{1}.spm.tools.physio.log_files.relative_start_acquisition = 0;
+matlabbatch{1}.spm.tools.physio.log_files.align_scan = 'last';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nslices = '';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.NslicesPerBeat = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.TR = '';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Ndummies = '';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nscans = '';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.onset_slice = '';
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.time_slice_to_slice = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sqpar.Nprep = [];
+matlabbatch{1}.spm.tools.physio.scan_timing.sync.nominal = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.modality = 'ECG';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.filter.no = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.min = 0.4;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.file = 'initial_cpulse_kRpeakfile.mat';
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.initial_cpulse_select.auto_matched.max_heart_rate_bpm = 90;
+matlabbatch{1}.spm.tools.physio.preproc.cardiac.posthoc_cpulse_select.off = struct([]);
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.filter.passband = [0.01 2];
+matlabbatch{1}.spm.tools.physio.preproc.respiratory.despike = false;
+matlabbatch{1}.spm.tools.physio.model.output_multiple_regressors = 'multiple_regressors.txt';
+matlabbatch{1}.spm.tools.physio.model.output_physio = 'physio.mat';
+matlabbatch{1}.spm.tools.physio.model.orthogonalise = 'none';
+matlabbatch{1}.spm.tools.physio.model.censor_unreliable_recording_intervals = false;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.c = 3;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.r = 4;
+matlabbatch{1}.spm.tools.physio.model.retroicor.yes.order.cr = 1;
+matlabbatch{1}.spm.tools.physio.model.rvt.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.hrv.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.noise_rois.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.movement.no = struct([]);
+matlabbatch{1}.spm.tools.physio.model.other.no = struct([]);
+matlabbatch{1}.spm.tools.physio.verbose.level = 2;
+matlabbatch{1}.spm.tools.physio.verbose.fig_output_file = '';
+matlabbatch{1}.spm.tools.physio.verbose.use_tabs = false;
diff --git a/sem/examples/data/example_data.mat b/sem/examples/data/example_data.mat
new file mode 100644
index 00000000..2472c51a
Binary files /dev/null and b/sem/examples/data/example_data.mat differ
diff --git a/sem/examples/tapas_sem_example_hier_estimate.m b/sem/examples/tapas_sem_example_hier_estimate.m
new file mode 100644
index 00000000..859e4104
--- /dev/null
+++ b/sem/examples/tapas_sem_example_hier_estimate.m
@@ -0,0 +1,111 @@
+function [posterior, summary] = tapas_sem_example_hier_estimate(model, param)
+%% Example for inversion with a linear model for the prior.
+%
+% Input
+% model -- String. Either seria or prosa
+% param -- String. Parametric distribution.
+% Output
+% posterior -- Structure. Contains the posterior estimates.
+% summary -- Table. Contains a table with a summary of the
+% posterior.
+
+% aponteeduardo@gmail.com
+% copyright (C) 2018
+%
+
+
+n = 0;
+
+n = n + 1;
+if nargin < n
+ model = 'seria';
+end
+
+n = n + 1;
+if nargin < n
+ param = 'mixedgamma';
+end
+
+[data] = load_data();
+
+switch model
+case 'seria'
+ ptheta = tapas_sem_seria_ptheta();
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_seria_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_seria_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_seria_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_seria_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_seria_multi_later;
+ case 'wald'
+ ptheta.llh = @c_seria_multi_wald;
+ otherwise
+ error('parametric function not defined')
+ end
+
+ ptheta.jm = [...
+ eye(19)
+ zeros(3, 8) eye(3) zeros(3, 8)];
+case 'prosa'
+ ptheta = tapas_sem_prosa_ptheta(); % Choose at convinience.
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_prosa_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_prosa_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_prosa_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_prosa_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_prosa_multi_later;
+ case 'wald'
+ ptheta.llh = @c_prosa_multi_wald;
+ otherwise
+ error('parametric function not defined')
+ end
+
+ ptheta.jm = [...
+ eye(15)
+ zeros(3, 6) eye(3) zeros(3, 6)];
+end
+
+pars = struct();
+
+pars.T = ones(4, 1) * linspace(0.1, 1, 1).^5;
+pars.nburnin = 4000;
+pars.niter = 4000;
+pars.ndiag = 500;
+pars.mc3it = 4;
+pars.verbose = 1;
+
+% The total number of samples stored is floor(pars.niter/pars.thinning). This
+% saves storages and accelerates other computations.
+pars.thinning = 100;
+
+display(ptheta);
+inference = struct();
+
+posterior = tapas_sem_hier_estimate(data, ptheta, inference, pars);
+summary = posterior.summary;
+
+display(posterior);
+tapas_sem_display_posterior(posterior);
+
+end
+
+function [data] = load_data()
+
+f = mfilename('fullpath');
+[tdir, ~, ~] = fileparts(f);
+
+data = load(fullfile(tdir, 'data', 'example_data.mat'));
+
+data = data.data;
+
+end
diff --git a/sem/examples/tapas_sem_example_mixed_estimate.m b/sem/examples/tapas_sem_example_mixed_estimate.m
new file mode 100644
index 00000000..f1baa486
--- /dev/null
+++ b/sem/examples/tapas_sem_example_mixed_estimate.m
@@ -0,0 +1,106 @@
+function [posterior, summary] = tapas_sem_example_mixed_estimate(model, param)
+%% Example for inversion with a mixed effects model as prior.
+%
+% Input
+% model -- String. Either seria or prosa
+% param -- String. Parametric distribution.
+% Output
+% posterior -- Structure. Contains the posterior estimates.
+% summary -- Table. Contains a table with a summary of the
+% posterior.
+
+% aponteeduardo@gmail.com
+% copyright (C) 2018
+%
+
+
+n = 0;
+
+n = n + 1;
+if nargin < n
+ model = 'seria';
+end
+
+n = n + 1;
+if nargin < n
+ param = 'mixedgamma';
+end
+
+[data] = load_data();
+
+switch model
+case 'seria'
+ ptheta = tapas_sem_seria_ptheta();
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_seria_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_seria_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_seria_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_seria_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_seria_multi_later;
+ case 'wald'
+ ptheta.llh = @c_seria_multi_wald;
+ end
+
+ ptheta.jm = [...
+ eye(19)
+ zeros(3, 8) eye(3) zeros(3, 8)];
+case 'prosa'
+ ptheta = tapas_sem_prosa_ptheta(); % Choose at convinience.
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_prosa_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_prosa_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_prosa_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_prosa_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_prosa_multi_later;
+ case 'wald'
+ ptheta.llh = @c_prosa_multi_wald;
+ end
+
+ ptheta.jm = [...
+ eye(15)
+ zeros(3, 6) eye(3) zeros(3, 6)];
+end
+
+ptheta.x = eye(4);
+ptheta.mixed = ones(4, 1)';
+pars = struct();
+
+pars.T = ones(4, 1) * linspace(0.1, 1, 1).^5;
+pars.nburnin = 4000;
+pars.niter = 4000;
+pars.ndiag = 500;
+pars.thinning = 100;
+pars.verbose = 1;
+
+display(ptheta);
+inference = struct();
+tic
+posterior = tapas_sem_mixed_estimate(data, ptheta, inference, pars);
+summary = posterior.summary;
+tapas_sem_display_posterior(posterior)
+toc
+
+display(posterior);
+
+end
+
+function [data] = load_data()
+
+f = mfilename('fullpath');
+[tdir, ~, ~] = fileparts(f);
+
+data = load(fullfile(tdir, 'data', 'example_data.mat'));
+
+data = data.data;
+
+end
diff --git a/sem/examples/tapas_sem_example_multiv_estimate.m b/sem/examples/tapas_sem_example_multiv_estimate.m
new file mode 100644
index 00000000..14d39fdf
--- /dev/null
+++ b/sem/examples/tapas_sem_example_multiv_estimate.m
@@ -0,0 +1,109 @@
+function [posterior, summary] = ...
+ tapas_sem_example_multiv_estimate(model, param)
+%% Example for inversion with a single prior for the whole population.
+%
+% Input
+% model -- String. Either seria or prosa
+% param -- String. Parametric distribution.
+% Output
+% posterior -- Structure. Contains the posterior estimates.
+% summary -- Table. Contains a table with a summary of the
+% posterior.
+
+% aponteeduardo@gmail.com
+% copyright (C) 2018
+%
+
+n = 0;
+
+n = n + 1;
+if nargin < n
+ model = 'seria';
+end
+
+n = n + 1;
+if nargin < n
+ param = 'mixedgamma';
+end
+
+[data] = load_data();
+
+switch model
+case 'seria'
+ ptheta = tapas_sem_seria_ptheta();
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_seria_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_seria_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_seria_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_seria_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_seria_multi_later;
+ case 'wald'
+ ptheta.llh = @c_seria_multi_wald;
+ end
+
+ ptheta.jm = [...
+ eye(19)
+ zeros(3, 8) eye(3) zeros(3, 8)];
+
+ ptheta.x = ones(4, 1);
+
+case 'prosa'
+ ptheta = tapas_sem_prosa_ptheta(); % Choose at convinience.
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_prosa_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_prosa_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_prosa_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_prosa_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_prosa_multi_later;
+ case 'wald'
+ ptheta.llh = @c_prosa_multi_wald;
+ end
+
+ ptheta.jm = [...
+ eye(15)
+ zeros(3, 6) eye(3) zeros(3, 6)];
+
+ ptheta.x = ones(4, 1);
+
+end
+
+pars = struct();
+
+pars.T = ones(4, 1) * linspace(0.1, 1, 1).^5;
+pars.nburnin = 4000;
+pars.niter = 4000;
+pars.ndiag = 500;
+pars.thinning = 100;
+pars.verbose = 1;
+
+display(ptheta);
+inference = struct();
+tic
+posterior = tapas_sem_multiv_estimate(data, ptheta, inference, pars);
+summary = posterior.summary;
+tapas_sem_display_posterior(posterior);
+toc
+
+display(posterior)
+end
+
+function [data] = load_data()
+
+f = mfilename('fullpath');
+[tdir, ~, ~] = fileparts(f);
+
+data = load(fullfile(tdir, 'data', 'example_data.mat'));
+
+data = data.data;
+
+end
diff --git a/sem/examples/tapas_sem_example_single_subject_estimate.m b/sem/examples/tapas_sem_example_single_subject_estimate.m
new file mode 100644
index 00000000..93de74b8
--- /dev/null
+++ b/sem/examples/tapas_sem_example_single_subject_estimate.m
@@ -0,0 +1,113 @@
+function [posterior] = tapas_sem_example_single_subject_estimate(model, param)
+%% Example for estimate for single subjects.
+%
+% Input
+% model -- String. Either seria or prosa
+% param -- String. Parametric distribution.
+% Output
+% posterior -- Structure. Contains the posterior estimates.
+% summary -- Table. Contains a table with a summary of the
+% posterior.
+
+% aponteeduardo@gmail.com
+% copyright (C) 2018
+%
+
+
+n = 0;
+
+n = n + 1;
+if nargin < n
+ model = 'seria';
+end
+
+n = n + 1;
+if nargin < n
+ param = 'mixedgamma';
+end
+
+[data] = load_data();
+
+switch model
+case 'seria'
+ ptheta = tapas_sem_seria_ptheta();
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_seria_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_seria_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_seria_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_seria_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_seria_multi_later;
+ case 'wald'
+ ptheta.llh = @c_seria_multi_wald;
+ otherwise
+ error('parametric function not defined')
+ end
+
+ ptheta.jm = [...
+ eye(19)
+ zeros(3, 8) eye(3) zeros(3, 8)];
+ ptheta.p0(11) = tapas_logit([0.005], 1);
+case 'prosa'
+ ptheta = tapas_sem_prosa_ptheta(); % Choose at convinience.
+ switch param
+ case 'invgamma'
+ ptheta.llh = @c_prosa_multi_invgamma;
+ case 'gamma'
+ ptheta.llh = @c_prosa_multi_gamma;
+ case 'mixedgamma'
+ ptheta.llh = @c_prosa_multi_mixedgamma;
+ case 'lognorm'
+ ptheta.llh = @c_prosa_multi_lognorm;
+ case 'later'
+ ptheta.llh = @c_prosa_multi_later;
+ case 'wald'
+ ptheta.llh = @c_prosa_multi_wald;
+ otherwise
+ error('parametric function not defined')
+ end
+
+ ptheta.jm = [...
+ eye(15)
+ zeros(3, 6) eye(3) zeros(3, 6)];
+
+end
+
+pars = struct();
+
+pars.T = linspace(0.1, 1, 1).^5;
+pars.nburnin = 10000;
+pars.niter = 10000;
+pars.ndiag = 500;
+pars.mc3it = 4;
+pars.verbose = 1;
+pars.thinning = 100;
+
+display(ptheta);
+inference = struct();
+inference.kernel_scale = 0.1 * 0.1;
+
+posterior = cell(numel(data), 1);
+for i = 1:numel(data)
+ posterior = tapas_sem_single_subject_estimate(...
+ data(i), ptheta, inference, pars);
+ display(posterior);
+ tapas_sem_display_posterior(posterior);
+end
+
+end
+
+function [data] = load_data()
+
+f = mfilename('fullpath');
+[tdir, ~, ~] = fileparts(f);
+
+data = load(fullfile(tdir, 'data', 'example_data.mat'));
+
+data = data.data;
+
+end
diff --git a/tools/ti/examples/data/tapas_sooner.mat b/tools/ti/examples/data/tapas_sooner.mat
new file mode 100644
index 00000000..2df1ab17
Binary files /dev/null and b/tools/ti/examples/data/tapas_sooner.mat differ
diff --git a/tools/ti/examples/tapas_ti_example.m b/tools/ti/examples/tapas_ti_example.m
new file mode 100644
index 00000000..2bf41a4e
--- /dev/null
+++ b/tools/ti/examples/tapas_ti_example.m
@@ -0,0 +1,112 @@
+function [results] = tapas_ti_example()
+%% This script simulates data from different models and checks where it comes
+% from.
+%
+% Input
+% mi Model to be used for inversion
+% session Session of the experiment (either 1 or 2)
+% block Block of the experiment, either 3, 4 or 5
+% sbj Subject
+% Output
+%
+% aponteeduardo@gmail.com
+% copyright (C) 2015
+%
+
+DIM_THETA = sooner_gamma_ndims();
+
+ptheta = tapas_sooner_ptheta();
+ptheta.p0(13:15) = [log(1.0) log(0.5) log(0.5)];
+htheta = tapas_sooner_htheta();
+
+pars = struct();
+pars.T = linspace(0.0001, 1, 16).^5;
+pars.nburnin = 5000;
+pars.niter = 5000;
+pars.mc3it = 8;
+pars.verbose = 1;
+pars.samples = 1;
+
+data = load(mat_fname());
+data = data.table;
+[y, u] = prepare_data_db(data);
+[y, u] = select_data(y, u, 3, 1);
+
+[pt, tfe] = tapas_ti_estimate(y, u, ptheta, htheta, pars);
+results.pt = pt;
+results.fe = tfe;
+results.y = y;
+
+end % gamma_inversion
+
+function [y, u] = select_data(y, u, block, session)
+%% Selects a chuck of the data
+
+block = block * session;
+
+y.t = y.t(u.b == block);
+y.a = y.a(u.b == block);
+y.i = y.i(u.b == block);
+
+u.tt = u.tt(u.b == block);
+
+end % select_data
+
+function [fname] = mat_fname()
+%% Generates the name of the simulation
+
+% Get current location
+f = mfilename('fullpath');
+[tdir, ~, ~] = fileparts(f);
+
+fname = fullfile(tdir, 'data', 'tapas_sooner.mat');
+
+
+end %
+
+function [y, u] = prepare_data_db(data)
+%% Generates the data ready to be feeded into the inversion method
+%
+% Input
+%
+% data Matrix as generated by the python script.
+%
+% Output
+% y Subjects time, actions, and trial validity
+% u Trial type and block
+%
+
+% aponteeduardo@gmail.com
+% copyright (C) 2015
+%
+
+y = struct('t', [], 'a', [], 'i', []);
+u = struct('tt', [], 'b', []);
+
+nt = size(data, 1);
+
+% Tenths of second!
+y.t = data(:, 5)/100;
+y.a = data(:, 6);
+y.i = zeros(nt, 1);
+y.i(isnan(y.t)) = 1;
+
+u.tt = data(:, 4);
+u.b = data(:, 1) .* data(:, 2);
+
+% Because of an inconsistency
+
+for i = 1:nt
+ if y.a(i) == 0
+ y.a(i) = 1;
+ else
+ y.a(i) = 0;
+ end
+ if u.tt(i) == 1
+ u.tt(i) = 0;
+ else
+ u.tt(i) = 1;
+ end
+end
+
+end % prepare_data_db