Need help designing stopband filter
3 views (last 30 days)
Show older comments
Pseudoscientist
on 26 Jan 2022
Commented: Star Strider
on 9 Feb 2022
Hello,
I'm trying to design a stopband filter that can remove spikes at 1.294 Hz and 3.101 Hz
My data matrix 64x64x64x2960, where the three first dimensions are spatial dimensions and the 4th dimension is the temporal dimension along which I need to filter the data.
I have tried this, but it doesnt work for 2960 data points and requires at least 5040 data points:
Fs = 10;
fcomb = [[1.285 1.29 1.3 1.35],[2.85 2.90 3.15 3.20]];
mags = [[1 0 1], [0 1];
dev = [[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])
I have also tried matlabs bandstop() function, but somehow it made my data completely flat in freq domain. I only want to remove the spikes at 1.294 Hz and 3.101 Hz ...
0 Comments
Accepted Answer
Star Strider
on 26 Jan 2022
Thank you for quoting my code!
The FIR filter will eliminate both frequencies in one filtfilt call to it, however they are not efficient and can only be used on long signals. It might be best to use two IIR filters in series.
That design would be something like this —
Fs = 10;
Fn = Fs/2;
Ws = [1.290 1.298]/Fn;
Wp = Ws.*[0.999 1.001];
Rs = 50;
Rp = 1;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs);
[z,p,k] = ellip(n,Rp,Rs,Wp,'stop');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos, 2^16, Fs)
set(subplot(2,1,1), 'XLim',[1.25 1.35])
set(subplot(2,1,2), 'XLim',[1.25 1.35])
Ws = [3.0 3.2]/Fn;
Wp = Ws.*[0.999 1.001];
Rs = 50;
Rp = 1;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs);
[z,p,k] = ellip(n,Rp,Rs,Wp,'stop');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos, 2^16, Fs)
set(subplot(2,1,1), 'XLim',[2.5 3.5])
set(subplot(2,1,2), 'XLim',[2.5 3.5])
There is no way of cascading them functionally, so the only option is to use the output of the first filter as the input to the second filter. Use the filtfilt function to use them to filter the signals.
.
14 Comments
Star Strider
on 9 Feb 2022
Noi worries about the questions!
Otherwise, I well know that feeling! SARS-CoV-2 precipitates a sustained immune response with elevated cytokines and interleukins of several varieties. That’s likely the cause of the ‘brain fog’, and it takes a while to get back to normal.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!