Ifft2 results do not match that of irfft2 in Pyhton
5 次查看(过去 30 天)
显示 更早的评论
Hi All,
I am using the rfft2 function in Python to get the Fourier trasnformed data and use the ifft2 function in Matlab to get back the original data.
I firstly, load the spectral data from Python
clear
clc
rfft2_real = load('rfft2_real.txt');
rfft2_imag = load('rfft2_imag.txt');
Then I construct the whole spectral domain by adding the imaginary and real terms together
% Reconstruct the complex rfft2 output
rfft2_result = rfft2_real + 1i * rfft2_imag;
since rfft2 in Python stores only the positive frequencies for one of the dimensions I had to account for the missing negative frequencies in the follwoing way:
% Compute full FFT2 result by mirroring the data
[m, n_half] = size(rfft2_result);
n = 2 * (n_half - 1); % Reconstruct full FFT size
% Reconstruct the full frequency domain
fft2_result = zeros(m, n);
fft2_result(:, 1:n_half) = rfft2_result; % Copy half-spectrum
fft2_result(:, n_half+1:n) = conj(fliplr(rfft2_result(:, 2:end-1))); % Mirror
% Compute the inverse FFT to get back the original matrix
reconstructed_x = ifft2(fft2_result)
I played with this code and it gives me the right answer for some signals but for others it does not. Anybody knows the issue?
1 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!