code: def _rdft(signal, dft_length):
      """DFT for real signals.
      Calculates the onesided dft, assuming real signal implies complex conjugate symetry,
      hence only onesided DFT is returned.
  
      Args:
          signal (tensor) signal to transform, assumes that the last dimension is the time dimension
              signal can be framed, e.g. (1, 40, 1024) for a single batch of 40 frames of
              length 1024
          dft_length (int) - DFT length
  
      Returns:
          spec_real (float32 tensor) - real part of spectrogram, e.g. (1, 40, 513) for a 1024 length dft
          spec_imag (float32 tensor) - imag part of spectrogram, e.g. (1, 40, 513) for a 1024 length dft
      """
      # calculate the positive frequency atoms, and tell tensorflow this is a constant.
      rdft_mat = _rdft_matrix(dft_length)
  
      # tflite doest support complex types so split into real and imaginary:
      rdft_mat_real = tf.constant(np.real(rdft_mat))
      rdft_mat_imag = tf.constant(np.imag(rdft_mat))
  
      frame_length = tf.shape(signal)[-1]
      # Right-padding, in case the frame length and DFT lenght are different,
      # pad the signal on the right hand side of the frame
      pad_values = tf.concat(
          [
              tf.zeros([tf.rank(signal) - 1, 2], tf.int32),
              [[0, dft_length - frame_length]],
          ],
          axis=0,
      )
  
      signal_padded = tf.pad(signal, pad_values)
  
      # matrix multiplying real and imag separately is faster than using complex types.
      spec_real = tf.matmul(signal_padded, rdft_mat_real)
      spec_imag = tf.matmul(signal_padded, rdft_mat_imag)
      spectrogram = tf.stack([spec_real, spec_imag], axis=-1)
  
      return spectrogram
  
file_path: kapre/kapre/tflite_compatible_stft.py
imports: import math
  import tensorflow
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: _rdft(signal, dft_length) and returns: spectrogram