# FIR filtering returns “static” signal

//PROBLEM

I'm trying to filter EEG trials from an array in which each trail has dimensions [8x125] = [number of channels x samples@250Hz], but the resulting signal looks static and wrong. Why is this happening? How can I improve my filtered signal quality? See below how the original signal and its PSD are and how the signal comes out of the filtering process:

//PROCEDURE

I'm first applying an IIR 60Hz notch filter, padding the signal (50 mirrored samples on each side), applying a bandpass FIR filter from 5 to 30 Hz, and trimming the signal back down, considering the introduced delay from the FIR filter:

from scipy.signal import lfilter, kaiserord, firwin, iirnotch, freqz

##::FILTERS DESIGN
#Bandpass freq
low = 5 / NYQ
high = 30 / NYQ
#Notch
b1, a1 = iirnotch(60, 9, SPS)
#Kaiser window method
width = 2/NYQ  #transition width
ripple_db = 11 #attenuation
N, beta = kaiserord(ripple_db, width)
b = firwin(N, [low, high], pass_zero = 'bandpass',  window=('kaiser', beta))
print('>>FIR Order: ', N)
delay = int(0.5 * (N-1)) # / SPS
print('>>Delay: ', delay)

##::FILTERING DATA
win = 50
for x in range(data.shape[0]):
#Notch filter
filtsamples = lfilter(b1, a1, data[x, :, :], axis = 1)
prefilt = np.hstack(( np.flip(filtsamples[:, 0:win], axis = 1), filtsamples[:, :], np.flip(filtsamples[:, -win:], axis = 1) ))
#FIR
posfilt = lfilter(b, [1.0], prefilt, axis = 1)
flt_data[x,:,:] = posfilt[:, win+delay:-win]


Here are my frequency and phase responses for each filter:

• @Ben It looks like it is IIR, hence the design call iirnotch. – Peter K. Jul 21 at 17:41
• Welcome to SE.SP! It looks like an interesting problem. I suspect that the show you see in the bottom plots is the shape of the FIR filter impulse response. That leads me to think there's a "glitch" or "spike" in the intermediate filtered data in filtsamples. I'm wondering if the prefilt data is being transposed, so you're filtering across data sets rather than along them? – Peter K. Jul 21 at 17:45
• @PeterK. you are right, the Notch filtered signal does look weird. When I plot it as is, it gives me this result and when I change the axis to 0 on lfilter, it gives me this result. Both have a prominent spike at 60Hz... but it feels that axis = 0 is not destructing the signal as much. What do you think? – mgmussi Jul 21 at 23:51