-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathadaptive_mss.c
77 lines (60 loc) · 1.79 KB
/
adaptive_mss.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "L138_LCDK_aic3106_init.h"
#include "readme.cof"
#define mu 1E-11 // learning rate
#define N 128 // length of delay line/adaptive filter
#define NUM_SECTIONS 128 // number of weights in synthetic transfer functino
AIC31_data_type codec_data;
float weights[N]; // adaptive filter weights
float x[N]; // delay line
float w[NUM_SECTIONS][2]; // synthetic transfer functino weights
interrupt void interrupt4(void)
{
short i;
float input, refnoise, signal, signoise, wn, yn, error;
codec_data.uint = input_sample();
refnoise =(codec_data.channel[LEFT]); // noise sensor - on outside of headphones
input = refnoise;
for (i=0; i < NUM_SECTIONS; i++)
// filter refnoise (noise sensor input)
// to emulate transfer function of headphone wall
// readme.cof contains a low pass 3rd order FIR cheby filter
{
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];
w[i][0] = wn;
input = yn;
}
yn=0.0;
x[0] = refnoise;
for (i = 0; i < N; i++) // compute adaptive filter output (w'x)
{
yn += (weights[i] * x[i]);
}
error = - yn; // compute error
for (i = N-1; i >= 0; i--) // update weights and delay line
{
weights[i] = weights[i] + mu*error*x[i];
x[i] = x[i-1];
}
codec_data.channel[LEFT]= ((uint16_t)(error));
codec_data.channel[RIGHT]= ((uint16_t)(error));
output_sample(codec_data.uint);
return;
}
int main()
{
int i;
for (i= 0; i < N; i++) // initialize delay line
{
weights[i] = 0;
x[i] = 0;
}
for (i= 0; i < NUM_SECTIONS; i++) //initialize weihts
{
w[i][0] = 0.0;
w[i][1] = 0.0;
}
L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);
while(1);
}