Looking at music
A very convenient way to get a quick impression of how the songs of the diverse genres "look" like is to draw a spectrogram for a set of songs of a genre. A spectrogram is a visual representation of the frequencies that occur in a song. It shows the intensity of the frequencies on the y axis in the specified time intervals on the x axis; that is, the darker the color, the stronger the frequency is in the particular time window of the song.
Matplotlib provides the convenient function specgram()
that performs most of the under-the-hood calculation and plotting for us:
>>> import scipy >>> from matplotlib.pyplot import specgram >>> sample_rate, X = scipy.io.wavfile.read(wave_filename) >>> print sample_rate, X.shape 22050, (661794,) >>> specgram(X, Fs=sample_rate, xextent=(0,30))
The wave file we just read was sampled at a sample rate of 22,050 Hz and contains 661,794 samples.
If we now plot the spectrogram for these first 30 seconds...