Update highPassFilter.py
Browse files- highPassFilter.py +41 -35
highPassFilter.py
CHANGED
@@ -1,35 +1,41 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding: utf-8
|
3 |
-
|
4 |
-
# In[2]:
|
5 |
-
|
6 |
-
|
7 |
-
import scipy.signal
|
8 |
-
|
9 |
-
def high_pass_filter(audio, sr, cutoff=100, order=5):
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
|
4 |
+
# In[2]:
|
5 |
+
|
6 |
+
|
7 |
+
import scipy.signal
|
8 |
+
|
9 |
+
# def high_pass_filter(audio, sr, cutoff=100, order=5):
|
10 |
+
# """
|
11 |
+
# Applies a high-pass filter to an audio signal.
|
12 |
+
|
13 |
+
# Parameters:
|
14 |
+
# audio (numpy array): The input audio signal.
|
15 |
+
# sr (int): The sample rate of the audio signal.
|
16 |
+
# cutoff (float): The cutoff frequency in Hz. Default is 100 Hz.
|
17 |
+
# order (int): The order of the filter. Default is 5.
|
18 |
+
|
19 |
+
# Returns:
|
20 |
+
# numpy array: The filtered audio signal.
|
21 |
+
# """
|
22 |
+
# # Design the high-pass filter using a Butterworth filter design
|
23 |
+
# sos = scipy.signal.butter(order, cutoff, btype='highpass', fs=sr, output='sos')
|
24 |
+
|
25 |
+
# # Apply the filter using sosfilt (second-order sections filter)
|
26 |
+
# filtered_audio = scipy.signal.sosfilt(sos, audio)
|
27 |
+
|
28 |
+
# return filtered_audio
|
29 |
+
|
30 |
+
|
31 |
+
def high_pass_filter(audio, sr, cutoff=300):
|
32 |
+
# Design a Butterworth high-pass filter
|
33 |
+
nyquist = 0.5 * sr
|
34 |
+
normal_cutoff = cutoff / nyquist
|
35 |
+
b, a = butter(1, normal_cutoff, btype='high', analog=False)
|
36 |
+
filtered_audio = lfilter(b, a, audio)
|
37 |
+
return filtered_audio
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|