question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synthetic phase for inverse transforms

See original GitHub issue

Would it be useful to have inverse transforms istft, icqt #165 synthesize phase when the input is magnitude spectra? @dpwe’s repsonse to #424 provides an example of how to do this for inverting MFCCs by transferring the phase of the corresponding forward transform of white noise.

I’ve test-driven this on my icqt prototype, and it sounds pretty good; much better than a magnitude-only reconstruction.

It’s a bit of a nuisance to do this by hand since the parameters and duration need to be matched to the input signal. It would be easy to do this from within the inverse transform though, since that information is all present. I’m thinking an optional (defaulting to False) parameter.

Thoughts?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:26 (13 by maintainers)

github_iconTop GitHub Comments

8reactions
jongwookcommented, Apr 3, 2017

I’m using this implementation of Griffin-Lim algorithm, and the restored audio sounds perceivably better than random/from-white-noise initialization of phases.

def griffinlim(spectrogram, n_iter = 100, window = 'hann', n_fft = 2048, hop_length = -1, verbose = False):
    if hop_length == -1:
        hop_length = n_fft // 4

    angles = np.exp(2j * np.pi * np.random.rand(*spectrogram.shape))

    t = tqdm(range(n_iter), ncols=100, mininterval=2.0, disable=not verbose)
    for i in t:
        full = np.abs(spectrogram).astype(np.complex) * angles
        inverse = librosa.istft(full, hop_length = hop_length, window = window)
        rebuilt = librosa.stft(inverse, n_fft = n_fft, hop_length = hop_length, window = window)
        angles = np.exp(1j * np.angle(rebuilt))

        if verbose:
            diff = np.abs(spectrogram) - np.abs(rebuilt)
            t.set_postfix(loss=np.linalg.norm(diff, 'fro'))

    full = np.abs(spectrogram).astype(np.complex) * angles
    inverse = librosa.istft(full, hop_length = hop_length, window = window)

    return inverse

Is it something to be avoided due to the slow speed? In that case, I think @Jonathan-LeRoux’s algorithm would be a nice addition, although I found it hard to write it efficiently only using Python.

4reactions
bmcfeecommented, Aug 31, 2017

Curious, what use cases are there when the phase from the forward transform can’t be kept around for doing the inverse?

The main one I have in mind is sonifying samples from a generative model of magnitude spectra.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Synthesis, Calculating the Inverse DFT
They are included here for a tremendously important reason: The most efficient way to calculate the DFT is through the Fast Fourier Transform...
Read more >
7.2. The Inverse DFT — Digital Signals Theory - Brian McFee
The sign of the complex exponent is flipped: positive for inverse transform, negative for the forward transform;. The summation ranges over m (frequencies), ......
Read more >
Gradient-search phase-retrieval algorithm for inverse synthetic ...
A class of algorithms referred to as ''phase-retrieval" algorithms can correct phase errors without the need for prominent points.
Read more >
Inverse FFT Synthesis - CCRMA
The basic idea was to tabulate window main-lobes for a variety of sweep rates. (The phase variation across the main lobe determines the...
Read more >
Example of discrete and inverse discrete Fourier transform
Generate synthetic data centered around zero¶ ... We will compare the Fourier transform with and without taking into consideration about the phase information....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found