
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - irfft() Function
SciPy's irfft() method calculates the Inverse Real Fast Fourier Transform that converts frequency-domain data into the real-valued time or spatial domain. It does this in an efficient manner, eliminating the unnecessary negative frequency terms. This makes it ideal for processing real-valued datasets in numerous scientific and technical applications.
If the given input carries negative frequencies, then the irfft algorithm will compute them as conjugate versions of positive frequencies that appear like a real-valued signal. This assumption ensuresconsistency for real inputs derived from rfft.
This method is more commonly used for recovery from frequency-domain filtering or operations in signal processing, imaging reconstruction, and spectrum analysis.
The norm option controls scaling, for example, "forward" for proportional scaling, overwrite_x allows you to overwrite the input data to have better performance in large scales.
Syntax
The syntax for the SciPy irfft() method is as follows −
.irfft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, *, plan=None)
Parameters
This method accepts the following parameters −
x (array_like) − Input array representing real-valued frequency-domain data.
n (int, optional) − Length of the inverse FFT output. If greater than the input size, the data is padded; if smaller, it is truncated.
axis (int, optional) − Axis along which to compute the inverse FFT. Defaults to the last axis (-1).
norm (backward, ortho, forward), optional − The normalization mode allows control over scaling: "backward" (default, no scaling), "ortho" (unitary scaling for energy preservation), and "forward" (scales the output by 1/n, where n is the transform length).
overwrite_x (bool, optional) − If True, allows the input array x to be overwritten for better performance. Default is False.
workers (int, optional) − Number of parallel workers to use for computation. Default is None, meaning a single thread is used.
plan (object, optional) − Precomputed plan for FFT optimization (advanced use). Default is None.
Return Value
out ndarray − Returns a real-valued time or spatial domain signal reconstructed from the input frequency-domain data.
Example 1: irfft() with 'n' parameter
This is the basic example of SciPy irfft() which computes the inverse of the real Fast Fourier Transform (RFFT) from frequency domain to time or spatial domain, with the n parameter which specifies the output length.
import scipy.fft import numpy as np # Frequency-domain data (result of rfft) frequency_data = np.array([8 + 0j, 0 + 0j, 0 + 0j]) # Reconstruct the original time-domain signal time_data = scipy.fft.irfft(frequency_data, n=4) print("Reconstructed Signal:", time_data)
When we run above program, it produces following result
Reconstructed Signal: [2. 2. 2. 2.]
Example 2: Comparison of ifft() and irfft()
SciPy's ifft reconstructs a signal from a full complex input including positive and negative frequencies and returns as a complex output. Instead, irfft takes as input a real-valued input from rfft, which does not include the negative frequencies and returns purely real output.
In the above code, ifft works on the entire frequency data, whereas irfft focuses on the real inputs, which reduces redundant calculations and improves efficiency for real-valued datasets.
import scipy.fft # Using ifft for full inverse FFT on a complex input ifft_result = scipy.fft.ifft([2, -2j, -2, 2j]) # Using irfft for inverse FFT on real-valued frequency data irfft_result = scipy.fft.irfft([2, -2j, -2]) print("IFFT Result:", ifft_result) print("IRFFT Result:", irfft_result)
Following is an output of the above code −
IFFT Result: [0.+0.j 2.+0.j 0.+0.j 0.+0.j] IRFFT Result: [0. 2. 0. 0.]
Example 3: Handling Invalid Input in irfft()
Input should be numeric; otherwise, an Value error will be generated when using irfft() method.
The following code illustrates why data type validation of input values is important when calling the irfft() method.
import scipy.fft # Invalid input with non-numeric values frequency_data = [10, 'a', -5] try: scipy.fft.irfft(frequency_data) except ValueError as e: print("Error:", e)
Output of the above code is as follows −
ValueError: could not convert string to float: 'a'
Example 4: Using norm="forward" for Proper Amplitude Scaling
The norm="forward" argument in irfft from SciPy ensures that the amplitude of the reconstructed signal directly maps to the frequency domain with proportional energy. This is an important consideration for any application requiring proper amplitude scaling.
The below code, reconstructs a real-valued signal from frequency data using irfft() and forward normalization, which makes it ideal for the accurate signal processing task.
import scipy.fft import numpy as np a = [20, -10+5j, -5] reconstructed_signal = scipy.fft.irfft(a, norm="forward") print("Reconstructed Signal with Forward Norm:", reconstructed_signal)
Output of the above code is as follows −
Reconstructed Signal with Forward Norm: [-5. 15. 35. 35.]
Example 5: irfft with overwrite_x = True parameter
The overwrite_x = True parameter of irfft() in SciPy instructs the function to reuse the memory of the input array for the computation, which improves performance by reducing memory usage. This is useful for large datasets and performance-critical applications.
The method makes use of irfft to reconstruct a real-valued signal from frequency data, maximizing memory efficiency by allowing input overwriting throughout the transformation.
import scipy.fft import numpy as np data = np.array([10, -4+2j, -6], dtype=complex) reconstructed_signal = scipy.fft.irfft(data, overwrite_x=True) print("Reconstructed Signal:", reconstructed_signal)
Output of the above code is as follows −
Reconstructed Signal: [-1. 3. 3. 5.]