An optimized, zero-dependency Adaptive Noise Cancellation (ANC) system for real-time speech enhancement using the Normalized Least Mean Squares (NLMS) algorithm in MATLAB.
- What This Project Does
- System Model & Architecture
- Mathematical Formulation
- Simulation Results
- Parameter Rationale
- Benchmarking vs. Literature
- How to Run
- File Structure
- References
- License
Real-world speech signals are frequently corrupted by background acoustic noise. Traditional static digital filters (e.g., FIR or IIR filters) fail to isolate the target speech when the noise occupies the same frequency band. Furthermore, noise characteristics are usually non-stationary and change dynamically.
This project implements an adaptive filtering solution:
- Continuously adjusts filter coefficients dynamically to track noise statistics.
- Uses the NLMS algorithm to normalize the step size against signal power, providing fast convergence and robust stability.
- Achieves a +5.14 dB SNR improvement, converting heavily masked speech into a clear, intelligible output.
The system takes two signals:
-
Primary Input
$d(n)$ : The corrupted speech signal, composed of the clean speech$s(n)$ plus local noise$v_1(n)$ . -
Reference Input
$x(n)$ : A noise reference source that is highly correlated with the noise$v_1(n)$ , but completely uncorrelated with the target speech$s(n)$ (typically captured via a second reference microphone).
Below is the signal processing flowchart of the ANC system:
graph LR
subgraph Signal Generation
S["Speech s(n)"] --> Add(("+"))
V1["Correlated Noise v1(n)"] --> Add
end
subgraph Adaptive Filter Loop
Add -->|Primary d_n| Sub((" - "))
X["Reference Noise x(n)"] --> Filter["Adaptive Filter w(n)"]
Filter -->|Estimated Noise y_n| Sub
Sub -->|Error e_n β s_n| Out["Cleaned Output"]
Sub -->|Feedback Error| Filter
end
classDef default fill:#0f172a,stroke:#3b82f6,stroke-width:2px,color:#fff;
classDef signal fill:#1e1b4b,stroke:#a855f7,stroke-width:2px,color:#fff;
class S,V1,Add signal;
The adaptive filter estimates
As the filter converges,
At each sampling instant
-
Estimated Noise Output:
$$y(n) = \mathbf{w}^T(n) \mathbf{x}(n)$$ -
Error (Recovered Speech):
$$e(n) = d(n) - y(n)$$ -
Normalized Coefficient Update:
$$\mathbf{w}(n+1) = \mathbf{w}(n) + \frac{\mu}{\epsilon + |\mathbf{x}(n)|^2} e(n) \mathbf{x}(n)$$
Where:
-
$\mathbf{w}(n)$ is the vector of filter weights. -
$\mathbf{x}(n)$ is the vector of reference noise samples in the filter's delay line buffer. -
$\mu$ is the step size parameter. -
$\epsilon$ is a small positive regularization constant to prevent division by zero in quiet periods.
| Metric | Value | Meaning |
|---|---|---|
| Input SNR | ~2.00 dB | Heavily corrupted, unintelligible audio |
| Output SNR | ~7.14 dB | Intelligible speech recovered |
| SNR Improvement | +5.14 dB | Clear acoustic improvement |
The filter parameters were selected to optimize convergence rate, steady-state misadjustment, and computational budget:
| Parameter | Selected Value | Engineering Rationale |
|---|---|---|
| Step size |
0.05 |
Achieves a stable trade-off between fast convergence and minimal tracking jitter. |
| Filter length |
64 taps |
Captures enough past noise correlations without excessive mathematical delay or computational load. |
| Regularization |
1e-6 |
Stabilizes weight updates during moments of silence or signal dropout. |
| Algorithm | Key Strengths | Relative Limitations |
|---|---|---|
| NLMS (This project) | Low computational cost, highly stable, invariant to reference power. | Slightly slower convergence than RLS. |
| RLS | Maximum convergence speed. | High computational complexity ( |
| Kalman-LMS (KLMS) | Optimal tracking in fast non-stationary noise. | High complexity; requires estimation of state covariance. |
| Wavelet-Domain ANC | Multi-resolution filtering capabilities. | Introduces processing delay due to wavelet decomposition. |
| DNN-based (Deep Learning) | Exceptional speech recovery. | Requires vast training datasets; lacks strict safety bounds. |
- MATLAB (Tested on R2024a, works on any standard release)
- No external toolboxes required.
- Clone this repository:
git clone https://github.com/IamOumarIbrahim/adaptive-noise-cancellation-dsp.git
- Open MATLAB, navigate to the directory, and run the script:
run('nlms_anc.m') - Outputs:
- The command window will print the input SNR, output SNR, and total SNR improvement.
- A 3-panel figure is generated showing the time-domain waveform comparisons.
adaptive-noise-cancellation-dsp/
βββ README.md - Project documentation (this file)
βββ nlms_anc.m - Full MATLAB script (Signal generation -> NLMS loop -> SNR calculations -> Plots)
- S. Haykin, Adaptive Filter Theory, Prentice Hall, 3rd ed.
- L. Cai, "Research of speech enhancement based on adaptive noise cancellation methods," Applied Mechanics and Materials, 2014.
- A. Mahmoodzadeh et al., "Speech enhancement using a Kalman-based normalized LMS algorithm," IST, 2008.
- M. A. Akhaee et al., "Speech enhancement by ANC in the wavelet domain," ICICS, 2005.
This repository is licensed under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication.