Butterworth Bandpass filter design

20 views (last 30 days)
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 :)

Accepted Answer

Star Strider
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
Matija Jankovic
Matija Jankovic on 22 Jul 2020
This is actually really quite useful for me Star Strider. Thanks for taking the time to do this! I realize I should have probably provided a little more information about the data itself.
Basically, the text file I shared was the freq/dB data from a circuit I simulated on LtSpice. I have also attached the time domain data text file here which I'm assuming you're wanting to use?
The aim: In this circuit I have 3 AC sources (10kHz, 11kHz and 12kHz). The data in this text file is the circuit response to all three frequencies combined. I am trying to filter out the 11k and 12kHz frequencies responses and only be left with the 10kHz response. Maybe with this new text file I can do this? Thanks again!
Star Strider
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!
.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!