converting from conv2 to fft2

1 次查看(过去 30 天)
mathango
mathango 2016-5-16
Does any one knows how to convert the following code into 2D and 3D version?
if true
% 1D algorithm
x = rand(1e5,1);
y = rand(1e5,1);
tic, z1 = conv(x,y); toc
n = length(x) + length(y) - 1;
tic, z2 = ifft(fft(x,n) .* fft(y,n)); toc
disp(max(abs(z1-z2)./abs(z1)))
% 2D algorithm with 'same'
x = rand(1e4,1e4);
y = rand(1e2,1e2);
tic, z1 = conv2(x,y,'same'); toc
n = length(x) + length(y) - 1;
tic, z2 = ifft2(fft2(x,n) .* fft2(y,n)); toc
disp(max(abs(z1-z2)./abs(z1)))
% 3D algorithm with 'same'
x = rand(1e3,1e3,1e3);
y = rand(1e2,1e2,1e2);
tic, z1 = convn(x,y,'same'); toc
n = length(x) + length(y) - 1;
tic, z2 = ifftn(fftn(x,n) .* fftn(y,n)); toc
disp(max(abs(z1-z2)./abs(z1)))
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by