sccn / clean_rawdata

Cleaning Raw EEG data
GNU General Public License v3.0
43 stars 17 forks source link

design_fir crashes on data with high sampling rates #4

Open arnodelorme opened 4 years ago

arnodelorme commented 4 years ago

Transfered from https://sccn.ucsd.edu/bugzilla/show_bug.cgi?id=12974

This bug involves the design_fir function which is called by the clean_channels function in the clean_rawdata toolbox

The design_fir function crashes on data with a high sampling rate (9600) but performs perfectly well with data with a lower sampling rate (9000).

line 89 of clean_channels:

B = design_fir(100,[2*[0 45 50]/signal.srate 1],[1 1 0 0]);

line 47 of design_fir:

F = interp1(round(F*nfft),A,(0:nfft),'pchip');

The original F ([2*[0 45 50]/signal.srate 1]) is multiplied by the nFFT (512) to produce [ 0 5 5 512] with a sampling rate of 9600, and [ 0 5 6 512] with a sampling rate of 9000. As griddedInterpolate needs unique numbers, the function crashes with the 9600 sr data.

If you increase the nFFT to 1024, then it becomes [ 0 10 11 1024] (round([2[0 45 50]/9600 1]1024)). However, it seems that the nFFT cannot be specified in clean_channels and is determined by the order of the filter, which is currently hardcoded into clean_channels (N=100).

Currently I only have a try and catch around it in clean_channels, where I specify the 'nfft':

try
    B = design_fir(100,[2*[0 45 50]/signal.srate 1],[1 1 0 0]);
catch
    B = design_fir(100,[2*[0 45 50]/signal.srate 1],[1 1 0 0],1024);
end

However, I dont know whether this is the best fix.

Regards, Tyler

PS loving the toolbox

arnodelorme commented 2 years ago

It is a good point. I do not have a solution. I will leave this open.