0
$\begingroup$

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: Pwelch

PSD with autoregression spectrum: Pwelch

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;
$\endgroup$
  • 1
    $\begingroup$ Welcome to SE.DSP! I'm a little confused: what do you see as the artefacts in the PSDs? What do you see as the signals? Can you clarify by editing you question? $\endgroup$ – Peter K. Jul 24 '18 at 17:03
  • $\begingroup$ Hello, sorry that I wasn't clearer before. I edited the question, I hope it is clarified. $\endgroup$ – Krithika Jul 25 '18 at 19:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.