Skip to content

Commit

Permalink
Fixed no results when LowPass exceeds Nyquist frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
Paradeluxe committed Dec 14, 2024
1 parent d665832 commit afc438b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def runPraditor(params, audio_obj, which_set):
fs=_audio_obj.frame_rate
)

# warning or auto change?
if which_set == "offset":
_audio_arr_filtered = np.flip(_audio_arr_filtered)

Expand Down
8 changes: 6 additions & 2 deletions tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def bandpass_filter(data, lowcut, highcut, fs, order=4):
nyquist = 0.5 * fs
low = lowcut / nyquist
high = highcut / nyquist
b, a = butter(order, [low, high], btype='bandpass', output="ba")
filtered_data = filtfilt(b, a, data)
try:
b, a = butter(order, [low, high], btype='bandpass', output="ba")
filtered_data = filtfilt(b, a, data)
except ValueError: # 如果设置的最高频率大于了可接受的范围,则变为(实际意义上的)高通滤波
b, a = butter(order, [low, 1], btype='bandpass', output="ba")
filtered_data = filtfilt(b, a, data)
return filtered_data


Expand Down

0 comments on commit afc438b

Please sign in to comment.