Created
February 21, 2018 10:47
-
-
Save josesoyo/24cb9a8c87ec53e6f443be1de8d9f027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.signal as sp | |
import numpy as np | |
import matplotlib.pylab as plt | |
# low pass functions copied from the web | |
def butter_lowpass(cutOff, fs, order=5): | |
nyq = 0.5 * fs | |
normalCutoff = cutOff / nyq | |
b, a = sp.butter(order, normalCutoff, btype='low') | |
return b, a | |
def butter_lowpass_filter(data, cutOff, fs, order=4): | |
b, a = butter_lowpass(cutOff, fs, order=order) | |
y = sp.lfilter(b, a, data) | |
return y | |
length , samplingRate, amplitude = 1500, 500, 2 | |
x = np.linspace(0, length,length)/samplingRate | |
flo, fhi = 1, 50 | |
lo = amplitude*np.sin(2*np.pi*flo*x) | |
hi = (amplitude/3)*(np.sin(2*np.pi*fhi*x)) | |
sumLoHi = lo+hi | |
filtered = butter_lowpass_filter(sumLoHi,10,500, 10) #filter | |
# plot | |
plt.figure(figsize=(12,10)) | |
#plt.subplot(211) | |
plt.plot(x,sumLoHi,'-', label='sum') | |
plt.plot(x, lo, 'b', label='low') | |
plt.plot(x, filtered, label='filtered') | |
plt.legend() | |
plt.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment