code: def instantaneous_frequency(
      phase_angle, time_axis=-2, use_unwrap=True
  ):
      """Transform a fft tensor from phase angle to instantaneous frequency.
  
      Take the finite difference of the phase. Pad with initial phase to keep the
      tensor the same size.
      Args:
        phase_angle: Tensor of angles in radians. [Batch, Time, Freqs]
        time_axis: Axis over which to unwrap and take finite difference.
        use_unwrap: True preserves original GANSynth behavior, whereas False will
            guard against loss of precision.
  
      Returns:
        dphase: Instantaneous frequency (derivative of phase). Same size as input.
      """
      if use_unwrap:
          # Can lead to loss of precision.
          phase_unwrapped = unwrap(phase_angle, axis=time_axis)
          dphase = diff(phase_unwrapped, axis=time_axis)
      else:
          # Keep dphase bounded. N.B. runs faster than a single mod-2pi expression.
          dphase = diff(phase_angle, axis=time_axis)
          dphase = tf.where(dphase > np.pi, dphase - 2 * np.pi, dphase)
          dphase = tf.where(dphase < -np.pi, dphase + 2 * np.pi, dphase)
  
      # Add an initial phase to dphase.
      size = phase_angle.get_shape().as_list()
      size[time_axis] = 1
      begin = [0 for unused_s in size]
      phase_slice = tf.slice(phase_angle, begin, size)
      dphase = tf.concat([phase_slice, dphase], axis=time_axis) / np.pi
      return dphase
  
file_path: magenta/magenta/models/gansynth/lib/spectral_ops.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 6 for calling a global function with example usage: instantaneous_frequency(phase_angle, time_axis, use_unwrap) and returns: dphase