(signal_tensor, fft_length)
return result_real_part, result_imag_part
Implement real-input Fourier Transform by matmul.
Implement real-input Fourier Transform by matmul.
Implement real - input Fourier Transform by matmul .
def _naive_rdft(signal_tensor, fft_length):
  """Implement real-input Fourier Transform by matmul."""
  # We are right-multiplying by the DFT matrix, and we are keeping
  # only the first half ("positive frequencies").
  # So discard the second half of rows, but transpose the array for
  # right-multiplication.
  # The DFT matrix is symmetric, so we could have done it more
  # directly, but this reflects our intention better.
  complex_dft_matrix_kept_values = _dft_matrix(fft_length)[:(
      fft_length // 2 + 1), :].transpose()
  real_dft_tensor = tf.constant(
      np.real(complex_dft_matrix_kept_values).astype(np.float32),
      name='real_dft_matrix')
  imag_dft_tensor = tf.constant(
      np.imag(complex_dft_matrix_kept_values).astype(np.float32),
      name='imaginary_dft_matrix')
  signal_frame_length = int(signal_tensor.shape[-1])
  half_pad = (fft_length - signal_frame_length) // 2
  pad_values = tf.concat([
      tf.zeros([tf.rank(signal_tensor) - 1, 2], tf.int32),
      [[half_pad, fft_length - signal_frame_length - half_pad]]
  ],
                         axis=0)
  padded_signal = tf.pad(signal_tensor, pad_values)
  result_real_part = tf.matmul(padded_signal, real_dft_tensor)
  result_imag_part = tf.matmul(padded_signal, imag_dft_tensor)
  return result_real_part, result_imag_part
def _naive_rdft ( signal_tensor , fft_length ) : # We are right-multiplying by the DFT matrix, and we are keeping # only the first half ("positive frequencies"). # So discard the second half of rows, but transpose the array for # right-multiplication. # The DFT matrix is symmetric, so we could have done it more # directly, but this reflects our intention better. complex_dft_matrix_kept_values = _dft_matrix ( fft_length ) [ : ( fft_length // 2 + 1 ) , : ] . transpose ( ) real_dft_tensor = tf . constant ( np . real ( complex_dft_matrix_kept_values ) . astype ( np . float32 ) , name = 'real_dft_matrix' ) imag_dft_tensor = tf . constant ( np . imag ( complex_dft_matrix_kept_values ) . astype ( np . float32 ) , name = 'imaginary_dft_matrix' ) signal_frame_length = int ( signal_tensor . shape [ - 1 ] ) half_pad = ( fft_length - signal_frame_length ) // 2 pad_values = tf . concat ( [ tf . zeros ( [ tf . rank ( signal_tensor ) - 1 , 2 ] , tf . int32 ) , [ [ half_pad , fft_length - signal_frame_length - half_pad ] ] ] , axis = 0 ) padded_signal = tf . pad ( signal_tensor , pad_values ) result_real_part = tf . matmul ( padded_signal , real_dft_tensor ) result_imag_part = tf . matmul ( padded_signal , imag_dft_tensor ) return result_real_part , result_imag_part