-
Notifications
You must be signed in to change notification settings - Fork 2
/
denoiser.py
44 lines (29 loc) · 858 Bytes
/
denoiser.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
import pywt
import numpy as np
def denoiser(original_signal):
ca2,cd2,cd1 = pywt.wavedec(original_signal, 'db4', level=2)
sigma1=np.std(cd1)
th1 = sigma1 * np.sqrt( 2*np.log( len( cd1 ) ) )
for i in range(len(cd1)):
if cd1[i]<th1:
cd1[i]=0
sigma2=np.std(cd2)
th2 = sigma2 * np.sqrt( 2*np.log( len( cd2 ) ) )
for i in range(len(cd2)):
if cd2[i]<th2:
cd2[i]=0
return np.array([ca2,cd2,cd1])
def denoisersig(original_signal):
ca2,cd2,cd1 = pywt.wavedec(original_signal, 'db4', level=2)
sigma1=np.std(cd1)
th1 = sigma1 * np.sqrt( 2*np.log( len( cd1 ) ) )
for i in range(len(cd1)):
if cd1[i]<th1:
cd1[i]=0
sigma2=np.std(cd2)
th2 = sigma2 * np.sqrt( 2*np.log( len( cd2 ) ) )
for i in range(len(cd2)):
if cd2[i]<th2:
cd2[i]=0
denoised_signal = pywt.waverec([ca2,cd2,cd1],'db4')
return np.array(denoised_signal)