Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- highPassFilter.ipynb +72 -0
- waveletDenoise.ipynb +50 -0
- wienerFilter.ipynb +51 -0
highPassFilter.ipynb
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"id": "b2d45592-5695-40ec-ad90-7d03275337a6",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"# import scipy.signal\n",
|
11 |
+
"\n",
|
12 |
+
"# def high_pass_filter(audio, sr, cutoff=200, order=3):\n",
|
13 |
+
"# \"\"\"\n",
|
14 |
+
"# Applies a high-pass filter to an audio signal.\n",
|
15 |
+
"\n",
|
16 |
+
"# Parameters:\n",
|
17 |
+
"# audio (numpy array): The input audio signal.\n",
|
18 |
+
"# sr (int): The sample rate of the audio signal.\n",
|
19 |
+
"# cutoff (float): The cutoff frequency in Hz. Default is 100 Hz.\n",
|
20 |
+
"# order (int): The order of the filter. Default is 5.\n",
|
21 |
+
" \n",
|
22 |
+
"# Returns:\n",
|
23 |
+
"# numpy array: The filtered audio signal.\n",
|
24 |
+
"# \"\"\"\n",
|
25 |
+
"# # Design the high-pass filter using a Butterworth filter design\n",
|
26 |
+
"# sos = scipy.signal.butter(order, cutoff, btype='highpass', fs=sr, output='sos')\n",
|
27 |
+
" \n",
|
28 |
+
"# # Apply the filter using sosfilt (second-order sections filter)\n",
|
29 |
+
"# filtered_audio = scipy.signal.sosfilt(sos, audio)\n",
|
30 |
+
" \n",
|
31 |
+
"# return filtered_audio"
|
32 |
+
]
|
33 |
+
},
|
34 |
+
{
|
35 |
+
"cell_type": "code",
|
36 |
+
"execution_count": null,
|
37 |
+
"id": "8a1efa78-61d4-4545-b50a-080161bb6aa5",
|
38 |
+
"metadata": {},
|
39 |
+
"outputs": [],
|
40 |
+
"source": [
|
41 |
+
"def high_pass_filter(audio, sr, cutoff=300):\n",
|
42 |
+
" # Design a Butterworth high-pass filter\n",
|
43 |
+
" nyquist = 0.5 * sr\n",
|
44 |
+
" normal_cutoff = cutoff / nyquist\n",
|
45 |
+
" b, a = butter(1, normal_cutoff, btype='high', analog=False)\n",
|
46 |
+
" filtered_audio = lfilter(b, a, audio)\n",
|
47 |
+
" return filtered_audio"
|
48 |
+
]
|
49 |
+
}
|
50 |
+
],
|
51 |
+
"metadata": {
|
52 |
+
"kernelspec": {
|
53 |
+
"display_name": "Python 3 (ipykernel)",
|
54 |
+
"language": "python",
|
55 |
+
"name": "python3"
|
56 |
+
},
|
57 |
+
"language_info": {
|
58 |
+
"codemirror_mode": {
|
59 |
+
"name": "ipython",
|
60 |
+
"version": 3
|
61 |
+
},
|
62 |
+
"file_extension": ".py",
|
63 |
+
"mimetype": "text/x-python",
|
64 |
+
"name": "python",
|
65 |
+
"nbconvert_exporter": "python",
|
66 |
+
"pygments_lexer": "ipython3",
|
67 |
+
"version": "3.11.7"
|
68 |
+
}
|
69 |
+
},
|
70 |
+
"nbformat": 4,
|
71 |
+
"nbformat_minor": 5
|
72 |
+
}
|
waveletDenoise.ipynb
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "5d909ed5-71b2-4586-96e1-f7820a8912ca",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"# Function to apply wavelet denoising\n",
|
11 |
+
"def wavelet_denoise(audio, wavelet='db1', level=1):\n",
|
12 |
+
" coeffs = pywt.wavedec(audio, wavelet, mode='per')\n",
|
13 |
+
" # Thresholding detail coefficients\n",
|
14 |
+
" sigma = np.median(np.abs(coeffs[-level])) / 0.6745\n",
|
15 |
+
" uthresh = sigma * np.sqrt(2 * np.log(len(audio)))\n",
|
16 |
+
" coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]\n",
|
17 |
+
" return pywt.waverec(coeffs, wavelet, mode='per')\n"
|
18 |
+
]
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"cell_type": "code",
|
22 |
+
"execution_count": null,
|
23 |
+
"id": "02d29b97-fe10-4cd9-a176-0c7bf153a3f9",
|
24 |
+
"metadata": {},
|
25 |
+
"outputs": [],
|
26 |
+
"source": []
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"metadata": {
|
30 |
+
"kernelspec": {
|
31 |
+
"display_name": "Python 3 (ipykernel)",
|
32 |
+
"language": "python",
|
33 |
+
"name": "python3"
|
34 |
+
},
|
35 |
+
"language_info": {
|
36 |
+
"codemirror_mode": {
|
37 |
+
"name": "ipython",
|
38 |
+
"version": 3
|
39 |
+
},
|
40 |
+
"file_extension": ".py",
|
41 |
+
"mimetype": "text/x-python",
|
42 |
+
"name": "python",
|
43 |
+
"nbconvert_exporter": "python",
|
44 |
+
"pygments_lexer": "ipython3",
|
45 |
+
"version": "3.11.7"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"nbformat": 4,
|
49 |
+
"nbformat_minor": 5
|
50 |
+
}
|
wienerFilter.ipynb
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"id": "a680a4b0-f69e-4645-9790-2f70f2bcf48f",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import scipy.signal\n",
|
11 |
+
"def wiener_filter(audio):\n",
|
12 |
+
" \n",
|
13 |
+
" '''\n",
|
14 |
+
" The Wiener filter is designed to minimize the impact of noise by applying an adaptive filtering process. \n",
|
15 |
+
" It tries to estimate the original, clean signal by taking into account both the noisy signal and the statistical properties of the noise. \n",
|
16 |
+
" The Wiener filter is particularly useful when dealing with stationary noise (constant background noise, like white noise).\n",
|
17 |
+
" '''\n",
|
18 |
+
" return scipy.signal.wiener(audio)"
|
19 |
+
]
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"cell_type": "code",
|
23 |
+
"execution_count": null,
|
24 |
+
"id": "b4eaa3f1-770f-4260-8a84-0d7afe5ea3b4",
|
25 |
+
"metadata": {},
|
26 |
+
"outputs": [],
|
27 |
+
"source": []
|
28 |
+
}
|
29 |
+
],
|
30 |
+
"metadata": {
|
31 |
+
"kernelspec": {
|
32 |
+
"display_name": "Python 3 (ipykernel)",
|
33 |
+
"language": "python",
|
34 |
+
"name": "python3"
|
35 |
+
},
|
36 |
+
"language_info": {
|
37 |
+
"codemirror_mode": {
|
38 |
+
"name": "ipython",
|
39 |
+
"version": 3
|
40 |
+
},
|
41 |
+
"file_extension": ".py",
|
42 |
+
"mimetype": "text/x-python",
|
43 |
+
"name": "python",
|
44 |
+
"nbconvert_exporter": "python",
|
45 |
+
"pygments_lexer": "ipython3",
|
46 |
+
"version": "3.11.7"
|
47 |
+
}
|
48 |
+
},
|
49 |
+
"nbformat": 4,
|
50 |
+
"nbformat_minor": 5
|
51 |
+
}
|