
- 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 - rfft() Function
The rfft() function in SciPy calculates the 1-dimensional Fast Fourier Transform (FFT) for real-valued input data. It produces the non-redundant positive frequency components. This approach takes advantage of symmetry to reduce computation time and memory usage, which makes it effective for real-world signals.
Rfft() method is widely applied in signal processing audio analysis and data compression. Real-valued datasets have to be understood or manipulated for frequency components in these fields. It will help in tasks like filtering, noise removal, and extracting spectral features.
Users often encounter errors when working with rfft(). Mismatched input dimensions when specifying the axis parameter can lead to ValueError. Using complex input instead of real-valued data might result in unexpected behavior or wrong outputs.
The n parameter has an impact on the FFT's length letting you cut it short or add zeros to pad it. The norm parameter adjusts the scaling ("backward", "forward", "ortho"), and overwrite_x improves speed by using the input array during computation.
Syntax
The syntax for the SciPy rfft() method is as follows −
.rfft(x, n=None, axis=-1, norm=None, overwrite_x=False, plan = none)
Parameters
This method accepts the following parameters −
x (array-like) − Input array (signal data).
n (int, optional) − Length of the output transform. Pads with zeros or truncates if needed.
axis (int, optional) − Axis along which to compute the FFT (default is the last axis).
norm (str, optional) − Normalization mode ("backward", "forward" or "ortho").
overwrite_x (bool, optional) − If True, allows modifying input x to save memory.
plan (plan, optional) − Reserved for precomputed FFT plans for performance optimization.
Return Value
Returns a complex-valued array representing the positive frequency components of the input real-valued data.
Example 1
This is the basic example of rfft() method where it computes a complex-valued array from the real-valued data. Following is the code −
import scipy.fft import numpy as np # Real-valued input data x = np.array([1, 2, 3, 4]) # Compute the 1D RFFT frequency_data = scipy.fft.rfft(x) print("Frequency Domain Data:", frequency_data)
When we run above program, it produces following result
Frequency Domain Data: [10.+0.j -2.+2.j -2.+0.j]
Example 2
The rfft() method is especially useful for finding out frequencies of real-world data like detection of significant frequencies in a signal from heartbeat for medical application.
This code produces the simulation of a heartbeat signal with an array of the real-valued time domain. It then applies the rfft() to transform this signal into the frequency domain.
import scipy.fft import numpy as np heartbeat_signal = np.array([0.2, 0.8, 1.0, 0.6, 0.3, 0.1, 0.05, 0.1]) frequency_data = scipy.fft.rfft(heartbeat_signal) print("Frequency Components of Heartbeat Signal:", frequency_data)
Following is an output of the above code −
Frequency Components of Heartbeat Signal: [ 3.15 +0.j 0.04142136-1.79852814j -0.55 -0.2j -0.24142136+0.10147186j -0.05 +0.j ]
Example 3
The rfft() expects the input data to be real valued; passing complex-valued data triggers TypeError or produces incorrect results.
This code illustrates an error example in which the input is complex valued while given to rfft(); therefore, checking data consistency prior to using the function is crucial.
import scipy.fft import numpy as np # Invalid complex-valued input invalid_data = np.array([1 + 2j, 3 + 4j, 5 + 6j]) try: # Attempt to compute RFFT on invalid input frequency_data = scipy.fft.rfft(invalid_data) except TypeError as e: print("Error:", e)
Output of the above code is as follows −
TypeError: x must be a real sequence