MATLAB: Butterworth Bandpass filter issues

codefilterMATLAB

Hi there! I am trying to make a butterworth bandpass filter in matlab and am having some trouble with it. The specifications for my filter are a center frequency of 10kHz with limits of +/- 30 Hz. In addition to this, I'd like to have 100dB of attenuation at 1kHz away from the center frequency, so if anyone could shed some light on how I could do this that would be awesome!
Right now I am trying to test my filter by simulating a 10kHz sinusoidal signal in LTSpice, exporting the time-voltage data to matlab and then resampling the signal so that it is periodic. I have then made and applied a butterworth bandpass filter with passband 9970Hz – 10030 Hz in the hope that I can completely allow the 10kHz signal to pass through. Right now this is not the case and I am getting some cutoff which progressively increases with time. Running the provided matlab script with the provided text file will illustrate this. I have attached the matlab code as well as the exported time-voltage text file.
Any help would be greatly appreciated!

Best Answer

That is likely asking too much of a Butterworth design. Use an elliptic filter instead:
Fs = 44100; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [1E+3-30 1E+3+30]/Fn; % Passband Frequency (Normalised)
Ws = [1E+3-100 1E+3+100]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 100; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp,'bandpass'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
Use your own sampling frequency.
.