converting from conv2 to fft2

1 vue (au cours des 30 derniers jours)
mathango
mathango le 16 Mai 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

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by