File size: 1,111 Bytes
309d009 f2dc369 |
1 2 3 4 5 6 7 8 9 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 |
from scipy.signal import butter, lfilter
import scipy.signal
# def high_pass_filter(audio, sr, cutoff=100, order=5):
# """
# Applies a high-pass filter to an audio signal.
# Parameters:
# audio (numpy array): The input audio signal.
# sr (int): The sample rate of the audio signal.
# cutoff (float): The cutoff frequency in Hz. Default is 100 Hz.
# order (int): The order of the filter. Default is 5.
# Returns:
# numpy array: The filtered audio signal.
# """
# # Design the high-pass filter using a Butterworth filter design
# sos = scipy.signal.butter(order, cutoff, btype='highpass', fs=sr, output='sos')
# # Apply the filter using sosfilt (second-order sections filter)
# filtered_audio = scipy.signal.sosfilt(sos, audio)
# return filtered_audio
def high_pass_filter(audio, sr, cutoff=300):
# Design a Butterworth high-pass filter
nyquist = 0.5 * sr
normal_cutoff = cutoff / nyquist
b, a = butter(1, normal_cutoff, btype='high', analog=False)
filtered_audio = lfilter(b, a, audio)
return filtered_audio
|