Butterworth Bandpass filter design
20 views (last 30 days)
Show older comments
Matija Jankovic
on 22 Jul 2020
Commented: Star Strider
on 22 Jul 2020
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 :)
0 Comments
Accepted Answer
Star Strider
on 22 Jul 2020
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.
.
4 Comments
Star Strider
on 22 Jul 2020
My pleasure.
If all the sampling intervals are equal, the sampling interval is 3.697882035164080e-007 and the sampling frequency is 2.704250677795428e+06. Use those with the filter deisgn code and you should have no problems. Remember, the second column is the signal, so filter it. Plot the filtered and unfiltered signals against the first column, that ppears to be the sampling times. You have already written most of that (except for the plot calls, assuming that you want to plot the original signal and filtered output), so there is nothing for me to add at this point.
If my Answer helped you solve your problem, please Accept it!
.
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


