Acyclic FFT Convolution in Matlab
The following example illustrates the implementation of acyclic convolution using a Cooley-Tukey FFT in matlab:
x = [1 2 3 4]; h = [1 1 1]; nx = length(x); nh = length(h); nfft = 2^nextpow2(nx+nh-1) xzp = [x, zeros(1,nfft-nx)]; hzp = [h, zeros(1,nfft-nh)]; X = fft(xzp); H = fft(hzp); Y = H .* X; format bank; y = real(ifft(Y)) % zero-padded result yt = y(1:nx+nh-1) % trim and print yc = conv(x,h) % for comparisonProgram output:
nfft = 8 y = 1.00 3.00 6.00 9.00 7.00 4.00 0.00 0.00 yt = 1.00 3.00 6.00 9.00 7.00 4.00 yc = 1 3 6 9 7 4
Next Section:
FFT versus Direct Convolution
Previous Section:
Acyclic FFT Convolution