def testPolar2Rect(self, shape): mag_np = 10 * np.random.rand(*shape) phase_np = np.pi * (2 * np.random.rand(*shape) - 1) rect_np = mag_np * np.cos(phase_np) + 1.0j * mag_np * np.sin(phase_np) mag_tf = tf.convert_to_tensor(mag_np) phase_tf = tf.convert_to_tensor(phase_np) with self.cached_session() as sess: rect_tf = sess.run(spectral_ops.polar2rect(mag_tf, phase_tf)) self.assertAllClose(rect_np, rect_tf)
def specgrams_to_stfts(self, specgrams): """Converts specgrams to stfts. Args: specgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2]. Returns: stfts: Complex64 tensor of stft, shape [batch, time, freq, 1]. """ logmag = specgrams[:, :, :, 0] p = specgrams[:, :, :, 1] mag = tf.exp(logmag) if self._ifreq: phase_angle = tf.cumsum(p * np.pi, axis=-2) else: phase_angle = p * np.pi return spectral_ops.polar2rect(mag, phase_angle)[:, :, :, tf.newaxis]