Professional Documents
Culture Documents
Active Noise Cancellation: Using The Lms and Fxlms Algorithms
Active Noise Cancellation: Using The Lms and Fxlms Algorithms
November 7, 2016
Marko Stamenovic
Recurse Center Lightning Talk
https://github.com/markostam
Background and Motivation
Let’s start at the beginning
Background
Active Noise Cancellation (ANC)
◉Targets specific
frequencies.
◉Expensive.
𝑒 ( 𝑛 ) =𝑑 ( 𝑛 ) − 𝒘 𝑇 ( 𝑛 ) 𝒙 ( 𝑛 )
𝒘
( 𝑛+1 )=𝒘 ( 𝑛 ) − 𝜇 𝒙 ( 𝑛 ) 𝑒 ( 𝑛 )
◉ = Learning rate
LMS for ANC Block Diagram
and Equations
error e(n)
𝑒 ( 𝑛 ) =𝑑 ( 𝑛 ) − 𝒘 𝑇 ( 𝑛 ) 𝒙 ( 𝑛 )
𝒘
( 𝑛+1 ) =𝒘 ( 𝑛 ) − 𝜇 𝒙 ( 𝑛 ) 𝑒 ( 𝑛 )
Cool story, show me dez code
𝑆 𝑒𝑡𝑢𝑝 𝑠𝑡𝑢𝑓𝑓 𝑎𝑛𝑑 𝑠𝑦𝑛𝑡h𝑒𝑡𝑖𝑐 𝑡𝑟𝑎𝑛𝑠𝑓𝑒𝑟 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑴𝒆𝒂𝒕
𝒐𝒇 𝒕𝒉𝒆 𝑨𝑵𝑪 :𝑓𝑖𝑙𝑡𝑒𝑟 𝑡h𝑒 𝑠𝑖𝑔𝑛𝑎𝑙∧𝑢𝑝𝑑𝑎𝑡𝑒 𝑤𝑒𝑖𝑔h𝑡𝑠
yn=0.0;
x[0] = refnoise;
interrupt void interrupt4(void)
{ for (i = 0; i < N; i++) // compute adaptive filter output (w'x)
short i; {
float input, refnoise, signal, signoise, wn, yn, error; yn += (weights[i] * x[i]);
codec_data.uint = input_sample(); }
refnoise =(codec_data.channel[LEFT]); // noise sensor
input = refnoise; error = - yn; // compute error
for (i=0; i < N; i++) for (i = N-1; i >= 0; i--) // update weights and delay line
// filter refnoise to emulate transfer {
// function of firewall (3rd order lp filter) weights[i] = weights[i] + mu*error*x[i];
{ x[i] = x[i-1];
wn = input - a[i][1]*w[i][0] - a[i][2]*w[i][1]; }
yn = b[i][0]*wn + b[i][1]*w[i][0] + b[i][2]*w[i][1];
w[i][1] = w[i][0]; codec_data.channel[LEFT]= ((uint16_t)(error));
w[i][0] = wn; codec_data.channel[RIGHT]= ((uint16_t)(error));
input = yn; output_sample(codec_data.uint);
} return;
}
(𝑎𝑙𝑠𝑜
𝑢𝑝𝑑𝑎𝑡𝑒𝑡h𝑒 𝑑𝑒𝑙𝑎𝑦 𝑙𝑖𝑛𝑒 𝑎𝑛𝑑 𝑜𝑢𝑡𝑝𝑢𝑡 𝑡h𝑒 𝑓𝑖𝑙𝑡𝑒𝑟𝑒𝑑 𝑠𝑖𝑔𝑛𝑎𝑙 )
FxLMS Block Diagram
◉One thing missing from the
𝑒 ( 𝑛 ) =𝑑 ( 𝑛 ) − 𝒘 𝑇 ( 𝑛 ) 𝒙 ( 𝑛 ) LMS model in practical ANC
( 𝑛+1 )=𝒘 ( 𝑛 ) − 𝜇 𝒙′ ( 𝑛 ) 𝑒 ( 𝑛 )
𝒘 applications is the path from
the speakers to the ear for
the correction signal.
𝑒 ( 𝑛 ) =𝑑 ( 𝑛 ) − 𝒘 𝑇 ( 𝑛 ) 𝒙 ( 𝑛 )
( 𝑛+1 ) =𝒘 ( 𝑛 ) − 𝜇 𝒙′ ( 𝑛 ) 𝑒 ( 𝑛 )
𝒘
4
Experimental
Results
Experimental Setup
µ = 0.002
Learning Rate Too Large
µ = 2.6
Learning Rate Juust Right
Co nve rg e nc e Time in Cyc le s
200
Error
150
100
Amplitude
50
-50
-100
0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
Cycles
50
40
Amplitude
30
20
10
µ = 1.3
-10
0 20 40 60 80 100 120 140
Numbering of filter tap
5
Demo
Time!!!!!!!!!!!!!!!!!!!!!!
Yes, it’s really time for the: