Divyayan Dey
Divyayan Dey

Reputation: 15

Infeasible output with scipy.signal.sosfilt

I am designing a 3rd order Butterworth filter in Python which I am testing on a composition of sinusoids -

t=np.linspace(0,100,1000)
sig=np.sin(2*np.pi*10*t)+np.sin(2*pi*20*t)+np.sin(2*pi*30*t)
sos=signal.butter(3,15,'hp',analog=True,output='sos')
filtered=signal.sosfilt(sos,sig)
plt.subplot(2,1,1)
plt.plot(t,sig)
plt.subplot(2,1,2)
plt.plot(t,filtered)
plt.show()

After executing the above, I see a output waveform like this - Original signal and filtered signal

Please point out the mistake in my code.

Upvotes: 0

Views: 395

Answers (1)

Warren Weckesser
Warren Weckesser

Reputation: 114781

You are treating an analog filter as a digital filter, but that doesn't work. In the call of butter, change the argument to analog=False to create a digital (i.e. discrete time) signal.

Upvotes: 2

Related Questions