
- 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 - ifftshift() Function
The ifftshift method in SciPy is used to undo the effect of fftshift. The zero-frequency component shifts back to the start of the spectrum by using ifftshift() method.
This method is especially used when executing inverse FFT to rebuild original signals or images, after shifting the frequency components to the center for visualize and analysis using fftshift method. This is necessary because the IFFT expects the zero-frequency at the beginning of the spectrum for proper signal reconstruction.
Using ifftshift we restore the orginal-frequency so that IFFT works properly. This is essential for accurate signal or image recovery after shifting for analysis.
Syntax
Following is the syntax of the SciPy method −
.ifftshift(x, axes=None)
Parameters
Following is the parameters of ifftshift() method
x (array_like) The input array.
axes (optional) The axes along which the shift is performed. By default, it shifts along all axes.
Return Value
Returns a new array with the zero-frequency component shifted back to the beginning.
Example 1: Reversing Frequency Shift
This example demonstrates the use of ifftshift() method to get the original alignment of frequencies after applying fftshift() method for visualization. Following is the code −
import numpy as np arr = np.fft.fftfreq(8, 0.5) shifted_freq = np.fft.fftshift(arr) print("Shifted Frequencies:", shifted_freq) unshifted_freq = np.fft.ifftshift(shifted_freq) print("\nReversed Shifted Frequencies:", unshifted_freq)
Following is an output of the above code −
Shifted Frequencies: [-1. -0.75 -0.5 -0.25 0. 0.25 0.5 0.75] Reversed Shifted Frequencies: [ 0. 0.25 0.5 0.75 -1. -0.75 -0.5 -0.25]
Example 2: Reversing Frequencies for 2D Array
In the below example we will see how to use ifftshift() method to get the original alignment of 2D array after using fftshift() method. Following is the code −
import numpy as np arr_1d= np.arange(12) data= arr_1d.reshape(3,4) print("Original 2D Frequencies:\n", data) shifted_freqs = np.fft.fftshift(data) print("\nShifted 2D Frequencies:\n",shifted_freqs) reversed_freqs = np.fft.ifftshift(shifted_freqs) print("\nReversed freq (after ifftshift):\n ",reversed_freqs)
Output of the above code is as follows
Original 2D Frequencies: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] Shifted 2D Frequencies: [[10 11 8 9] [ 2 3 0 1] [ 6 7 4 5]] Reversed freq (after ifftshift): [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]]