FIltering for multiple band of frequncies

I have below two questions.
  1. I want to filter a signal with sampling 100Hz in range of 4-7Hz and 10-13Hz and 30-35Hz. I saw the bandpass function that says to filter seperating and concatenate the filtered signal. But I want to know if we could filter these 3 range of frequncies with any specific filter?
  2. What is bandpass or bandstop ripple and how to we choose the ripple ?

 Risposta accettata

As much as I like elliptic filters, creating three of them and filtering them in parallel is simply not efficient. Multiband filters are much easier to implement as FIR filters.
Try a FIR filter such as this one:
Fs = 100; % Sampling Frequency (Hz)
fcuts = [3.5 4 7 7.5 9.5 10 13 13.5 29 30 35 36]; % Frequencies
mags = [0 1 0 1 0 1 0 ]; % Passbands & Stopbands
devs = [0.05 0.01 0.05 0.01 0.05 0.01 0.05]; % Tolerances
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,Fs); % Kaiser Window FIR Specification
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale'); % Filter Realisation
figure
freqz(hh,1,2^14,Fs)
set(subplot(2,1,1), 'XLim',[0 50]); % Zoom Frequency Axis
set(subplot(2,1,2), 'XLim',[0 50]); % Zoom Frequency Axis
Then use the filtfilt function to do the actual filtering:
signal_filtered = filtfilt(hh, 1, signal);
The Bode plot for this filter:
FIltering for multiple band of frequncies - 2020 02 06.png

10 Commenti

Thank you for the response. It was helpful. Could you please tell me how did you define the mags and devs ?
As always, my pleasure!
The ‘mags’ tell kaiserord which of the ‘fcuts’ segments are passbands (1) and which are stopbands (0), so it is just a matter of lining them up correctly with the ‘fcuts’ frequency intervals.
The ‘devs’ vector are the allowed deviations, and it is generally preferable to have lower deviations in the passbands, and allow higher deviations in the stopbands.
Thanks alot. Much appreciated!!
Had another question, What is bandpass or bandstop ripple and how to we choose the ripple ?
As always, my pleasure!
In the fir1 filters designed by kaiserord, all of that is in the code for the kaiserord function (see Algorithms for detaills). The stopband attenuation is 50 dB. The passband ripple is usually about 1 dB.
Other functions, such as firpmord and firpm are more flexible and permit more parameters to be specified in the design.
I chose kaiserord and fir1 for this because they are generally adequate in my experience, and preferable for efficient multi-band filters such as the one you requested.
There are many other options. See Digital Filter Design for a reference to all of them.
Very nice and thanks a lot for sharing and for your clear explanation.
For those wanting to save some time when working with many frequency ranges and automatically define devs and mags those two alternatrive lines can be useful:
mags = [repmat([0 1],1,(size(fcuts)(2)/4)) 0];
devs = mags*0.01+!mags*0.05;
@Louis — Thank you!
I adopted a version of that later, most recently in How to apply a filter to a signal?
Hello Star Strider,
I am still a bit confused on lining up the mags to fcuts when you have mags with a length of 7 and fcuts with a length of 12.
@Ameen — The ‘mags’ vector corresponds to the passbands or stopbands described in ‘fcuts’.
An approach that might make it a bit easier to understand —
Fs = 1000; % Use Correct Sampling Frequency (Must Be Greater Than 370 Hz)
fcomb = [[55 59 61 64], [55 59 61 64]+60, [55 59 61 64]+120]; % BANDPASS Design
mags = [[0 1 0], [1 0], [1 0]];
dev = [[0.5 0.1 0.5], [0.1 0.5], [0.1 0.5]];
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
set(subplot(2,1,1), 'XLim', [0 200]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 200]) % Zoom X-Axis
Fs = 1000; % Use Correct Sampling Frequency (Must Be Greater Than 370 Hz)
fcomb = [[55 59 61 64], [55 59 61 64]+60, [55 59 61 64]+120]; % BANDSTOP Design
mags = [[1 0 1], [0 1], [0 1]];
dev = [[0.5 0.1 0.5], [0.1 0.5], [0.1 0.5]];
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
set(subplot(2,1,1), 'XLim', [0 200]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 200]) % Zoom X-Axis
This is the same code except that ‘mags’ is reversed (1→0 and 0→1) between the bandpass and bandstop designs. The ‘devs’ vector is unchanged.
Experiment with simple versions of this. You will then understand how it works. (You can do it without the window functions, however they correct for the signal and filter transfer function both being finite, so they make the filter more accurate.)
.
So the stopbands are [55 59], [61,64], [61 64]+60, [61 64]+120 and passbands are [59,61], [55 59]+60, [55 59]+120 in the first example?
No, they’re [59 61], [119 121], and [179 181] (or [59 61], [59 61]+60 and [59 61]+120) in this illustration.
They’re the centre two frequencies in those vectors.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by