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.