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 Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by