How to Use ifft in MATLAB: Syntax and Examples
In MATLAB, use the
ifft function to compute the inverse discrete Fourier transform of a vector or matrix. The syntax is y = ifft(x), where x is the frequency domain data and y is the time domain signal.Syntax
The basic syntax of ifft in MATLAB is:
y = ifft(x): Computes the inverse discrete Fourier transform ofx.y = ifft(x, n): Computes the inverse transform with lengthn, padding or truncatingxas needed.y = ifft(x, [], dim): Computes along the dimensiondimofx.
This function converts frequency domain data back to the time domain.
matlab
y = ifft(x) y = ifft(x, n) y = ifft(x, [], dim)
Example
This example shows how to compute the inverse Fourier transform of a simple frequency domain vector and plot the result.
matlab
x = [1 1i -1 -1i]; y = ifft(x); % Display the result disp('Inverse FFT result:'); disp(y); % Plot real and imaginary parts plot(real(y), '-o', 'DisplayName', 'Real Part'); hold on; plot(imag(y), '-x', 'DisplayName', 'Imaginary Part'); hold off; title('Inverse FFT of x'); xlabel('Index'); ylabel('Amplitude'); legend;
Output
Inverse FFT result:
0.0000 + 0.0000i
1.0000 + 0.0000i
0.0000 + 0.0000i
0.0000 - 1.0000i
Common Pitfalls
Common mistakes when using ifft include:
- Not matching the length
nwith the original FFT length, causing unexpected padding or truncation. - Ignoring the dimension argument when working with matrices, which can lead to incorrect results.
- Assuming the output is always real; if the input has small imaginary parts due to numerical errors, the output may also be complex.
Always verify the input size and dimension to avoid these issues.
matlab
x = [1 2 3]; % Warning: ifft with different length truncates or pads y_wrong = ifft(x, 5); % Correct: use original length or correct dimension y_right = ifft(x, length(x));
Quick Reference
| Syntax | Description |
|---|---|
| y = ifft(x) | Inverse FFT of vector or matrix x |
| y = ifft(x, n) | Inverse FFT with length n, pads or truncates x |
| y = ifft(x, [], dim) | Inverse FFT along dimension dim of x |
Key Takeaways
Use
ifft(x) to convert frequency data back to time domain in MATLAB.Specify length
n to control output size and avoid padding issues.Use the dimension argument when working with multi-dimensional arrays.
Output may be complex; check for small imaginary parts due to numerical errors.
Always match
ifft parameters to your original FFT data for accurate results.