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!

回答(1 个)

Star Strider
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 个评论
Max Behr
Max Behr 2019-8-14
Thanks for your answer.
I got a programm which detects the heart beats of a ECG. The detection is usually working very well. But sometimes the programm doesn't detect it correctly.
Now I got the detected heartbeats and I can calculate the Heartfrequency out of it.
Unfortunately there are some not realistic peaks and drops, e.g. down to 10 beats per minute.
Therefor I would like to denoise the calculated heartfrequencies over time.
I tired to use ur code but I am getting an error code:
Error using ellipord (line 77)
The cutoff frequencies must be within the interval of (0,1).
Error in filtfilt (line 7)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Order Calculation
Star Strider
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).

请先登录,再进行评论。

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by