Kalman filter for active noise control

This code realizes the Kalman filter approach for an active noise control system (ANC) to attenuate the dynamic noise.
118 Downloads
Updated 22 Feb 2024

View License

Kalman Filter Approach for Active Noise Control
Introduction
This article offers an elaborate description of the Kalman filter code employed in the active control system. Conventional active noise management methods usually employ an adaptive filter, such as the filtered reference least mean square (FxLMS) algorithm, to adjust to changes in the primary noise and acoustic environment. Nevertheless, the slow convergence characteristics of the FxLMS algorithm typically impact the effectiveness of reducing dynamic noise. Hence, this study suggests employing the Kalman filter in the active noise control (ANC) system to enhance the efficacy of noise reduction for dynamic noise. The ANC application effectively utilizes the Kalman filter with a novel dynamic ANC model. The numerical simulation revealed that the proposed Kalman filter exhibits superior convergence performance compared to the FxLMS algorithm for handling dynamic noise.
The picture illustrates the Kalman filter algorithm utilized in active noise control, as implemented in the provided MATLAB code.
Code Explanation
The section provides a concise introduction to the KF.mat file, which implements the Kalman filter method for a single-channel active noise control (ANC) application. Furthermore, the FxLMS algorithm is conducted as a comparative analysis. The Kalman filter technique employs the modified feed-forward active noise control (ANC) structure, whereas the FxLMS algorithm uses the conventional feed-forward ANC structure.
Contents
  • Cleaning the memory and workspace
  • Loading the primary and secondary path
  • Simulation system configuration
  • Creating the disturbance and filtered reference
  • Dynamic noise cancellation by the single channel FxLMS algorithm
  • Dynamic noise cancellation by the Kalman filter approach
Cleaning the memory and workspace
This segment of code is utilized to clean the memory and workspace of the MATLAB software.
close all ;
clear ;
clc ;
Loading the primary and secondary path
This part of the code loads the primary path and secondary path from the Mat files: PriPath_3200.mat and SecPath_200_6000.mat. All these paths are synthesized from the band-pass filters, whose impulse responses are illustrated in Figure 3.
load('PriPath_3200.mat');
load('SecPath_200_6000.mat') ;
figure ;
subplot(2,1,1)
plot(PriPath);
title('Primary Path');
grid on ;
subplot(2,1,2);
plot(SecPath);
title('Secondary Path');
xlabel('Taps');
grid on ;
Figure 3: The impulse response of the primary path and the secondary path.
Simulation system configuration
The sampling rate of the active noise control (ANC) system is set to 16000 Hz, and the simulation duration is 0.25 second. To simulate the dynamic noise, the primary noise in this ANC system is a chirp signal, whose frequency gradually varies from 20 Hz to 1600 Hz, as shown in Figure 4.
fs = 16000 ; % sampling rate 16 kHz.
T = 0.25 ; % Simulation duration (seconds).
t = 0:1/fs:T ;% Time variable.
N = length(t) ;
fw = 500 ;
fe = 300 ;
y = chirp(t,20,T,1600);
figure ;
plot(t,y);
title('Reference signal x(n)');
xlabel('Time (seconds)') ;
ylabel('Magnitude') ;
axis([-inf inf -1.05 1.05]);
grid on ;
Figure 4: The waveform of the reference signal that is a chirp signal ranging from 20 to 1600 Hz.
Creating the disturbance and filtered reference
The disturbance and filtered reference used in the ANC system are created by passing the chirp signal through the loaded primary and secondary paths.
%X = 0.4*sin(2*pi*fw*t)+0.3*sin(2*pi*fe*t);
X = y;
%plot(X(end-100:end))
D = filter(PriPath,1,X);
Rf = filter(SecPath,1,X);
%plot(D(end-100:end))
Dynamic noise cancellation by the single channel FxLMS algorithm
In this part, the single-channel FxLMS algorithm is used to reduce the chirp disturbance. The length of the control filter in the FxLMS algorithm has 80 taps, and the step size is set to 0.0005. Figure 5 shows the error signal picked up by the error sensor in the ANC system. This figure shows that the FxLMS algorithm can not fully attenuate this dynamic noise during the 0.25 second.
L = 80 ;
muW = 0.0005;
noiseController = dsp.FilteredXLMSFilter('Length',L,'StepSize',muW, ...
'SecondaryPathCoefficients',SecPath);
[y,e] = noiseController(X,D);
figure;
plot(t,e) ;
title('FxLMS algorithm') ;
ylabel('Error signal e(n)');
xlabel('Time (seconds)') ;
grid on ;
Figure 5. The error signal of the single-channel ANC system based on the FxLMS algorithm.
Dynamic noise cancellation by the Kalman filter approach
The Kalman filter is employed in the signal-channel ANC system to track the fluctuation of the chirp disturbance. The variance of the observed noise is initially set to $0.005$. Figure 6 shows the error signal of the Kalman filter algorithm. Additionally, Figure 7 illustrates the variation of the coefficients $w_5(n)$ and $w_{60}(n)$ as time progresses. The outcome illustrates that the Kalman filter effectively mitigates the chirp disturbances. The Kalman filter approach has markedly superior convergence behavior compared to the FxLMS method, as illustrated in Figure 8.
q = 0.005;
P = eye(L);
W = zeros(L,1);
Xd = zeros(L,1);
ek = zeros(N,1);
w5 = zeros(N,1);
w60 = zeros(N,1);
%-----------Kalman Filer---------
for ii =1:N
Xd =[Rf(ii);Xd(1:end-1)];
yt = Xd'*W ;
ek(ii) = D(ii)-yt ;
K = P*Xd/(Xd'*P*Xd + q);
W = W +K*ek(ii) ;
P =(eye(L)-K*Xd')*P ;
%---------------------------
w5(ii) = W(5);
w60(ii) = W(60);
%---------------------------
end
%-------------------------------
figure;
plot(t,ek);
title('Kalman algorithm') ;
ylabel('Error signal e(n)');
xlabel('Time (seconds)')
grid on ;
figure
plot(t,w5,t,w60);
title('Control Filter Weights');
xlabel('Time (seconds)');
legend('w_5','w_{60}');
grid on ;
figure;
plot(t,e,t,ek);
title('FxLMS vs Kalman') ;
ylabel('Error signal e(n)');
xlabel('Time (seconds)') ;
legend('FxLMS algorithm','KF algorithm');
grid on ;
Figure 6: The error signal of the single-channel ANC system based on the Kalman filter.
Figure 7: The time history of the coefficients $w_{5}(n)$ and $w_{60}(n)$ in the control filter.
Figure 8:Comparison of the error signals in the FxLMS algorithm and the Kalman filter.
Summary
This document provides a detailed introduction to the Kalman filter code used in the active control system. Traditional active noise control typically adapts the adaptive filter, such as the filtered reference least mean square (FxLMS) algorithm, to adapt to the variations of the primary noise and acoustic environment. However, the sluggish convergence behavior of the FxLMS algorithm usually affects the noise reduction for the dynamic noise. Therefore, this work proposes using the Kalman filter in the ANC system to improve the noise reduction performance for dynamic noise. With a novel dynamic ANC model, the Kalman filter is excellently deployed in the ANC application. The numerical simulation demonstrated that the proposed Kalman filter has a much better convergence performance than the FxLMS algorithm in dealing with dynamic noise.

Cite As

DONGYUAN SHI (2025). Kalman filter for active noise control (https://www.mathworks.com/matlabcentral/fileexchange/159311-kalman-filter-for-active-noise-control), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2023b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.1

This update version gives a detailed description of the whole code.

1.0.0