Butterworth filter high pass and band pass

54 ビュー (過去 30 日間)
Dongwei Bai
Dongwei Bai 2019 年 7 月 21 日
回答済み: Star Strider 2019 年 7 月 21 日
I have a project design low pass, high pass and band pass filters to filter data, right now I'm using something like the code below and only changing 'low' to 'high' and 'bandpass' for all three filters but the results are not correct for high and bandpass. Does anyone know how to get dataOut for high and bandpass filter?
[b,a] = butter(3,[0.2 0.6],'low');
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);
  2 件のコメント
Star Strider
Star Strider 2019 年 7 月 21 日
Please see the documentation on IIR Filter Design.
This is going to throw an error:
[b,a] = butter(3,[0.2 0.6],'low');
Error using butter (line 62)
For the 'low' filter option, Wn must be a 1 element vector.
... the results are not correct for high and bandpass.
The prototype for all filters is the lowpass design. The others are all transformations of that design. You need to provide the appropriate passband and stopband frequencies. You can easily calculate the normalised frequencies by dividing the frequencies in Hz (or whatever units you are usng) by the Nyquist frequency. For example to calculate a bandpass filter with a 100 to 300 Hz passband and a sampling frequency of 1000 Hz (giving a Nyquist frequency, ‘Fn’) of 500 Hz):
Wp = [100 300]/Fn;
Also, you need to use the filtfilt function, not filter, for IIR filters.
Dongwei Bai
Dongwei Bai 2019 年 7 月 21 日
Thanks for replying, my problem is not about the low pass filter and I'm only using single element for low pass filter. The problems is to use high pass and band pass. Do you know how to do it?

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2019 年 7 月 21 日
Yes.
[b,a] = butter(3, 0.3, 'high'); % Highpass
[b,a] = butter(3,[0.2 0.6],'bandpass'); % Bandpass
I would use an elliptical filter, and a more sophisticated design, for example (from another post):
Ts = 1; % Sampling Interval (Days)
Ts = 1/365.25; % Sampling Interval (Years)
Fs = 1/Ts; % Sampling Frequency (Cycles/Year)
Fn = Fs/2; % Nyquist Frequency (Cycles/Year)
Wp = (1/13)/Fn; % Passband Frequency (Cycles/Year) Normalised
Ws = Wp*1.1; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple Or Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp); % Filter Design (Zero-Pole-Gain)
[sos, g] = zp2sos(z,p,k); % Second-Order-Section For Stability
figure
freqz(sos, 2^14, Fs)
set(subplot(2,1,1), 'XLim',[0 1])
set(subplot(2,1,2), 'XLim',[0 1])

Community Treasure Hunt

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

Start Hunting!

Translated by