Skip to content

Commit c6a8037

Browse files
committed
Class documentation has been added. setup.py and example created.
1 parent 99b58f6 commit c6a8037

File tree

6 files changed

+724
-0
lines changed

6 files changed

+724
-0
lines changed

LICENSE

+674
Large diffs are not rendered by default.
16.1 KB
Binary file not shown.

dist/lmso_algorithm-1.0.tar.gz

3.09 KB
Binary file not shown.

example/test.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from lmso-algorithm import lmso_algorithm

setup.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import setuptools
2+
from pathlib import Path
3+
4+
setuptools.setup(
5+
name = "lmso_algorithm",
6+
version = 1.0,
7+
long_description = Path("README.md").read_text(),
8+
packages = setuptools.find_packages(exclude = ["tests", "example"])
9+
10+
)

src/lmso_algorithm.py

+39
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,59 @@
66
import numpy as np
77

88
class cir_buf:
9+
"""
10+
Class that defines the concept of circular buffer.
11+
"""
912
def __init__(self, cblen):
1013
self.cblen = cblen
1114
self.cb = np.zeros([cblen, 1])
1215

1316
def cb_push(self, x):
17+
"""
18+
Pushes a sample in the circula buffer.
19+
:param x: input sample.
20+
"""
1421
self.cb = np.vstack((x, self.cb[0 : self.cblen - 1]))
1522

1623
def dot_product(self):
24+
"""
25+
Performs the scalar product of the circular buffer and its self.
26+
"""
1727
return ((self.cb).T).dot(self.cb)
1828

1929

2030
class fir(cir_buf):
31+
"""
32+
Class that defines the FIR filter.
33+
"""
2134
def __init__(self, ford):
2235
self.ord = ford
2336
self.coeffs = np.zeros([ford, 1])
2437

2538
def ffir(self, x):
39+
"""
40+
Performs the filtering of an input signal of the same length.
41+
:param x: input circular buffer.
42+
"""
2643
return ((x.cb).T).dot(self.coeffs)
2744

2845

2946
class lmso(fir, cir_buf):
3047
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+
"""
3162
id_vec = np.ones([ford, 1])
3263
id_matrix = np.diagflat(id_vec)
3364

@@ -52,6 +83,10 @@ def __init__(self, ford = 512, cst = 2.165e-6, lam = 0.95, sgmv = 0, sgmw = 0, l
5283
self.lam = lam
5384

5485
def lmso_w(self, echo):
86+
"""
87+
This function implements the white version of the LMSO algorithm.
88+
:param echo: echo sample.
89+
"""
5590
if(self.ln_init_proc == 0):
5691
self.msd = np.trace(self.ccorr_mat) + self.h.ord * self.sw
5792
self.ln_init_proc = -1
@@ -75,6 +110,10 @@ def lmso_w(self, echo):
75110
return err
76111

77112
def lmso_g(self, echo):
113+
"""
114+
This function implements the general version of the LMSO algorithm.
115+
:param echo: echo sample.
116+
"""
78117
self.xcorr_mat = self.lam * self.xcorr_mat + (1 - self.lam) * (self.x.cb).dot((self.x.cb).T)
79118
err = echo - self.h.ffir(self.x)
80119

0 commit comments

Comments
 (0)