Created
May 22, 2014 16:03
-
-
Save soravux/e1355535fff3cc07c3a1 to your computer and use it in GitHub Desktop.
Specgram and Fourier transform for blog post.
This file contains hidden or 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
| from scipy.io.wavfile import read, write | |
| import numpy as np | |
| from matplotlib import pyplot as plt | |
| def plotGraph(data, rate): | |
| """Plot an amplitude - spectrogram graph.""" | |
| norm_data = data.astype('double') / ( 2 ** 15 - 1) | |
| x_axis = np.arange(len(norm_data)) / rate | |
| ax = plt.subplot(311) | |
| plt.plot([2, 2], [0, 22050], 'r-', lw=4) | |
| Pxx, freqs, t, x = plt.specgram(data, NFFT=512, noverlap=0, Fs=rate) | |
| ax.set_xlabel('s') | |
| ax.set_ylabel('Hz') | |
| ax = plt.subplot(312) | |
| plt.plot(freqs, list(zip(*Pxx))[88200//512]) | |
| ax.set_xlabel('Hz') | |
| ax = plt.subplot(313) | |
| plt.plot(freqs, list(zip(*Pxx))[88200//512]) | |
| ax.set_xlabel('Hz') | |
| ax.set_yscale('log') | |
| plt.show() | |
| if __name__ == '__main__': | |
| rate, data = read('out.wav') | |
| plotGraph(data, rate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment