MATLAB: Butterworth Bandpass filter design

filter

I'm trying to design a butterworth bandpass filter and the following code is what I have so far:
However, when I run this code my signal_filtered matrix does not represent the correct data. I've set it so the passband frequency is 9kHz-10kHz and it seems like all frequencies are being rejected.
FYI, my text file contains frequency and dB data.
Any help would be greatly appreciated 🙂

Best Answer

A better design would be:
[z,p,k] = butter(n, Wp, 'bandpass');
[sos, g] = zp2sos(z,p,k);
or the complete code (that I typed myself because my version of MATLAB will not run images of code):
Fs = 22500;
Fn = Fs/2;
Wp = [9000 10000]/Fn;
Ws = [8500 10500]/Fn;
Rp = 0.5;
Rs = 50;
[n, Wn] = buttord(Wp, Ws, Rp, Rs);
[z,p,k] = butter(n, Wp, 'bandpass');
[sos, g] = zp2sos(z,p,k);
and you can see the Bode plot:
figure
freqz(sos, 2^16, Fs)
so it is obvious that only a small portion of your signal will be passed. That is how the filter is designed, and it appears to work correctly.
.
Related Question