Scale correction for signal reconstruction #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I recently found a small bug on the code. When a signal is reconstructed via overlap and add, the signal has twice the amplitude than the original one. This is caused due to the amount of frame overlap used, anything above 50% overlap leads to an scale on the amplitude. In this case, there is a 75% overlap, as to form the STFT you take frames of 32ms with 8ms shifts, that is 75% overlap. In order to know more about this phenomenon I would recommend you to take a look at this post: https://dsp.stackexchange.com/questions/53367/overlap-add-time-domain-audio-frames-how-does-normalization-scaling-work-with-o
This problem was previously addressed by the community, so TensorFlow released a function to correct the amplitude on the iSTFT: https://www.tensorflow.org/api_docs/python/tf/signal/inverse_stft_window_fn. However, this solution is only valid if you use the "inverse_stft" TF function (https://www.tensorflow.org/api_docs/python/tf/signal/inverse_stft), which you do not. In order to solve this you can always create a custom window function with all ones, however I believe it is cleaner to just multply each frame by the right scaling factor, in this case frame_step/frame_len
Below you may find a toy example I did with a simple sinusoide signal:
Side note: I would personally recommend using a Hanning window function to obtain a signal with less artefacts. See the same example as above after using a Hanning window:
Please, find below the toy code I used to obtain the previous plots: