Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions FlashSR/Util/UtilAudioLowPassFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ def lowpass(audio:ndarray, #[time] 1d array

@staticmethod
def lowpass_filter(x:ndarray, #[time] 1d array
highcutoff_freq:float, #high cutoff frequency
fs:int,
order:int, #the order of filter
ftype:Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'],
upsample_to_original:bool = True
) -> ndarray: #[time] 1d array
highcutoff_freq:float, #high cutoff frequency
fs:int,
order:int, #the order of filter
ftype:Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'],
upsample_to_original:bool = True
) -> ndarray: #[time] 1d array
nyq = 0.5 * fs
# Ensure hi is between 0 and 1 (exclusive)
hi = highcutoff_freq / nyq
hi = min(hi, 0.999) # Clamp to just below 1
hi = max(hi, 0.001) # Clamp to just above 0

if ftype == "butter":
sos = butter(order, hi, btype="low", output="sos")
elif ftype == "cheby1":
Expand Down Expand Up @@ -106,4 +110,4 @@ def subsampling(data, lowpass_ratio, fs_ori=44100, upsample_to_original:bool = T

if __name__ == "__main__":
util = UtilAudioLowPassFilter()
util.lowpass(np.zeros(24000),48000, filter_name="cheby", filter_order=8, cutoff_freq=8000)
util.lowpass(np.zeros(24000),48000, filter_name="cheby", filter_order=8, cutoff_freq=8000)