-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
converter_jedi_bss.py
59 lines (46 loc) · 1.1 KB
/
converter_jedi_bss.py
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
"""
Blind Source Separation using the JediSep Algorithm with Shogun
Based on the example from scikit-learn
http://scikit-learn.org/
Kevin Hughes 2013
"""
import numpy as np
import pylab as pl
from shogun.Features import RealFeatures
from shogun.Converter import JediSep
# Generate sample data
np.random.seed(0)
n_samples = 2000
time = np.linspace(0, 10, n_samples)
# Source Signals
s1 = np.sin(2 * time) # sin wave
s2 = np.sign(np.sin(3 * time)) # square wave
S = np.c_[s1, s2]
S += 0.2 * np.random.normal(size=S.shape) # add noise
# Standardize data
S /= S.std(axis=0)
S = S.T
# Mixing Matrix
A = np.array([[1, 0.5], [0.5, 1]])
# Mix Signals
X = np.dot(A,S)
mixed_signals = RealFeatures(X)
# Separating
jedi = JediSep()
signals = jedi.apply(mixed_signals)
S_ = signals.get_feature_matrix()
A_ = jedi.get_mixing_matrix();
print A_
# Plot results
pl.figure()
pl.subplot(3, 1, 1)
pl.plot(S.T)
pl.title('True Sources')
pl.subplot(3, 1, 2)
pl.plot(X.T)
pl.title('Mixed Sources')
pl.subplot(3, 1, 3)
pl.plot(S_.T)
pl.title('Estimated Sources')
pl.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.36)
pl.show()