converting from conv2 to fft2

2 views (last 30 days)
mathango
mathango on 16 May 2016
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

Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!