
- 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 Fast Fourier Transform (FFT)
The Fast Fourier Transform (FFT) in SciPy is a powerful algorithm designed to compute the Discrete Fourier Transform (DFT) and its inverse with high efficiency, significantly reducing the computational cost compared to the standard DFT.
This allows for the conversion of signals between the time and frequency domains by enabling various types of signal and data analysis.
Scipy Fast Fourier Transform in SciPy
SciPy's scipy.fft module offers a suite of functions for performing one-dimensional, two-dimensional and even multi-dimensional FFTs. The primary function scipy.fft.fft is used for computing the one-dimensional FFT of an input array while scipy.fft.ifft calculates the inverse FFT by converting frequency data back to the time domain.
For data sets that consist of real numbers we can use scipy.fft.rfft and scipy.fft.irfft are optimized versions that only handle positive frequencies by reducing both computational time and memory usage.
For more complex data the functions such as scipy.fft.fftn and scipy.fft.ifftn extend these capabilities to multi-dimensional arrays which is particularly useful for tasks such as image processing.
SciPys FFT functions also provide flexibility with features such as normalization, axis specification and zero-padding. Moreover scipy.fft.fftshift and scipy.fft.ifftshift are useful for shifting the zero-frequency component to the center or moving it back to the edges by aiding in frequency spectrum visualization.
Key Features of Fast Fourier Transform(FFT)
The features make FFT a versatile and powerful tool for various applications such as signal processing, image analysis and audio processing. Following are the key features of Fast Fourier Transform(FFT) −
- Efficiency: FFT dramatically reduces the computational complexity of calculating the Discrete Fourier Transform (DFT) from O(N)2 to O(N log N) by making it much faster for large datasets.
- Signal Analysis: The FFT transforms time-domain signals into their frequency-domain representation by enabling the analysis of different frequency components in the signal.
- Inverse FFT (IFFT): The inverse FFT function reconstructs the original time-domain signal from its frequency-domain components.
- Support for Real and Complex Inputs: FFT can handle both real-valued and complex-valued data. Specialized versions such as rfft for real-valued inputs further optimize performance.
- Multi-Dimensional FFTs: The Functions such as fftn and ifftn allow FFT to be applied to multi-dimensional data such as images or volumetric data by making it useful in image and 3D data analysis.
- Zero-Padding and Truncation: Zero-padding is used to increase the resolution of the frequency spectrum while truncation can be used to reduce computational costs for signals with significant zeros.
- Frequency Shifting: Functions such as fftshift and ifftshift shift the zero-frequency component to the center or back by facilitating better visualization of the frequency spectrum.
- Normalization Options: Various normalization options ensure accurate scaling of the FFT results according to different conventions.
Example 1
Heres a simple example of using SciPy to compute the one-dimensional Fast Fourier Transform (FFT) of a signal along with its visualization −
import numpy as np from scipy.fft import fft, ifft import matplotlib.pyplot as plt # Create a sample signal N = 600 # Number of sample points T = 1.0 / 800.0 # Sample spacing x = np.linspace(0.0, N*T, N, endpoint=False) # Create a signal composed of two different frequencies y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x) # Compute the FFT yf = fft(y) # Compute the corresponding frequencies xf = np.fft.fftfreq(N, T)[:N//2] # Plot the original signal plt.figure(figsize=(12, 6)) plt.subplot(2, 1, 1) plt.plot(x, y) plt.title("Original Signal") plt.xlabel("Time (s)") plt.ylabel("Amplitude") # Plot the FFT (magnitude spectrum) plt.subplot(2, 1, 2) plt.plot(xf, 2.0/N * np.abs(yf[:N//2])) plt.title("FFT - Magnitude Spectrum") plt.xlabel("Frequency (Hz)") plt.ylabel("Magnitude") plt.tight_layout() plt.show()
Following is the output of the 1-Dimensional Fast Fourier Transform(FFT) −

Example 2
Heres a simple example of performing a two-dimensional Fast Fourier Transform (2D FFT) using SciPy. This example shows how to transform a 2D image or any 2D array into the frequency domain and then back into the spatial domain using the inverse 2D FFT −
import numpy as np import matplotlib.pyplot as plt from scipy.fft import fft2, ifft2, fftshift # Create a sample 2D array (image) image = np.zeros((256, 256)) image[100:150, 100:150] = 255 # Create a white square in the middle # Compute the 2D FFT fft_image = fft2(image) # Shift the zero frequency component to the center of the spectrum fft_image_shifted = fftshift(fft_image) # Compute the magnitude spectrum magnitude_spectrum = np.abs(fft_image_shifted) # Inverse 2D FFT to reconstruct the original image reconstructed_image = ifft2(fft_image).real # Plot the original image, magnitude spectrum, and reconstructed image plt.figure(figsize=(12, 4)) # Original image plt.subplot(1, 3, 1) plt.title("Original Image") plt.imshow(image, cmap='gray') plt.axis('off') # Magnitude spectrum plt.subplot(1, 3, 2) plt.title("Magnitude Spectrum") plt.imshow(np.log(magnitude_spectrum + 1), cmap='gray') plt.axis('off') # Reconstructed image plt.subplot(1, 3, 3) plt.title("Reconstructed Image") plt.imshow(reconstructed_image, cmap='gray') plt.axis('off') plt.show()
Here is the output of the 2d-Dimensional Fast Fourier Transform(FFT) −

Applications of FFT
The Fast Fourier Transform (FFT) in SciPy has a wide range of applications across various fields due to its ability to efficiently convert time-domain signals into their frequency-domain representation. Here are some key applications of FFT −
- Signal Processing: FFT is used to analyze the frequency content of signals, detect patterns, filter noise and design digital filters. It's fundamental in telecommunications, audio signal processing and radar signal analysis.
- Image Processing: FFT helps in image filtering, enhancement and compression by transforming images to the frequency domain by enabling operations such as high-pass and low-pass filtering.
- Audio Analysis: FFT is used for pitch detection, sound synthesis and music analysis. It helps in extracting features such as spectral content and rhythm from audio signals.
- Vibration Analysis: In mechanical engineering the FFT is used to analyze vibration data from machines to identify faults and predict maintenance needs.
- Medical Imaging: FFT is used in MRI and other imaging techniques to reconstruct images from raw data, improve resolution and filter noise.
- Astronomy: FFT is employed to analyze the frequency spectrum of astronomical signals by helping in the detection and characterization of celestial objects.