I've implemented this bandpass filter in matlab for the audio signals and it's working as expected. Now, I tried to implement the same thing in Python but it doesn't produced expected results, it just sort of discard the whole signal.
Here is the Matlab code:
[f,fs] = audioread('abc.wav');
n=6; %order
beginFreq = (300/(fs/2));
endFreq = (2300/(fs/2));
[b,a] = butter(n,[beginFreq,endFreq],'bandpass');
%filter the signal
filtered = filter(b,a,signal);
Here is the Python code (using scipy.signal)
[originalSignal, sampleRate] = sf.read('abc.wav')
lower = (300/(sampleRate/2))
higher = (2300/(sampleRate/2))
n=6 #order
[b, a] = signal.butter(n, [lower, higher], 'bandpass')
filtered = signal.lfilter(b, a, originalSignal)
plt.plot(originalSignal, 'b', filtered,'r')
There is one more weird thing with the output! I tried to change the values of the lower and higher frequencies. As the frequency range increases; only the amplitude of output signal increases from 'almost zero' to higher value. For example, when I give the lower and higher frequency values as '100.0' and '13000' respectively, the output signal is "same" as the input signal but with almost half the amplitude. So, apparently the filter is not affecting the frequencies at all but rather affecting the amplitude..... I've no idea what's going on... :(