code: def beat_extraction(short_features, window_size, plot=False):
      """
      This function extracts an estimate of the beat rate for a musical signal.
      ARGUMENTS:
       - short_features:     a np array (n_feats x numOfShortTermWindows)
       - window_size:        window size in seconds
      RETURNS:
       - bpm:            estimates of beats per minute
       - ratio:          a confidence measure
      """
  
      # Features that are related to the beat tracking task:
      selected_features = [
          0,
          1,
          3,
          4,
          5,
          6,
          7,
          8,
          9,
          10,
          11,
          12,
          13,
          14,
          15,
          16,
          17,
          18,
      ]
  
      max_beat_time = int(round(2.0 / window_size))
      hist_all = np.zeros((max_beat_time,))
      # for each feature
      for ii, i in enumerate(selected_features):
          # dif threshold (3 x Mean of Difs)
          dif_threshold = (
              2.0
              * (
                  np.abs(
                      short_features[i, 0:-1] - short_features[i, 1::]
                  )
              ).mean()
          )
          if dif_threshold <= 0:
              dif_threshold = 0.0000000000000001
          # detect local maxima
          [pos1, _] = utilities.peakdet(
              short_features[i, :], dif_threshold
          )
          position_diffs = []
          # compute histograms of local maxima changes
          for j in range(len(pos1) - 1):
              position_diffs.append(pos1[j + 1] - pos1[j])
          histogram_times, histogram_edges = np.histogram(
              position_diffs, np.arange(0.5, max_beat_time + 1.5)
          )
          hist_centers = (
              histogram_edges[0:-1] + histogram_edges[1::]
          ) / 2.0
          histogram_times = (
              histogram_times.astype(float) / short_features.shape[1]
          )
          hist_all += histogram_times
          if plot:
              plt.subplot(9, 2, ii + 1)
              plt.plot(short_features[i, :], "k")
              for k in pos1:
                  plt.plot(k, short_features[i, k], "k*")
              f1 = plt.gca()
              f1.axes.get_xaxis().set_ticks([])
              f1.axes.get_yaxis().set_ticks([])
  
      if plot:
          plt.show(block=False)
          plt.figure()
  
      # Get beat as the argmax of the agregated histogram:
      max_indices = np.argmax(hist_all)
      bpms = 60 / (hist_centers * window_size)
      bpm = bpms[max_indices]
      # ... and the beat ratio:
      ratio = hist_all[max_indices] / (hist_all.sum() + eps)
  
      if plot:
          # filter out >500 beats from plotting:
          hist_all = hist_all[bpms < 500]
          bpms = bpms[bpms < 500]
  
          plt.plot(bpms, hist_all, "k")
          plt.xlabel("Beats per minute")
          plt.ylabel("Freq Count")
          plt.show(block=True)
  
      return bpm, ratio
  
file_path: pyAudioAnalysis/pyAudioAnalysis/MidTermFeatures.py
imports: from __future__ import print_function
  import os
  import time
  import glob
  import numpy
  import matplotlib.pyplot
  import sys
  from pyAudioAnalysis import utilities
  from pyAudioAnalysis import audioBasicIO
  from pyAudioAnalysis import ShortTermFeatures
label_desc: Use image node_id 1 for calling a global function with example usage: beat_extraction(short_features, window_size, plot) and returns: bpm,  ratio