How do we use signal::filter and signal::butter in R for EEG data? 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 &lt;- 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] &lt;- 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.
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:

https://stackoverflow.com/a/49905340/9665680