cdactvm commited on
Commit
9cb187d
1 Parent(s): f2dc369

Upload waveletDenoise.py

Browse files
Files changed (1) hide show
  1. waveletDenoise.py +21 -0
waveletDenoise.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ # Function to apply wavelet denoising
8
+ def wavelet_denoise(audio, wavelet='db1', level=1):
9
+ coeffs = pywt.wavedec(audio, wavelet, mode='per')
10
+ # Thresholding detail coefficients
11
+ sigma = np.median(np.abs(coeffs[-level])) / 0.6745
12
+ uthresh = sigma * np.sqrt(2 * np.log(len(audio)))
13
+ coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]
14
+ return pywt.waverec(coeffs, wavelet, mode='per')
15
+
16
+
17
+ # In[ ]:
18
+
19
+
20
+
21
+