views:

71

answers:

2

I am looking for a simple (pseudo)code that spectrum-inverse a sampled audio signal. Ideally C++

The code should support different sample rates (16/32/48KHz).

+1  A: 

In order to get something that has the same type of temporal structure as the original, you need to

  • Create a spectrogram (with some window size)
  • Pick some upper and lower frequency bounds that you'll flip
  • Flip the spectogram's intensities within those bounds
  • Resynthesize a sound signal consistent with those frequencies

Since it's an audio signal, it doesn't much matter that the phases will be all messed up. You can't generally hear them anyway. Except for the flipping part, ARSS does the spectrogram creation and sound resynthesis.

Otherwise, you can just take a FFT, invert the amplitudes of the components, and take the inverse FFT. But that will be essentially nonsensical, as it will completely scramble the temporal structure of the sound as well as the frequency structure.

Rex Kerr
Thank you, ARSS uses frequency filter bank, so all I can do is inverse the frequency bins. I Wonder if there is some mathematical manipulation that invert the frequencies 'smoothly' (without dividing it into bins).
Lior Kogan
You can use wavelets that aren't explicitly binned, but in your case that hardly matters. Low frequency sounds change much more slowly than high-frequency ones, so the flip is going to alter the smoothness anyway.
Rex Kerr
+1  A: 

Mixing the signal by Fs/2 will swap high frequencies and low frequencies - think of rotating the spectrum around the unit circle by half a turn. You can achieve this rotation by multiplying every other sample by -1.

Mixing by Fs/2 is equivalent to mixing by exp(j*pi*n). If x is the input and y the output,

y[n] = x[n] * exp(j*pi*n) = x[n] * [cos(pi*n) + j*sin(pi*n)]

This simplifies easily because sin(pi*n) is 0, and cos(pi*n) is alternating 1,-1.

mtrw
So simple... Unbelievable
Lior Kogan
This trick comes up a lot in DSP. For instance, if you want to design a high pass filter, it's usually easier to design a low pass filter with the desired cutoff proportion, then rotate it around the unit circle to make it high pass.
mtrw