1
$\begingroup$

I would like to convolve two signals:

  • Room impulse response that was obtained by deconvolution, measured at 48 kHz. Truncated to 8192 samples.
  • Anechoic recording (.wav) recorded at 41.1 kHz

If I perform a fast convolution in the frequency domain, I understand I should do as follows:

[x, fs] = audioread('sound.wav');
L = length(x);
M = length(rir);

N = 2^nextpow2(L + M - 1);
H = fft(rir, N);
X = fft(x, N); 

y = real(ifft(H.*X));
iend = M+L-1;                                      
y = y(1:iend)';

audiowrite('convAudio.wav', y, fs)

Is this correct? Can I use the sampling frequency of the .wav signal?

Thanks in advance for your help!

$\endgroup$
1
  • 2
    $\begingroup$ No, you should resample one of the signals so that they have the same sample rate. $\endgroup$
    – ZR Han
    Commented Jan 26, 2022 at 10:15

1 Answer 1

1
$\begingroup$

Is this correct?

No. This only works if filter and signal have the same sample rate. Either up-sample the signal or down-sample the impulse response, depending on what you want your output sample rate to be. It might be the easiest to down-sample the impulse response to 44.1kHz

Resampling from 48kHz to 44.1kHz is fairly awkward and involves a fair bit of trade-offs, so the best option depends on your specific requirements. For a room impulse response h44 = resample(h48,441,480)*480/441 is probably a good starting point (although it messes up the transients a bit).

Tip: you can use fftfilt() to implement the frequency domain filter operation. That's significantly more efficient than doing a full size FFT over the whole wave file and it handles frame size, overlap and hop size automatically.

$\endgroup$
2
  • $\begingroup$ thanks a lot for your answer! May I ask why you add that factor? *480/441 $\endgroup$
    – Mia1
    Commented Feb 14, 2022 at 9:40
  • $\begingroup$ This maintains the level in the frequency domain. If you do an FFT of both versions and plot them at their respective sample rates, they will sit mostly on top of each other. $\endgroup$
    – Hilmar
    Commented Feb 14, 2022 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.