To note, I am using Matlab R2017a for my signal processing.
I have filtered my EEG signal according to the frequencies I am interested in using butterworth (2Hz-30Hz). But there are some large amplitude artefacts in my signal that I want to remove. I have been advised to replace the signal with NaN, but I want to use pwelch to look at the signal's PSD. But pwelch won't work if I have a NaN. I've tried an autoregression spectrum, but the PSD looks way off.
The below PSD graphs are of the same signal. This signal is unfiltered. This is to illustrate the huge difference between pwelch and autoregression, and why I don't want to use the autoregression.
PSD with pwelch:
PSD with autoregression spectrum:
I don't really want to use a median filter, because I don't want to predict what the data may look like.
What other ways can I use to remove these types of artefacts so that I can look at the signal in the PSD plot? I would prefer a method that ignores NaN (artefacts), rather than other methods like resampling or interpolation for the same reasons as why I don't want to use a median filter. The below is some code I used to create a signal with added artefacts to practice any filtering on.
Example code to replace artefacts with NaN:
N=38400; M=128; fs=128; x=randn(N,1); % Create signal with the same parameters as my data mi=10; ma=20; x(4032:4165)=(ma-mi).*rand(length(x(4032:4165)),1)+mi; % Add in large amplitude artefacts x(25875:25989)=(ma-mi).*rand(length(x(25875:25989)),1)+mi; t = (0:N-1)/fs; % Get time vector of x figure plot(t,x); % Look at where artefacts are located % First blip in time domain x1 = fs*31.5 % X axis units (time domain) (The units change everytime in x because the signal is produced with randn, so wen you do it, you may not get the same units) x2 = fs*32.53 x3 = t(4032:4165); x3 = (x3*fs)+1; % Find corresponding indices on the signal (x) that relate to the artefacts on the time vector % Second blip in time domain y1 = fs*202.1 % X axis units (time domain) y2 = fs*203 y3 = t(25875:25989); y3 = (y3*fs)+1; x(x3) = NaN; % Replace artefacts with NaN x(y3) = NaN;