How to create a filter with Hz and coefficient?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I got a very noisy signal and I would like to elimante the noise out of it.
According to a paper I should filter the data by "a filter between 0.5 and 35 Hz, using 8000 coefficient"
Does anybody know how to implement this in matlab? Or is there any "standard" code for this case?
Thank you for your help!
0 个评论
回答(1 个)
Star Strider
2019-8-14
A filter with 8000 coefficients is likely an FIR filter. For a simple bandpass or bandstop application, an IIR elliptical filter is much more efficient.
If you have R2018a or later, use either the bandpass or bandstop functions, depending on what you want to do. They will design an efficient IIR filter that you can use with filtfilt if you need to use those filters on other signals. If you do not have an earlier release than R2018a, it is still straightforward to design an elliptical filter that will do what you want.
A functioning bandpass elliptical filter prototype for your application is:
Fs = 1000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [0.5 35]/Fn; % Passband Normalised
Ws = [0.25 40]/Fn; % Stopband Normalised
Rp = 1; % Passband Ripple (Irrelevant in Butterworth)
Rs = 50; % Stopband Attenuation
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
The only thing you may need to change is the sampling frequency (‘Fs’) to match the sampling frequency of your signal. Use filtfilt to filter your signal with this filter.
2 个评论
Star Strider
2019-8-14
My pleasure.
That error is most likely caused by the sampling frequency ‘Fs’ being 80 Hz or lless for this filter. Ideally, the sampling frequency of your signal should be at least 90 Hz, and preferably higher (256 Hz).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!