Header Ads Widget

⚡ Premium Tools Hub • EXE Apps + Full Python Source Code
Lite • Pro • Bundle Packs • Instant Download

NumPy Discrete Fourier Transform Explained – Python FFT with Examples

NumPy – Discrete Fourier Transform (DFT) 

The Discrete Fourier Transform (DFT) is one of the most important tools in signal processing and data analysis.

It converts a signal from the time domain into the frequency domain.

NumPy provides powerful functions to compute DFT efficiently using FFT (Fast Fourier Transform).


What is DFT?

DFT transforms a sequence of values into components of different frequencies.

It helps us understand the frequency content of a signal.


Import NumPy FFT Module

import numpy as np

1. Basic FFT (Fast Fourier Transform)

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 back to time domain
  • Restores original signal

3. Frequency Spectrum Analysis

import numpy as np

signal = np.array([1, 2, 3, 4, 5, 6, 7, 8])

fft = np.fft.fft(signal)

frequencies = np.abs(fft)

print(frequencies)

Meaning:

  • Shows strength of each frequency
  • Useful in signal analysis

4. Sampling a Sine Wave

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 1, 100)
signal = np.sin(2 * np.pi * 5 * t)

fft = np.fft.fft(signal)

plt.plot(np.abs(fft))
plt.title("Frequency Spectrum of Sine Wave")
plt.show()

5. Noise Filtering Example

import numpy as np

signal = np.sin(np.linspace(0, 10, 100)) + np.random.random(100)

fft = np.fft.fft(signal)

filtered = np.fft.ifft(fft)

print(filtered.real[:10])

Real-World Applications

1. Signal Processing

  • Audio analysis
  • Noise filtering

2. Image Processing

  • Image compression
  • Edge detection

3. Communications

  • Wireless signal analysis
  • Data transmission

4. Machine Learning

  • Feature extraction
  • Pattern recognition

Why Use NumPy FFT?

Using NumPy provides:

  • Fast FFT computation
  • Efficient signal transformation
  • Easy array-based processing
  • High-performance scientific tools

Combined with Python, it becomes essential for signal processing and data science.


Summary

NumPy provides FFT functions:

np.fft.fft()
np.fft.ifft()
np.fft.fftfreq()

These are used for frequency domain analysis.


Conclusion

The Discrete Fourier Transform in NumPy is a powerful tool for analyzing signals, images, and data patterns. It is widely used in engineering, science, and machine learning.




Post a Comment

0 Comments