File size: 516 Bytes
9cb187d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# coding: utf-8

# In[1]:


# Function to apply wavelet denoising
def wavelet_denoise(audio, wavelet='db1', level=1):
    coeffs = pywt.wavedec(audio, wavelet, mode='per')
    # Thresholding detail coefficients
    sigma = np.median(np.abs(coeffs[-level])) / 0.6745
    uthresh = sigma * np.sqrt(2 * np.log(len(audio)))
    coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]
    return pywt.waverec(coeffs, wavelet, mode='per')


# In[ ]: