How to create a filter with Hz and coefficient?

4 views (last 30 days)
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!

Answers (1)

Star Strider
Star Strider on 14 Aug 2019
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 Comments
Max Behr
Max Behr on 14 Aug 2019
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 on 14 Aug 2019
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).

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!