Bandpass Filtering EEG Data
7 views (last 30 days)
Show older comments
Hi!
I'm trying to bandpass filter EEG data that has 64 channels. For some reason, the filter is replacing a large part of some channels with NaNs. Here is the code I'm using. Fs in this case is 240 Hz. I have attached the EEG data that I'm using. Thank you so much!
function [ppf] = pfilter(x, Fs)
%First apply a bandpass filter to get frequencies between 0.1 Hz and 40 Hz
Fn = Fs/2; %nyquist frequency
wp = [1 40]/Fn; %normalizing frequency range.
[b,a] = butter(1,wp);%1st order butterworth filter.
[sos,g] = tf2sos(b,a);
figure(1);
freqz(sos, 240, Fs);
ppf = x;
for i = 1:size(x,2);
tmp = ppf(:,i); tmp(tmp==0)=NaN;
tmp(isfinite(tmp)) = detrend(tmp(isfinite(tmp)));
ppf(:,i) = filter(b,a,tmp);
end
end
0 Comments
Answers (1)
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!