In [58]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter, freqz

freqs = [40.0,41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0]
N = 1000
fs = 100
t = np.arange(N)
x = np.zeros(N)
for freq in freqs:
    x = x + np.sin(freq*2.0*np.pi*t/fs)
plt.figure(0)
plt.plot(t[1:100], x[1:100])
xx = np.repeat(x,10)
plt.figure(1)
plt.plot(xx[1:100])
order = 9
low = 100
high = 200
b, a = butter(order, [low, high], btype='band', fs=1000)
w, h = freqz(b,a)
plt.figure(3)
plt.plot(w/np.pi*500,np.abs(h))
xxx = lfilter(b, a, xx)
plt.figure(4)
plt.plot(xxx[1:100])
plt.figure(5)


Out[58]:
<Figure size 432x288 with 0 Axes>
<Figure size 432x288 with 0 Axes>

In [59]:
f = np.linspace(0,1,len(xxx))
spectrum = np.abs(np.fft.fft(xxx))
plt.plot(f*1000, spectrum)
plt.figure(6)
plt.plot(f*1000, np.abs(np.fft.fft(xx)))
plt.figure(7)
ff = np.linspace(0,1,len(x))
plt.plot(ff*100, np.abs(np.fft.fft(x)))


Out[59]:
[<matplotlib.lines.Line2D at 0x1c19061b70>]

In [ ]: