I don't know what you were doing with the detrend(), butter(), and filtfilt() filters in your m file, like if they were supposed to get rid of the large negative going spikes or they were for something else. But to get rid of the spikes you can use either filloutliers (to replace them with estimated "good" values), or rmoutliers (to delete them completely and make the array shorter).
Or you can use simple masking:
badIndexes = (y < -1000);
y(badIndexes) = [];
You can attach the text file 'P0037.txt' if you need anymore help.
Best Answer