Skip to content

Commit d5a9324

Browse files
committed
setup.py updated
1 parent 123a80a commit d5a9324

12 files changed

+221
-3
lines changed

build/lib/lmso_algorithm/__init__.py

Whitespace-only changes.

build/lib/lmso_algorithm/algorithm.py

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: Alexandru - George Rusu (2019). All Rights Reserved.
5+
"""
6+
import numpy as np
7+
8+
class cir_buf:
9+
"""
10+
Class that defines the concept of circular buffer.
11+
"""
12+
def __init__(self, cblen):
13+
self.cblen = cblen
14+
self.cb = np.zeros([cblen, 1])
15+
16+
def cb_push(self, x):
17+
"""
18+
Pushes a sample in the circula buffer.
19+
:param x: input sample.
20+
"""
21+
self.cb = np.vstack((x, self.cb[0 : self.cblen - 1]))
22+
23+
def dot_product(self):
24+
"""
25+
Performs the scalar product of the circular buffer and its self.
26+
"""
27+
return ((self.cb).T).dot(self.cb)
28+
29+
30+
class fir(cir_buf):
31+
"""
32+
Class that defines the FIR filter.
33+
"""
34+
def __init__(self, ford):
35+
self.ord = ford
36+
self.coeffs = np.zeros([ford, 1])
37+
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+
"""
43+
return ((x.cb).T).dot(self.coeffs)
44+
45+
46+
class lmso(fir, cir_buf):
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+
"""
62+
id_vec = np.ones([ford, 1])
63+
id_matrix = np.diagflat(id_vec)
64+
65+
self.h = fir(ford)
66+
self.c = np.sqrt(cst) * id_vec
67+
self.ccorr_mat = cst * id_matrix
68+
self.gamma_mat = self.ccorr_mat + sgmw * id_matrix
69+
70+
self.x = cir_buf(ford)
71+
self.xcorr_mat = np.zeros([ford, ford])
72+
73+
self.msd = cst
74+
self.tmp = 0
75+
self.sx = 0
76+
self.sv = sgmv
77+
self.sw = sgmw
78+
self.sw_idmat = sgmw * id_matrix
79+
80+
self.ln_init_proc = lniproc * ford
81+
self.alpha = alpha
82+
self.delta = delta
83+
self.lam = lam
84+
85+
def lmso_w(self, echo):
86+
"""
87+
This function implements the white version of the LMSO algorithm.
88+
:param echo: echo sample.
89+
"""
90+
if(self.ln_init_proc == 0):
91+
self.msd = np.trace(self.ccorr_mat) + self.h.ord * self.sw
92+
self.ln_init_proc = -1
93+
94+
err = echo - self.h.ffir(self.x)
95+
if(self.ln_init_proc > 0):
96+
self.sx = self.x.dot_product()
97+
sz = self.alpha / (self.sx + self.delta)
98+
u = sz * err * self.x.cb
99+
self.c += u
100+
self.ccorr_mat = self.lam * self.ccorr_mat + (1 - self.lam) * (self.c).dot((self.c).T)
101+
self.ln_init_proc -= 1
102+
else:
103+
self.sx = self.x.dot_product() / self.h.ord
104+
sz = self.msd / (self.msd * self.sx * (self.h.ord + 2) + self.h.ord * self.sv)
105+
u = sz * err * self.x.cb
106+
self.tmp = self.msd * (1 - sz * self.sx)
107+
self.msd = self.tmp + self.h.ord * self.sw
108+
109+
self.h.coeffs += u
110+
return err
111+
112+
def lmso_g(self, echo):
113+
"""
114+
This function implements the general version of the LMSO algorithm.
115+
:param echo: echo sample.
116+
"""
117+
self.xcorr_mat = self.lam * self.xcorr_mat + (1 - self.lam) * (self.x.cb).dot((self.x.cb).T)
118+
err = echo - self.h.ffir(self.x)
119+
120+
if(self.ln_init_proc > 0):
121+
self.sx = self.x.dot_product()
122+
sz = self.alpha / (self.sx + self.delta)
123+
u = sz * err * self.x.cb
124+
self.c += u
125+
self.ccorr_mat = self.lam * self.ccorr_mat + (1 - self.lam) * (self.c).dot((self.c).T)
126+
self.ln_init_proc -= 1
127+
else:
128+
self.sx = self.x.dot_product() / self.h.ord
129+
gr_prod = (self.gamma_mat).dot(self.xcorr_mat)
130+
rg_prod = (self.xcorr_mat).dot(self.gamma_mat)
131+
tp = np.trace(gr_prod)
132+
sz = tp / (self.h.ord * self.sx * tp + 2 * np.trace(gr_prod.dot(self.xcorr_mat)) \
133+
+ self.h.ord * self.sx * self.sv)
134+
u = sz * err * self.x.cb
135+
self.ccorr_mat = self.gamma_mat - sz * (gr_prod + rg_prod) \
136+
+ sz**2 * (2 * rg_prod.dot(self.xcorr_mat) + self.xcorr_mat * tp) \
137+
+ sz**2 * self.sv * self.xcorr_mat
138+
139+
self.h.coeffs += u
140+
self.gamma_mat = self.ccorr_mat + self.sw_idmat
141+
return err
142+

build/lib/lmso_algorithm/common.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: Alexandru - George Rusu (2019). All Rights Reserved.
5+
"""
6+
def time_dif(time, all = False, string = False):
7+
hours, rest = divmod(time, 3600)
8+
minutes, seconds = divmod(rest, 60)
9+
if(all == True):
10+
return hours, minutes, seconds, str(int(hours)).zfill(2) + ":" + str(int(minutes)).zfill(2) + ":" + str(round(seconds)).zfill(2)
11+
elif(string == True):
12+
return str(int(hours)).zfill(2) + ":" + str(int(minutes)).zfill(2) + ":" + str(round(seconds)).zfill(2)
13+
else:
14+
return hours, minutes, seconds
15+
16+
17+
def vrms(a):
18+
return ((a.astype(float)**2).sum() / len(a))**0.5
19+

build/lib/lmso_algorithm/echoproc.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: Alexandru - George Rusu (2019). All Rights Reserved.
5+
"""
6+
import numpy as np
7+
8+
def shift(seq, n = 0):
9+
a = n % len(seq)
10+
return np.concatenate((seq[-a:], seq[:-a]), axis = 0)
11+
12+

dist/lmso_algorithm-1.0.tar.gz

-3.09 KB
Binary file not shown.

dist/lmso_algorithm-1.1.tar.gz

3.21 KB
Binary file not shown.

lmso_algorithm.egg-info/PKG-INFO

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Metadata-Version: 1.0
2+
Name: lmso-algorithm
3+
Version: 1.1
4+
Summary: An Optimized LMS Algorithm
5+
Home-page: https://github.com/alexgrusu/lmso_algorithm
6+
Author: Alexandru - George Rusu
7+
Author-email: [email protected]
8+
License: UNKNOWN
9+
Description: # lmso_algorithm
10+
11+
The least-mean-square (LMS) and the normalized least-mean-square (NLMS) algorithms require a trade-off between fast convergence
12+
and low misadjustment, obtained by choosing the control parameters. In general, time variable parameters are proposed
13+
according to different rules. Many studies on the optimization of the NLMS algorithm imply time variable control parameters
14+
according some specific criteria.
15+
16+
The optimized LMS (LMSO) algorithm [1] for system identification is developed in the context of a state variable model, assuming
17+
that the unknown system acts as a time-varying system, following a first-order Markov model [2].
18+
19+
The proposed algorithm follows an optimization problem and introduces a variable step-size in order to minimize the system misalignment
20+
21+
22+
[1] A. G. Rusu, S. Ciochină, and C. Paleologu, “On the step-size optimization of the LMS algorithm,” in Proc. IEEE TSP, 2019, 6 pages.
23+
24+
[2] G. Enzner, H. Buchner, A. Favrot, and F. Kuech, “Acoustic echo control,” in Academic Press Library in Signal Processing,
25+
vol. 4, ch. 30, pp. 807–877, Academic Press 2014.
26+
27+
28+
Keywords: Adaptive filters,Echo cancellation,System identification
29+
Platform: UNKNOWN

lmso_algorithm.egg-info/SOURCES.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
README.md
2+
setup.py
3+
lmso_algorithm/__init__.py
4+
lmso_algorithm/algorithm.py
5+
lmso_algorithm/common.py
6+
lmso_algorithm/echoproc.py
7+
lmso_algorithm.egg-info/PKG-INFO
8+
lmso_algorithm.egg-info/SOURCES.txt
9+
lmso_algorithm.egg-info/dependency_links.txt
10+
lmso_algorithm.egg-info/top_level.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lmso_algorithm.egg-info/top_level.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lmso_algorithm

setup.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
setuptools.setup(
55
name = "lmso_algorithm",
6-
version = 1.0,
6+
version = 1.1,
77
long_description = Path("README.md").read_text(),
8-
packages = setuptools.find_packages(exclude = ["tests", "example"])
9-
8+
packages = setuptools.find_packages(exclude = ["tests", "example"]),
9+
author="Alexandru - George Rusu",
10+
author_email="[email protected]",
11+
description="An Optimized LMS Algorithm",
12+
keywords="Adaptive filters, Echo cancellation, System identification",
13+
url="https://github.com/alexgrusu/lmso_algorithm", # project home page, if any
1014
)

0 commit comments

Comments
 (0)