Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Specgram and Fourier transform for blog post.
from 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 = plt.subplot(312)
plt.plot(freqs, list(zip(*Pxx))[88200//512])
ax = plt.subplot(313)
plt.plot(freqs, list(zip(*Pxx))[88200//512])
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