1

Overall what I need to do is fft two wav files, convolve them, and then inverse fft (to find the time stamps of one sound in a larger, noiser wav file.

I have the fft of two wav files thanks to bunkus at Python Scipy FFT wav files

Having used this code, how would I convolve two wav files given the frequency and amplitude arrays of each? If I used numpy.convolve would the two inputs be the frequency array of each wav file? The amplitude array? What about scipy.signal.fftconvolve()?

I need to output the convolution in a format such that it can then be passed into np.fft.ifft() on this convolution.

quinz
  • 1,282
  • 4
  • 21
  • 33
  • 1
    You are looking to convolve the signals, which is equivalent to multiplying in the frequency domain. So either use `numpy.convolve` or `scipy.signal.fftconvolve` on the data before applying the FFT, or apply the FFT, multiply the two results, then IFFT. However, to find the one signal in the other, you should not use convolution, but the cross correlation. This requires flipping the "model" signal before applying the convolution. – Cris Luengo Sep 03 '19 at 14:30
  • So in summary I should flip the model signal, apply convolution, fft, then ifft? How would I flip the signal? And what would be the input into the fft at that point? The frequency array of the convoluted result? – Nina Moorman Sep 03 '19 at 18:32
  • No. convolution(a,b) == ifft(fft(a)*fft(b)). – Cris Luengo Sep 03 '19 at 19:45

1 Answers1

0

To do FFT fast linear convolution you need to first zero pad both data vectors before the FFTs, to a least a length N+M-1 (commonly double to the next power of 2).

Then the multiplication needs to be a complex multiplication of the two FFT's complex results, not a real multiplication of just the magnitudes.

Make sure the IFFT input is conjugate symmetric if you want a strictly real convolution result.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153