0
0
RosComparisonBeginner · 4 min read

Wavelet vs Fourier Transform: Key Differences and Usage

The Fourier Transform breaks a signal into infinite-length sine and cosine waves, showing frequency content but losing time information. The Wavelet Transform uses short, localized waves to analyze both time and frequency, making it better for signals with changing frequencies.
⚖️

Quick Comparison

Here is a quick side-by-side comparison of Wavelet and Fourier transforms based on key factors.

FactorFourier TransformWavelet Transform
Signal RepresentationInfinite-length sine/cosine wavesShort, localized wavelets
Time-Frequency LocalizationGood frequency, no time infoGood time and frequency info
Best ForStationary signalsNon-stationary signals
Computational ComplexityGenerally lowerGenerally higher
OutputFrequency spectrumTime-frequency spectrum
Use Case ExampleAudio equalizationEEG signal analysis
⚖️

Key Differences

The Fourier Transform decomposes a signal into sine and cosine waves of infinite duration. This means it provides exact frequency information but loses when those frequencies occur in time. It works best for signals whose frequency content does not change over time, called stationary signals.

In contrast, the Wavelet Transform uses small waves called wavelets that are localized in both time and frequency. This allows it to capture changes in frequency over time, making it ideal for analyzing non-stationary signals like speech or biological signals. Wavelets can zoom in on short, high-frequency events and also analyze long, low-frequency trends.

Because wavelets analyze signals at multiple scales, they provide a time-frequency representation, unlike the Fourier Transform's pure frequency view. However, this added flexibility comes with increased computational cost and complexity.

⚖️

Code Comparison

This example shows how to compute the Fourier Transform of a simple signal using Python's numpy library.

python
import numpy as np
import matplotlib.pyplot as plt

# Create a sample signal: 5 Hz sine wave + noise
fs = 100  # Sampling frequency
t = np.linspace(0, 1, fs, endpoint=False)
signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.random.randn(fs)

# Compute Fourier Transform
freqs = np.fft.fftfreq(fs, 1/fs)
fft_values = np.fft.fft(signal)

# Plot magnitude spectrum
plt.plot(freqs[:fs//2], np.abs(fft_values)[:fs//2])
plt.title('Fourier Transform Magnitude Spectrum')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.show()
Output
A plot showing the magnitude spectrum with a peak near 5 Hz frequency.
↔️

Wavelet Transform Equivalent

This example computes the Continuous Wavelet Transform (CWT) of the same signal using Python's pywt library.

python
import numpy as np
import matplotlib.pyplot as plt
import pywt

# Same signal as before
fs = 100
t = np.linspace(0, 1, fs, endpoint=False)
signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.random.randn(fs)

# Compute Continuous Wavelet Transform
scales = np.arange(1, 31)
cwt_matrix, frequencies = pywt.cwt(signal, scales, 'mexh', sampling_period=1/fs)

# Plot scalogram
plt.imshow(np.abs(cwt_matrix), extent=[0, 1, 1, 31], cmap='jet', aspect='auto')
plt.title('Wavelet Transform Scalogram')
plt.xlabel('Time (seconds)')
plt.ylabel('Scale')
plt.show()
Output
A color-coded scalogram plot showing signal energy across time and scales.
🎯

When to Use Which

Choose Fourier Transform when your signal is stationary and you only need frequency information, such as in audio equalization or spectral analysis of steady signals.

Choose Wavelet Transform when your signal changes over time and you need to know when frequencies occur, like in speech processing, seismic data, or biomedical signals.

Wavelets provide richer information but require more computation, so use them when time-frequency detail is important.

Key Takeaways

Fourier Transform shows frequency content but loses time information.
Wavelet Transform provides both time and frequency details for non-stationary signals.
Use Fourier for steady signals and Wavelets for signals with changing frequencies.
Wavelets are computationally heavier but offer richer analysis.
Both transforms are essential tools depending on signal characteristics.