英文:
Java alternative for scipy butterworth bandpass filter
问题
我正在尝试对一些音频频率进行带通滤波,我已经成功在Python的scipy.signal模块中实现并获得了正确的结果。但我的需求是在Java中实现,以便我可以在Android中进行一些滤波。
我尝试在Java中使用berndporr/iirj库,但它返回的数据与原始数据相同。以下是使用该库的Java代码。list
是一个包含音频样本的双精度数组。
double[] filteredList = new double[list.length];
Butterworth butterworth = new Butterworth();
butterworth.bandPass(3,44100,110,90);
for(int i = 0; i < list.length; i++)
{
filteredList[i] = butterworth.filter(list[i]);
}
filteredList
与我的使用scipy编写的Python程序的输出不匹配。
Python代码如下:
import numpy as np
from scipy.signal import butter, lfilter
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y
arr = np.array(list)
filteredList = butter_bandpass_filter(arr, 20, 200, 44100, order=3)
这里的filteredList
包含了正确的输出。我正在将结果与应用20Hz-200Hz带通滤波器的FL Studio输出进行比较。
有人可以告诉我Java代码有什么问题,或者有人可以告诉我一个更好的用于音频滤波的库吗?
英文:
I am trying to bandpass some audio frequencies and I have successfully implemented and have got the correct results from scipy.signal module in python. But my necessity is to do that in java so that I can do some filtering in android.
I tried using berndporr/iirj library in java but it returns the data as it originally was. Here is the code in java using this library. The list
is a double array containing the audio samples.
double[] filteredList = new double[list.length];
Butterworth butterworth = new Butterworth();
butterworth.bandPass(3,44100,110,90);
for(int i = 0; i < list.length; i++)
{
filteredList[i] = butterworth.filter(list[i]);
}
The filteredList
does not match with the output of my python program which is using scipy.
The python code is as follows:
import numpy as np
from scipy.signal import butter, filter
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y
arr = np.array(list)
filteredList = butter_bandpass_filter(arr, 20, 200, 44100, order=3)
Here the filteredList
contains the correct output.
I am comparing the results with output from FL studio which is applying a 20hz-200hz bandpass filter.
Can anyone tell me whats wrong with my Java code or can anyone tell me a better library for audio filtering.
答案1
得分: 1
在Android中进行音频过滤,存在一个标准的均衡器AudioEffect库,看起来可用。
顺便提一下,Java是一个不太适合信号处理的痛苦语言。如果您需要超越Android的AudioEffects的某些功能,请考虑使用Android NDK并用C++编写。
英文:
For audio filtering in Android, there is a standard equalizer AudioEffect library that looks usable.
FWIW, Java is a painful language to do signal processing in. If you need something beyond Android's AudioEffects, consider using Android NDK and writing in C++.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论