0
$\begingroup$

I am trying to bandpass a neural signal acquired at 20kHz between 0.5 and 100 Hz. I have tried to do it in two ways. The first way is to sequentially highpass and lowpass the signal and the second one is to use the bandpass function in Matlab. To my surprise, the results were dramatically different. See image below:

enter image description here

Here is the code:

clear
close all
load('bandpass_vs_seq_lo_and_hi_pass','tr','fs') % loads variable called tr and fs
% tr is the signal vector and fs is the sampling rate, 20kHz
padlen=0.01; % padding length in secs to remove transients at signal start and end
padn=padlen*fs; % padding length in samples
f_lo=0.5; % lo cutoff
f_hi=100; % hi cutoff
tvec=(1/fs:1/fs:1/fs*length(tr));

figure
ax1=subplot(3,1,1);
ax2=subplot(3,1,2);
ax3=subplot(3,1,3);

% sequential highpass and lowpass filter
    % hipass filter     
      nutr=[flipud(tr(1:padn));tr;flipud(tr(end-(padn-1):end))];  % prefixing and appending signal  
      [filtr,~]=highpass(nutr,f_lo,fs);
      filtr=filtr(padn+1:end-padn); % removing prefixed and appended parts
      tr1=filtr;

       % lopass filter
      nutr=[flipud(tr1(1:padn));tr1;flipud(tr1(end-(padn-1):end))];    
      [filtr2,~]=lowpass(nutr,f_hi,fs);
       filtr2=filtr2(padn+1:end-padn);
       tr1=filtr2;

 % bandpass filter
      nutr=[flipud(tr(1:padn));tr;flipud(tr(end-(padn-1):end))];    
     [filtr,~]=bandpass(nutr,[f_lo,f_hi],fs);
     filtr=filtr(padn+1:end-padn);
     tr2=filtr;
 
 plot(ax1,tvec,tr)
 plot(ax2,tvec,tr1)
 plot(ax3,tvec,tr2)
 
 xlabel(ax3,'Time (s)')
 title(ax1,'Original signal, fs=20kHz')
 title(ax2,'Sequential high pass and lowpass (0.5 to 100 Hz)')
 title(ax3,'Bandpass (0.5 to 100 Hz)')

Can anyone shed light on what is going on here?

$\endgroup$
3
  • $\begingroup$ You're designing very narrow filters near DC; that's difficult in general. I would try several steps of downsampling to reduce the sampling rate first, followed by a filter to reject DC. $\endgroup$
    – MBaz
    Feb 23 at 22:19
  • $\begingroup$ So, basically this devolves down to a Matlab question, because the devil is in the details, and the details are in the way Matlab implements highpass, lowpass, and bandpass. I suggest you build your own filters so that you know what's going on, and get back to us if there's problems. $\endgroup$
    – TimWescott
    Feb 23 at 22:21
  • 1
    $\begingroup$ @MBaz Thanks Guys!! For now I am satisfied with the results of sequential filtering. Reading some related questions is giving me a better insight into the pitfalls in this specific area. Like this one: dsp.stackexchange.com/questions/19245/… $\endgroup$ Feb 23 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.