Wavelet vs Fourier Transform: Key Differences and Usage
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.
| Factor | Fourier Transform | Wavelet Transform |
|---|---|---|
| Signal Representation | Infinite-length sine/cosine waves | Short, localized wavelets |
| Time-Frequency Localization | Good frequency, no time info | Good time and frequency info |
| Best For | Stationary signals | Non-stationary signals |
| Computational Complexity | Generally lower | Generally higher |
| Output | Frequency spectrum | Time-frequency spectrum |
| Use Case Example | Audio equalization | EEG 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.
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()
Wavelet Transform Equivalent
This example computes the Continuous Wavelet Transform (CWT) of the same signal using Python's pywt library.
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()
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.