Line 105 of code: dist(i)=sqrt((eeg_filt(ch,i,tr)-eeg_filt(ch,i+1,tr))^2+1); Issue The assumption that the time step is 1 is not correct for EEG signals. It depends on the sampling rate.