/ tutorials / wave-acoustics
Sign in
tutorials / wave-acoustics
wave-acoustics / src / matlab / wv_fftconv.m
14 lines · 498 BCodeBlameHistory
2% WV_FFTCONV Linear convolution of two real vectors, by FFT.
3%
4% The direct sum costs the product of the two lengths, which for a two-second
5% sound and a one-second impulse response is about 4e9 operations; the FFT
6% costs a few times n log n. The result is the full convolution, of length
7% numel(a) + numel(b) - 1, as a column.
8a = a(:);
9b = b(:);
10n = numel(a) + numel(b) - 1;
11nfft = 2 ^ nextpow2(n);
12y = real(ifft(fft(a, nfft) .* fft(b, nfft)));
13y = y(1:n);
14end
↑↓ move↵openescclose