NumPy – Fast Fourier Transform (FFT)
The Fast Fourier Transform (FFT) is one of the most powerful algorithms in numerical computing.
It is used to convert signals from the time domain into the frequency domain efficiently.
NumPy provides a built-in FFT module that makes signal processing fast and simple.
What is FFT?
FFT is an optimized version of the Discrete Fourier Transform (DFT).
It reduces computation time from O(n²) to O(n log n)
This makes it ideal for large datasets and real-time applications.
Import NumPy FFT Module
import numpy as np
1. Basic FFT Example
import numpy as np
signal = np.array([1, 2, 3, 4])
fft_result = np.fft.fft(signal)
print(fft_result)
Meaning:
- Converts signal into frequency components
- Output is complex numbers
2. Inverse FFT (Reconstruction)
import numpy as np
signal = np.array([1, 2, 3, 4])
fft_result = np.fft.fft(signal)
original = np.fft.ifft(fft_result)
print(original)
Meaning:
- Converts frequency domain back to time domain
- Restores original signal
3. FFT Frequency Spectrum
import numpy as np
signal = np.array([1, 2, 3, 4, 5, 6, 7, 8])
fft = np.fft.fft(signal)
magnitude = np.abs(fft)
print(magnitude)
Meaning:
- Shows strength of frequencies
- Used in signal analysis
4. FFT of a Sine Wave
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 1, 1000)
signal = np.sin(2 * np.pi * 10 * t)
fft = np.fft.fft(signal)
plt.plot(np.abs(fft))
plt.title("FFT of Sine Wave")
plt.show()
Use case:
- Audio processing
- Sound wave analysis
5. FFT with Noise Removal
import numpy as np
signal = np.sin(np.linspace(0, 10, 100)) + np.random.normal(0, 0.5, 100)
fft = np.fft.fft(signal)
filtered_signal = np.fft.ifft(fft)
print(filtered_signal.real[:10])
Real-World Applications
1. Signal Processing
- Audio filtering
- Noise reduction
2. Image Processing
- Image compression
- Pattern detection
3. Communications
- Wireless signals
- Data transmission
4. Machine Learning
- Feature extraction
- Time-series analysis
Why Use NumPy FFT?
Using NumPy provides:
- Extremely fast computation (O(n log n))
- Efficient array-based processing
- Built-in scientific functions
- Easy integration with ML and signal tools
Combined with Python, it becomes essential for engineering, AI, and data science.
Summary
NumPy FFT functions include:
np.fft.fft()
np.fft.ifft()
np.fft.fftfreq()
Conclusion
Fast Fourier Transform in NumPy is a powerful tool for analyzing signals, audio, images, and time-series data. It is widely used in science, engineering, and machine learning.


0 Comments