Feature Plotting

Plot the FilterBin MEL features with a colormap.


In [6]:
import os
import sys

import matplotlib.pyplot as plt
import numpy as np

def add_project_module_path():
    """
    Simple method for adding our module to the sys path
    """
    path_items=(os.getcwd()).split(os.sep)
    path_items.pop()
    final_path=""
    for item in path_items:
        final_path+=item+os.sep
    sys.path.append(final_path+'cssigps')
    sys.path.append(final_path)

# method for adding module to sys path
add_project_module_path()
from cssigps.dataset import *
from cssigps.feature import *
from get_dropbox_path import *
%matplotlib inline


path=get_dropbox_path()+"new-vowels-test"#+"yes-no-test"

# return a list of the audio test samples
samples = find_testsamples(path)
print('\nFound '+str(len(samples))+' samples')
sample_set = SampleSet(samples,envs=["Q1"])
sample_set.stats()

def plot_matrix(matrix,vmin=None,vmax=None):
    """plot matrix for visualization"""
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.set_aspect('equal')
    if vmin and vmax:
        plt.imshow(matrix, interpolation='nearest', cmap=plt.cm.gist_heat, vmin=vmin, vmax=vmax)
    else:
        plt.imshow(matrix, interpolation='nearest', cmap=plt.cm.gist_heat)
    #plt.colorbar()
    plt.show()

def matrix_expansion(matrix,n):
    """
    duplicate rows of features to create a better MEL visualization.
    The final size will rows * n x cols
    """
    rows,cols= matrix.shape
    nmatrix = np.zeros((rows*n,cols), dtype=f.dtype)
    for row in range(rows):
        for i in range(n):
            nmatrix[(row*n)+i]=matrix[row]
    return nmatrix
    
factory=FBankFeature()
examples = sample_set.class_rep()
col=0
for e in examples:
    feat = factory.generate(e)
    print('\t'+str(e))
    print('\tfeat.shape: '+str(feat.shape))
    print('\tfeat: '+str(feat))
    plot_matrix(feat.reshape(99,26).T,-2.,17.5)
    #plot_matrix(feat.reshape(99,26))


Found 58 samples
Num samples: 58
Num classes: 6
	'A' : 10
	'NONE' : 2
	'E' : 10
	'I' : 10
	'O' : 10
	'U' : 10
	<sample name='sample_Q1_0001_0_A1.wav' y='A1' >
	feat.shape: (2574,)
	feat: [ 0.88930553  3.655146    3.0054633  ...,  6.06211709  6.00336618
  6.4698044 ]
	<sample name='sample_Q1_0002_0_E1.wav' y='E1' >
	feat.shape: (2574,)
	feat: [ 1.27579993  2.33945518  4.16452176 ...,  5.97892098  5.45577508
  6.36552304]
	<sample name='sample_Q1_0002_11_NONE.wav' y='NONE' >
	feat.shape: (2574,)
	feat: [ 1.64481237  4.33011735  4.51824659 ...,  4.40544591  4.64690739
  4.88917447]
	<sample name='sample_Q1_0003_0_I1.wav' y='I1' >
	feat.shape: (2574,)
	feat: [ 2.78842063  2.26123226  5.47356545 ...,  5.89724261  6.17792255
  6.50169863]
	<sample name='sample_Q1_0004_0_O1.wav' y='O1' >
	feat.shape: (2574,)
	feat: [-2.10818629  2.06656113  2.78816306 ...,  6.17622634  6.00735151
  5.84232154]
	<sample name='sample_Q1_0005_0_U1.wav' y='U1' >
	feat.shape: (2574,)
	feat: [-0.11063946  3.67068882  4.20877208 ...,  6.04537702  5.88663335
  6.24290788]

In [4]: