code: def spectrogram(
      signal,
      sampling_rate,
      window,
      step,
      plot=False,
      show_progress=False,
  ):
      """
      Short-term FFT mag for spectogram estimation:
      Returns:
          a np array (numOfShortTermWindows x num_fft)
      ARGUMENTS:
          signal:         the input signal samples
          sampling_rate:  the sampling freq (in Hz)
          window:         the short-term window size (in samples)
          step:           the short-term window step (in samples)
          plot:           flag, 1 if results are to be ploted
          show_progress flag for showing progress using tqdm
      RETURNS:
      """
      window = int(window)
      step = int(step)
      signal = np.double(signal)
      signal = signal / (2.0**15)
      signal = dc_normalize(signal)
  
      num_samples = len(signal)  # total number of signals
      count_fr = 0
      num_fft = int(window / 2)
      specgram = np.zeros(
          (int((num_samples - window) / step) + 1, num_fft),
          dtype=np.float64,
      )
      for cur_p in tqdm(
          range(window, num_samples - window + 1, step),
          disable=not show_progress,
      ):
          count_fr += 1
          x = signal[cur_p : cur_p + window]
          X = abs(fft(x))
          X = X[0:num_fft]
          X = X / len(X)
          specgram[count_fr - 1, :] = X
  
      freq_axis = [
          float((f + 1) * sampling_rate) / (2 * num_fft)
          for f in range(specgram.shape[1])
      ]
      time_axis = [
          float(t * step) / sampling_rate
          for t in range(specgram.shape[0])
      ]
  
      if plot:
          fig, ax = plt.subplots()
          imgplot = plt.imshow(specgram.transpose()[::-1, :])
          fstep = int(num_fft / 5.0)
          frequency_ticks = range(0, int(num_fft) + fstep, fstep)
          frequency_tick_labels = [
              str(
                  sampling_rate / 2
                  - int((f * sampling_rate) / (2 * num_fft))
              )
              for f in frequency_ticks
          ]
          ax.set_yticks(frequency_ticks)
          ax.set_yticklabels(frequency_tick_labels)
          t_step = int(count_fr / 3)
          time_ticks = range(0, count_fr, t_step)
          time_ticks_labels = [
              "%.2f" % (float(t * step) / sampling_rate)
              for t in time_ticks
          ]
          ax.set_xticks(time_ticks)
          ax.set_xticklabels(time_ticks_labels)
          ax.set_xlabel("time (secs)")
          ax.set_ylabel("freq (Hz)")
          imgplot.set_cmap("jet")
          plt.colorbar()
          plt.show()
      print(specgram.shape)
      return specgram, time_axis, freq_axis
  
imports: from __future__ import print_function
  import math
  import numpy
  import sys
  from scipy.fftpack import fft
  import matplotlib.pyplot
  from scipy.signal import lfilter
  from scipy.fftpack.realtransforms import dct
  from tqdm import tqdm
label_desc: Use image node_id 15 for calling a global function with example usage: spectrogram(signal, sampling_rate, window, step, plot, show_progress) and returns: specgram,  time_axis,  freq_axis