ComputationalPsychiatry / ComputationalPsychiatry/PhysIO

Off-by-one array size mismatch when processing ECG data (Siemens)

Open
#44 0 comments 0 reactions 1 assignee Claimed by @mrikasper View on GitHub
Dominant language
MATLAB
Stars
14
Forks
2
PR merge metrics
No merged PRs in 30d

Description

Hi everyone,

I'm a master's student fairly new to MATLAB and PhysIO, and I've been trying to use the toolbox to extract cardiac (ECG) data from fMRI sessions with the goal of calculating HRV for my subjects. I'm running into an error that affects around 13 out of 90 subjects and I can't figure out what's causing it.

**Error message:**

```
Warning: PhysIO failed for :
Unable to perform assignment because the size of the left side is N-by-1
and the size of the right side is (N-1)-by-1.
> In project_loop (line 190)
```

The exact value of N differs per subject (e.g. roughly in the range of 475,000 to 2,074,000 samples), but the pattern is always the same: left side is exactly 1 sample larger than the right side.

**Setup:**

- Scanner: Siemens
- PhysIO version: R2024a-v9.0.3
- TAPAS version: 6.1.0
- MATLAB: R2024a
- Signal: ECG only (no respiratory data — hence the expected `No respiratory time series provided` warnings)
- Sync method: `scan_timing_log` using a JSON sidecar file
- I am running a loop over subjects and tasks (two tasks per subject)

**Relevant configuration:**

Scan timing:
```matlab
physio.scan_timing.sync.method = 'scan_timing_log';
physio.scan_timing.sqpar.TR = 2.36;
physio.scan_timing.sqpar.Nslices = 48;
physio.scan_timing.sqpar.Ndummies = 0;
physio.scan_timing.sqpar.onset_slice = 1;
```

Cardiac preprocessing:
```matlab
physio.preproc.cardiac.modality = 'ECG';
physio.preproc.cardiac.fix_mismatch = true;
physio.preproc.cardiac.fix_mismatch_method = 'round'; % also tried 'truncate'
physio.preproc.cardiac.initial_cpulse_select.method = 'auto_matched';
physio.preproc.cardiac.initial_cpulse_select.max_heart_rate_bpm = 90;
physio.preproc.cardiac.initial_cpulse_select.min = 0.4;
physio.preproc.cardiac.posthoc_cpulse_select.method = 'off';
```

Log file alignment:
```matlab
physio.log_files.align_physio = 'scan';
physio.log_files.relative_start_acquisition = 0;
physio.log_files.align_scan = 'first';
```

**What I've already tried:**

- Setting `fix_mismatch = true` with both `fix_mismatch_method = 'truncate'` and `'round'`; neither resolved the error
- The error is caught by a `try/catch` block so the loop continues, but those subjects are fully skipped
- The subjects that fail don't seem to share any obvious characteristics (scan duration, task, etc.) compared to those that succeed

**Questions:**

1. What is most likely causing this 1-sample mismatch for some subjects but not others?
2. Why doesn't `fix_mismatch` catch this; is the mismatch happening before that logic runs?
3. Is there a recommended workaround, or a specific line in the Siemens reader I should patch manually?

Any help would be hugely appreciated! Thanks in advance!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.