Ifft2 results do not match that of irfft2 in Pyhton

조회 수: 2 (최근 30일)
Seyedalireza Abootorabi
Seyedalireza Abootorabi 2025년 2월 28일
편집: Matt J 2025년 2월 28일
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
Matt J
Matt J 2025년 2월 28일
편집: Matt J 2025년 2월 28일
Please provide the input data files, both the cases that give the right answer and the ones that don't.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2025년 2월 28일
편집: Matt J 2025년 2월 28일
I'm not a Python user, but if rfft2 only gives you positive x-frequencies, I would imagine it also only gives you positive y-frequencies as well, no? If so, why are you only mirroring across columns?

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by