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