Created
January 27, 2015 09:38
-
-
Save ati/67f533e86c88b02e0814 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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import scipy.fftpack | |
SAMPLE_RATE = 12800 | |
FFT_SIZE = 32768 | |
def plot_spectrum(y, title): | |
plt.figure(figsize=(19,4)) | |
plt.title(title) | |
plt.grid(True) | |
bin_width = 1.0*SAMPLE_RATE/FFT_SIZE | |
x_vals = np.array(np.linspace(0.0, len(y), num=len(y))*bin_width) | |
#print "len_x = %d, len_y = %d" % (len(x_vals), len(y)) | |
plt.plot(x_vals, np.log10(np.array(y)/len(y)), c="b") | |
return True | |
def plot_time(y, title): | |
plt.figure(figsize=(19,4)) | |
plt.title(title) | |
plt.plot(y, c="g") | |
return True | |
def fft(x): | |
window = np.hamming(FFT_SIZE) | |
return np.abs(window*scipy.fftpack.fft(x)) | |
data = np.loadtxt("/Users/ati/Downloads/ua.txt", dtype=np.float) | |
#plot_time(data[0:2048], "src") | |
plot_spectrum(fft(data[0:FFT_SIZE])[0:FFT_SIZE/4], "fft_size = %d"%FFT_SIZE) | |
plot_spectrum(fft(data[0:FFT_SIZE])[0:FFT_SIZE/16], "fft_size = %d"%FFT_SIZE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment