Nirs data importing error

Hi there,

I'm experiencing the same error every time I try to import a nirs file:

Screen Shot 2022-02-22 at 2.15.49 PM

I was wondering if you had any tips?

Thank you!


Could you please share a short file with which you're having this problem?
Zip it, upload it somewhere, and post the download link here.


I have been able to replicate the issue. It seems that the sampling frequency is not an integer as expected: sFile.prop.sfreq = 75.0019 whereas : mean(1./diff(nirs.t)) is 75.0002 (difference of 0.0017Hz)

So when creating the sample bounds; in the first case we try to access from 1 to 86407 ( round(sFile.prop.times(2) .* sFile.prop.sfreq) in the code) but the matrix data only contains 864006 samples. I think it is related to NIRS: Inconsistent sampling frequencies

An 'easy fix' is to only import the first 1150s of the signal as shown in the following screenshot :slight_smile:
Capture d’écran 2022-02-22 à 21.58.34


Great, thank you so much Edouard!

no problem. @Francois, can you confirm that this solution is ok for you or should we investigate further and maybe fix the importation code when the frequency is not an integer?

Thank you @edelaire for the explanations.
I'd like to add a test to capture this error, and then either fix it on the fly or display a clear error message, to help other users suffering from the same problem.
Did anybody get any additional information about this variations in the sampling rate?

I'd didn't get the chance to download you example file before you deleted it.
Could you please share it again?
If you don't want it to be publicly accessible, send me like via a private message on this forum.

Thank you for the example file.

Please update Brainstorm to get this fix:

It adjusts the number of time samples based on the sampling frequency defined to be used in Brainstorm, instead of relying only on the timestamps of the first and last samples in the NIRS file. This may cause a slight difference in timing in Brainstorm, with respect to what is available in the NIRS file.
A warning is displayed in the Matlab command window to show these differences. Example for this file:

BST> WARNING: Unstable sampling frequency in NIRS file.
BST>   | MEAN: mean(1./diff(t))=75.000187500460 Hz   |   STD: std(1./diff(t))=0.000000000217 Hz
BST>   | Time of last sample reported in the NIRS file: 1152.063786500000 s
BST>   | Time of last sample as imported in Brainstorm: 1152.037865000000 s

@edelaire Please let me know if you think there is any issue with this approach.

Thanks, François.
yes, the change looks good to me. I am still very puzzled as to why the frequency is not stable. Here the sampling rate should be 75Hz so I am not sure if the issue comes from the data acquisition or from a conversion before the importation in Brainstorm. I will add this to my todo list of things to investigate :slight_smile: