Butterworth filter high pass and band pass
33 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Star Strider
il 21 Lug 2019
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.
Risposte (1)
Star Strider
il 21 Lug 2019
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])
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!