Ignore:
Timestamp:
Feb 11, 2013, 11:06:28 AM (11 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:
050a8f3
Parents:
5314432 (diff), 88fc249 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge from develop

File:
1 moved

Legend:

Unmodified
Added
Removed
  • python/demos/demo_spectrogram.py

    r5314432 rfc117d0  
    1 #! /usr/bin/python
     1#! /usr/bin/env python
    22
    33import sys
     
    2323
    2424  # plotting
    25   imshow(log10(specgram.T), origin = 'bottom', aspect = 'auto', cmap=cm.gray_r)
     25  imshow(log10(specgram.T + .001), origin = 'bottom', aspect = 'auto', cmap=cm.gray_r)
    2626  axis([0, len(specgram), 0, len(specgram[0])])
    27   ylabel('Frequency (Hz)')
    28   xlabel('Time (s)')
    2927  # show axes in Hz and seconds
    3028  time_step = hop_s / float(samplerate)
    3129  total_time = len(specgram) * time_step
    32   ticks = 10
    33   xticks( arange(ticks) / float(ticks) * len(specgram),
    34       [x * total_time / float(ticks) for x in range(ticks) ] )
    35   yticks( arange(ticks) / float(ticks) * len(specgram[0]),
    36       [x * samplerate / 2. / float(ticks) for x in range(ticks) ] )
     30  print "total time: %0.2fs" % total_time,
     31  print ", samplerate: %.2fkHz" % (samplerate / 1000.)
     32  n_xticks = 10
     33  n_yticks = 10
     34
     35  def get_rounded_ticks( top_pos, step, n_ticks ):
     36      top_label = top_pos * step
     37      # get the first label
     38      ticks_first_label = top_pos * step / n_ticks
     39      # round to the closest .1
     40      ticks_first_label = round ( ticks_first_label * 10. ) / 10.
     41      # compute all labels from the first rounded one
     42      ticks_labels = [ ticks_first_label * n for n in range(n_ticks) ] + [ top_label ]
     43      # get the corresponding positions
     44      ticks_positions = [ ticks_labels[n] / step for n in range(n_ticks) ] + [ top_pos ]
     45      # convert to string
     46      ticks_labels = [  "%.1f" % x for x in ticks_labels ]
     47      # return position, label tuple to use with x/yticks
     48      return ticks_positions, ticks_labels
     49
     50  # apply to the axis
     51  xticks( *get_rounded_ticks ( len(specgram), time_step, n_xticks ) )
     52  yticks( *get_rounded_ticks ( len(specgram[0]), (samplerate / 2. / 1000.) / len(specgram[0]), n_yticks ) )
     53  ylabel('Frequency (kHz)')
     54  xlabel('Time (s)')
    3755
    3856if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.