Stopband filter with multiple stopbands
15 views (last 30 days)
Show older comments
Pseudoscientist
on 18 Mar 2021
Commented: Pseudoscientist
on 26 Jan 2022
Hello, I have a fMRI signal sampled at 10 Hz and I need to create a stopband filter with three stop bands
This examle looks something like it but I dont quite understand it:
https://www.mathworks.com/matlabcentral/answers/503999-filtering-for-multiple-band-of-frequncies
0 Comments
Accepted Answer
Star Strider
on 18 Mar 2021
This is a relatively straightforward problem.
Example —
Fs = 250;
fcomb = [[49 49.5 50.5 51], [49 49.5 50.5 51]+10, [49 49.5 50.5 51]+12.5];
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',[45 65]) % Optional
set(subplot(2,1,2), 'XLim',[45 65]) % Optional
producing:
Make appropriate changes for your signal and requirements.
3 Comments
Star Strider
on 22 Mar 2021
‘Why is it not just [49 51]?’
Because the frequencies on either side of the stopband need to be specified. In this baandstop filter, the first and last elements of the 4-element vector are the passband frequencies, and the centre two are the stopband freqencies. I group the pasband and stopband frequencies together in individual sub-vectors because it’s easier to read and understand the filter construction this way. (The ‘mags’ and ‘devs’ vectors would have reversed magnitudes to design passbands instead of stopbands. This can get complicated quickly, so I’ll stop with that observation. See the relevant documentation for details.)
‘How do I modify this filter for that since the values of the vectors of fcomb are separated by 0.5 Hz?’
This should do what you want:
Fs = 250;
fcomb = [[0.005 0.01 0.1 0.105], [0.115 0.12 0.35 0.38], [0.75 0.8 1.3 1.35]];
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 1.5]) % Optional
set(subplot(2,1,2), 'XLim',[0 1.5]) % Optional
Note that this is going to be a long filter (the length is a funciton of the sampling frequency, acttually), so likely not very efficient. (The sampling frequency should be at least 5 Hz for this filter to work optimally, and above 2.75 Hz for it to work at all.) However if it is only necessary to filter each signal once, the computational efficiency should not be a significant problem. Use the filtfilt function to do the actual filtering.
More Answers (0)
See Also
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!