Skip to content

IamOumarIbrahim/adaptive-noise-cancellation-dsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Š Adaptive Noise Cancellation for Speech Signals (NLMS)

MATLAB DSP Course University License: CC0

An optimized, zero-dependency Adaptive Noise Cancellation (ANC) system for real-time speech enhancement using the Normalized Least Mean Squares (NLMS) algorithm in MATLAB.


πŸ“– Table of Contents


πŸ’‘ What This Project Does

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.

βš™οΈ System Model & Architecture

The system takes two signals:

  1. Primary Input $d(n)$: The corrupted speech signal, composed of the clean speech $s(n)$ plus local noise $v_1(n)$.
  2. 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;
Loading

πŸ“ Mathematical Formulation

The adaptive filter estimates $v_1(n)$ using $x(n)$, and subtracts this estimate $y(n)$ from $d(n)$ to yield the output $e(n)$:

$$e(n) = d(n) - y(n) = s(n) + [v_1(n) - y(n)]$$

As the filter converges, $y(n) \to v_1(n)$, meaning the error signal $e(n) \to s(n)$ (the clean recovered speech).

NLMS Weight Update Equations

At each sampling instant $n$, the filter executes:

  1. Estimated Noise Output: $$y(n) = \mathbf{w}^T(n) \mathbf{x}(n)$$

  2. Error (Recovered Speech): $$e(n) = d(n) - y(n)$$

  3. 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.

πŸ“Š Simulation Results

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

πŸ”§ Parameter Rationale

The filter parameters were selected to optimize convergence rate, steady-state misadjustment, and computational budget:

Parameter Selected Value Engineering Rationale
Step size $\mu$ 0.05 Achieves a stable trade-off between fast convergence and minimal tracking jitter.
Filter length $L$ 64 taps Captures enough past noise correlations without excessive mathematical delay or computational load.
Regularization $\epsilon$ 1e-6 Stabilizes weight updates during moments of silence or signal dropout.

πŸ”¬ Benchmarking vs. Literature

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 ($O(L^2)$ vs $O(L)$ for NLMS).
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.

πŸš€ How to Run

Requirements

  • MATLAB (Tested on R2024a, works on any standard release)
  • No external toolboxes required.

Execution

  1. Clone this repository:
    git clone https://github.com/IamOumarIbrahim/adaptive-noise-cancellation-dsp.git
  2. Open MATLAB, navigate to the directory, and run the script:
    run('nlms_anc.m')
  3. 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.

πŸ“ File Structure

adaptive-noise-cancellation-dsp/
β”œβ”€β”€ README.md         - Project documentation (this file)
└── nlms_anc.m        - Full MATLAB script (Signal generation -> NLMS loop -> SNR calculations -> Plots)

πŸ“š References

  1. S. Haykin, Adaptive Filter Theory, Prentice Hall, 3rd ed.
  2. L. Cai, "Research of speech enhancement based on adaptive noise cancellation methods," Applied Mechanics and Materials, 2014.
  3. A. Mahmoodzadeh et al., "Speech enhancement using a Kalman-based normalized LMS algorithm," IST, 2008.
  4. M. A. Akhaee et al., "Speech enhancement by ANC in the wavelet domain," ICICS, 2005.

πŸ“„ License

This repository is licensed under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication.

About

πŸ”Š Normalized LMS (NLMS) adaptive noise cancellation system in MATLAB for speech enhancement, achieving +5.14 dB SNR improvement.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages