Update waveletDenoise.py
Browse files- waveletDenoise.py +10 -21
waveletDenoise.py
CHANGED
@@ -1,21 +1,10 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
coeffs = pywt.
|
10 |
-
|
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 |
-
|
|
|
1 |
+
import pywt
|
2 |
+
|
3 |
+
# Function to apply wavelet denoising
|
4 |
+
def wavelet_denoise(audio, wavelet='db1', level=1):
|
5 |
+
coeffs = pywt.wavedec(audio, wavelet, mode='per')
|
6 |
+
# Thresholding detail coefficients
|
7 |
+
sigma = np.median(np.abs(coeffs[-level])) / 0.6745
|
8 |
+
uthresh = sigma * np.sqrt(2 * np.log(len(audio)))
|
9 |
+
coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]
|
10 |
+
return pywt.waverec(coeffs, wavelet, mode='per')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|