Changeset 70b2ab0


Ignore:
Timestamp:
Sep 22, 2016, 1:48:44 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
f334300
Parents:
88c89e3
Message:

python/demos/demo_mfcc.py: add options to plot first and second derivatives, and set samplerate/win_s/hop_s, thanks to @jhoelzl (closes #68)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_mfcc.py

    r88c89e3 r70b2ab0  
    33import sys
    44from aubio import source, pvoc, mfcc
    5 from numpy import vstack, zeros
     5from numpy import vstack, zeros, diff
    66
    7 win_s = 512                 # fft size
    8 hop_s = win_s // 4          # hop size
    97n_filters = 40              # must be 40 for mfcc
    108n_coeffs = 13
    11 samplerate = 44100
    129
    1310if len(sys.argv) < 2:
    14     print("Usage: %s <source_filename>" % sys.argv[0])
     11    print("Usage: %s <source_filename> [samplerate] [win_s] [hop_s] [mode]" % sys.argv[0])
     12    print("  where [mode] can be 'delta' or 'ddelta' for first and second derivatives")
    1513    sys.exit(1)
    1614
    1715source_filename = sys.argv[1]
     16
     17if len(sys.argv) > 2: samplerate = int(sys.argv[2])
     18else: samplerate = 0
     19if len(sys.argv) > 3: win_s = int(sys.argv[3])
     20else: win_s = 512
     21if len(sys.argv) > 4: hop_s = int(sys.argv[4])
     22else: hop_s = win_s // 4
     23if len(sys.argv) > 5: mode = sys.argv[5]
     24else: mode = "default"
    1825
    1926samplerate = 0
     
    4956wave.yaxis.set_visible(False)
    5057
     58# compute first and second derivatives
     59if mode in ["delta", "ddelta"]:
     60    mfccs = diff(mfccs, axis = 0)
     61if mode == "ddelta":
     62    mfccs = diff(mfccs, axis = 0)
     63
    5164all_times = arange(mfccs.shape[0]) * hop_s
    5265n_coeffs = mfccs.shape[1]
     
    5467    ax = plt.axes ( [0.1, 0.75 - ((i+1) * 0.65 / n_coeffs),  0.8, 0.65 / n_coeffs], sharex = wave )
    5568    ax.xaxis.set_visible(False)
    56     ax.yaxis.set_visible(False)
     69    ax.set_yticks([])
     70    ax.set_ylabel('%d' % i)
    5771    ax.plot(all_times, mfccs.T[i])
    5872
    5973# add time to the last axis
    60 set_xlabels_sample2time( ax, frames_read, samplerate) 
     74set_xlabels_sample2time( ax, frames_read, samplerate)
    6175
    6276#plt.ylabel('spectral descriptor value')
    6377ax.xaxis.set_visible(True)
    64 wave.set_title('MFCC for %s' % source_filename)
     78title = 'MFCC for %s' % source_filename
     79if mode == "delta": title = mode + " " + title
     80elif mode == "ddelta": title = "double-delta" + " " + title
     81wave.set_title(title)
    6582plt.show()
Note: See TracChangeset for help on using the changeset viewer.