6
6
import numpy as np
7
7
8
8
class cir_buf :
9
+ """
10
+ Class that defines the concept of circular buffer.
11
+ """
9
12
def __init__ (self , cblen ):
10
13
self .cblen = cblen
11
14
self .cb = np .zeros ([cblen , 1 ])
12
15
13
16
def cb_push (self , x ):
17
+ """
18
+ Pushes a sample in the circula buffer.
19
+ :param x: input sample.
20
+ """
14
21
self .cb = np .vstack ((x , self .cb [0 : self .cblen - 1 ]))
15
22
16
23
def dot_product (self ):
24
+ """
25
+ Performs the scalar product of the circular buffer and its self.
26
+ """
17
27
return ((self .cb ).T ).dot (self .cb )
18
28
19
29
20
30
class fir (cir_buf ):
31
+ """
32
+ Class that defines the FIR filter.
33
+ """
21
34
def __init__ (self , ford ):
22
35
self .ord = ford
23
36
self .coeffs = np .zeros ([ford , 1 ])
24
37
25
38
def ffir (self , x ):
39
+ """
40
+ Performs the filtering of an input signal of the same length.
41
+ :param x: input circular buffer.
42
+ """
26
43
return ((x .cb ).T ).dot (self .coeffs )
27
44
28
45
29
46
class lmso (fir , cir_buf ):
30
47
def __init__ (self , ford = 512 , cst = 2.165e-6 , lam = 0.95 , sgmv = 0 , sgmw = 0 , lniproc = 2 , alpha = 1.0 , delta = 1e-6 ):
48
+ """
49
+ Constructor that initializes lmso object parameters.
50
+ :param ford: the length L of the adaptive filter, which is the same as for the input circular buffer.
51
+ :param cst: small constant that initializes the MSD.
52
+ :param lam: represents the forgetting factor of the exponential window.
53
+ :param sgmv: represents the variance of the measurement noise.
54
+ :param sgmw: represents the variance of the system noise.
55
+ :param lniproc: how long the initialization process lasts [e.g., int(lniproc) * L].
56
+ :param alpha: the fixed step-size of the NLMS algorithm used in the initialization process
57
+ for a period of int(lniproc) * L samples.
58
+ :param delta: the regularization parameter of the NLMS algorithm used in the initialization
59
+ process for a period of int(lniproc) * L samples.
60
+
61
+ """
31
62
id_vec = np .ones ([ford , 1 ])
32
63
id_matrix = np .diagflat (id_vec )
33
64
@@ -52,6 +83,10 @@ def __init__(self, ford = 512, cst = 2.165e-6, lam = 0.95, sgmv = 0, sgmw = 0, l
52
83
self .lam = lam
53
84
54
85
def lmso_w (self , echo ):
86
+ """
87
+ This function implements the white version of the LMSO algorithm.
88
+ :param echo: echo sample.
89
+ """
55
90
if (self .ln_init_proc == 0 ):
56
91
self .msd = np .trace (self .ccorr_mat ) + self .h .ord * self .sw
57
92
self .ln_init_proc = - 1
@@ -75,6 +110,10 @@ def lmso_w(self, echo):
75
110
return err
76
111
77
112
def lmso_g (self , echo ):
113
+ """
114
+ This function implements the general version of the LMSO algorithm.
115
+ :param echo: echo sample.
116
+ """
78
117
self .xcorr_mat = self .lam * self .xcorr_mat + (1 - self .lam ) * (self .x .cb ).dot ((self .x .cb ).T )
79
118
err = echo - self .h .ffir (self .x )
80
119
0 commit comments