Skip to content

STFT --> inverse_STFT not reconstructing the original signal when using no window #53205

@giamic

Description

@giamic

Tensorflow is not reconstructing the original signal when applying the STFT followed by the inverse STFT when using no window. The problems arise when the frames of the STFT overlap: It seems like every frame contributes with a weight of 1 regardless of the number of overlapping frames N = frame_size / frame_step. As a result, the central part of the signal is N times larger than the original. Here is a minimal code to reproduce the error:

import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf

size = 2048
frame_length = 512
frame_step = 128
waveform = np.sin(np.arange(size) * 1 / 100)

stft = tf.signal.stft(waveform, frame_length, frame_step, window_fn=None)
inverse_stft = tf.signal.inverse_stft(stft, frame_length, frame_step, window_fn=None)

plt.plot(waveform)
plt.plot(inverse_stft)
plt.show()
plt.clf()

Broken stft --> istft applied to sinusoidal signal:

Notice that I'm using no window. If I put the Hann window, the central part works well but the borders are smoothly going to zero, a related but surprisingly different bug that is already documented here: #36616. The implementation of scipy works well under all circumstances.

I'm using Tensorflow 2.6.0 installed with tensorflow-macos on an Apple M1 MacBookPro.

Metadata

Metadata

Assignees

Labels

2.6.0comp:signaltf.signal related issuesstaleThis label marks the issue/pr stale - to be closed automatically if no activitystat:awaiting responseStatus - Awaiting response from authortype:bugBug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions