Acoustic Analysis with Pylab and Scipy

output_7_0

Importing the required packages

import pylab as py

import scipy
from scipy.io.wavfile import read
from scipy.signal import hann
from scipy.fftpack import rfft

Graphing the waveform of a WAV file with Scipy.io and Pylab (Matplotlib)

The files are converted into a numpy array of some sort, bear in mind that scipy is built upon numpy.

source = read('sound.wav')
sr, audio = source
# sr here corresponds to the sample frequency of the file and audio to an array
# of acoustic values
print('Sample Frequency: {:}Hz \nAcoustic Values: {:}'.format(sr, audio))

Sample Frequency:                            44100Hz
Acoustic Values:                                 [ -121 -164 -282 …, -1064 -815 -717]

py.plot(audio, 'k')

py.ylabel('Decibels')
py.xlabel('Duration')
py.title('Vowel Wave Form')
py.xlim(0, 303104)

py.show()
output_5_0
Analysis may also be carried out on specific slices of the sound token as shown below
py.plot(audio[110000:150000], 'k')

py.ylabel('Decibels (dB)')
py.xlabel('Duration')
py.title('A Vowelic Slice')

py.show()

output_6_0

py.plot(audio[180000:190000], 'k')

py.ylabel('Decibels (dB)')
py.xlabel('Duration')
py.title('A Noisy Slice')

py.show()

output_7_0

Basic Fourier Analysis

window = hann(303104)
sample = audio * window

magnitude = 20 * scipy.log10(abs(rfft(sample)))
magnitude -= max(magnitude)

py.plot(magnitude, 'k')
py.ylabel('dB')
py.xlabel('Frequency')
py.title('Uneme Vowel Spectrum')
py.xlim(0, 303104)

py.show()

output_9_0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s