Changeset f36277c


Ignore:
Timestamp:
Feb 12, 2013, 8:08:51 PM (12 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:
deb3d65
Parents:
ae81726
Message:

python/demos/demo_onset_file.py: also plot descriptor and thresholded descriptor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_onset_file.py

    rae81726 rf36277c  
    2020o = onset("default", win_s, hop_s)
    2121
     22desc = []
     23tdesc = []
     24
    2225block_read = 0
    2326allsamples_max = zeros(0,)
     
    2730    allsamples_max = hstack([allsamples_max, new_maxes])
    2831    isbeat = o(samples)
     32    desc.append(o.get_descriptor())
     33    tdesc.append(o.get_thresholded_descriptor())
    2934    if isbeat:
    3035        thisbeat = (block_read - 4. + isbeat[0]) * hop_s / samplerate
     
    3641# do plotting
    3742from numpy import arange
    38 from pylab import plot, show, xlabel, ylabel, legend, ylim, subplot, axis
     43import matplotlib.pyplot as plt
    3944allsamples_max = (allsamples_max > 0) * allsamples_max
    4045allsamples_max_times = [ float(t) * hop_s / downsample / samplerate for t in range(len(allsamples_max)) ]
    41 plot(allsamples_max_times,  allsamples_max, '-b')
    42 plot(allsamples_max_times, -allsamples_max, '-b')
    43 axis(xmin = 0., xmax = max(allsamples_max_times) )
    44 for stamp in onsets: plot([stamp, stamp], [-1., 1.], '.-r')
    45 xlabel('time (s)')
    46 ylabel('amplitude')
    47 show()
    48 
     46plt1 = plt.axes([0.1, 0.75, 0.8, 0.19])
     47plt2 = plt.axes([0.1, 0.1, 0.8, 0.65], sharex = plt1)
     48plt.rc('lines',linewidth='.8')
     49plt1.plot(allsamples_max_times,  allsamples_max, '-b')
     50plt1.plot(allsamples_max_times, -allsamples_max, '-b')
     51for stamp in onsets: plt1.plot([stamp, stamp], [-1., 1.], '-r')
     52plt1.axis(xmin = 0., xmax = max(allsamples_max_times) )
     53plt1.xaxis.set_visible(False)
     54desc_times = [ float(t) * hop_s / samplerate for t in range(len(desc)) ]
     55desc_plot = [d / max(desc) for d in desc]
     56plt2.plot(desc_times, desc_plot, '-g')
     57tdesc_plot = [d / max(desc) for d in tdesc]
     58for stamp in onsets: plt2.plot([stamp, stamp], [min(tdesc_plot), max(desc_plot)], '-r')
     59plt2.plot(desc_times, tdesc_plot, '-y')
     60plt2.axis(ymin = min(tdesc_plot), ymax = max(desc_plot))
     61plt.xlabel('time (s)')
     62#plt.savefig('/tmp/t.png', dpi=200)
     63plt.show()
Note: See TracChangeset for help on using the changeset viewer.