Created
November 22, 2016 20:01
-
-
Save LongHairedHacker/f334da0d007dd4ca7e5857d891e7420b 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
#!/usr/bin/env python2 | |
import numpy | |
import scipy.signal | |
import matplotlib.pyplot as plt | |
f_samp = 100.0 | |
f_sine = 40.0 | |
f_lim = 2.0 | |
trans_width = 2.0 | |
#data = numpy.sin(2 * numpy.pi * f_sine * numpy.arange(0, 300.0, 1/f_samp)) | |
data = numpy.random.uniform(size=30000) | |
data_freqs = numpy.fft.rfftfreq(data.size, d=1/f_samp) | |
data_fft = numpy.fft.rfft(data - numpy.mean(data), norm='ortho') | |
coeffs = scipy.signal.firls(63, (0, f_lim, f_lim + trans_width, 50.0), (1.0, 1.0, 0.0, 0.0), nyq=f_samp/2) | |
filtered = scipy.signal.lfilter(coeffs, [1.0], data) | |
filtered_freqs = numpy.fft.rfftfreq(filtered.size, d=1/f_samp) | |
filtered_fft = numpy.fft.rfft(filtered - numpy.mean(filtered), norm='ortho') | |
ax_freq = plt.subplot(3,1,1) | |
ax_fft = plt.subplot(3,1,2) | |
ax_data = plt.subplot(3,1,3) | |
ax_fft.plot(data_freqs, data_fft) | |
ax_fft.plot(filtered_freqs, filtered_fft) | |
ax_data.plot(data) | |
ax_data.plot(filtered) | |
freq, response = scipy.signal.freqz(coeffs) | |
ax_freq.semilogy(50.0*freq/(numpy.pi), numpy.abs(response)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment