Skip to content

Fix functional connectivity matrix for odd-length time series #1706

@yu-wei-c

Description

@yu-wei-c

Describe the bug
The function connectivity matrix is calculated wrongly when the time series is odd-numbered length.
The bug occurs within the following code snippet in AnalyzeEnsemble_FUN_WU:

data = sub.getr('FUN');
fs = 1 / T;

if fmax > fmin && T > 0
    NFFT = 2 * ceil(size(data, 1) / 2);
    ft = fft(data, NFFT);  % Fourier transform
    f = fftshift(fs * abs(-NFFT / 2:NFFT / 2 - 1) / NFFT);  % absolute frequency
    ft(f < fmin | f > fmax, :) = 0;
    data = ifft(ft, NFFT);
end

The issue arises when the input data contains odd-numbered time series, such as 83x150 (indicating 150 time series with 83 time points). In this case, the variable NFFT attempts to add zeros to the end of each time series, leading to unexpected highly correlated function connectivity matrices.

The following is an example of the wrongly calculated functional connectivity matrices due to the odd-numbered time series in certain subjects

image

To Reproduce
Steps to reproduce the behavior:

  1. Provide functional data containing odd-numbered time series.
  2. Execute the code and observe the constructed functional connectivity

Expected behavior
The Fourier transform operation should be executed correctly, producing accurate results regardless of the number of time points in the input data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working and need to be fixed right awaygraphIssues related to package graph

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions