I am trying to design an experiment to determine the peak amplitude of an EEG signal in response to a stimulus. Till now, our team has been using MATLAB and since we wish to go open source, we are trying to replicate the same in R.

  • High pass cutoff: 0.3 Hz
  • Low pass cutoff: 30 Hz
  • Number of observations: 59000
  • Sampling rate: 500 Sps

The code I have written is as follows:

#Trying to pass parameters as pi-radians
bf <- signal::butter(2,W=c(0.3,30)/250,type="pass",plane="s")

#test is my EEG dataframe in R
for (i in 2:9) {
  test[,i] <- signal::filter(bf,test[,i])

I tried following the example on stackoverflow:

How do I run a high pass or low pass filter on data points in R?

However, the amplitudes which I am getting via this is greatly different for the same set of parameters when using MATLAB's EEGLAB which uses pop_basicfilter.m.

Please let me know if you need any additional information.

  • $\begingroup$ Does the shape look similar though? Implementations often differ in a constant scaling factor. You can also examine the spectrum of the signal before and after filtering to make sure your filter in R is indeed doing what you want it to do. $\endgroup$
    – Atul Ingle
    Dec 2 '16 at 15:35

I think your problem is that you want to use signal::filtfilt rather than signal::filter for the cut-offs you set to map on to the half-amplitude cut-off (otherwise, with the signal::filter function, these are the half-power cut-offs).

See my answer here for example code showing how to use the W parameter in signal::butter and double-check that your filter is working appropriately:



Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.