braph-software / BRAPH-2

BRAPH 2.0 is a comprehensive software package for the analysis and visualization of brain connectivity data, offering flexible customization, rich visualization capabilities, and a platform for collaboration in neuroscience research.
http://braph.org
Other
29 stars 12 forks source link

Incorrect Function Connectivity Matrix Calculation with Odd-Numbered Time Series #1706

Open c-yuwei opened 4 months ago

c-yuwei commented 4 months ago

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.