# Applying bessel filter to raw data to reduce the noise (error)

15 views (last 30 days)
Commented: Mathieu NOE on 21 May 2021
Hi Everyone,
I am trying to filter a set of data that I got from experiments using butterworth and bessel filters.
First I filtered the data using butterworth filter and things went very smooth. I used the matlab functions to design the filter and then applied them to the data using filter.
But for the bessel filter, i designed the filter successfully but I can't filter the noise using them. can someone share a code for bessel filter design and implementation with me which i can use to filter my data

Mathieu NOE on 20 May 2021
hello
here you are my friend; bessel are continuous filters that must be converted to digital (a contrario from butter that generates directly the digital filter) - that was probably your issue
% Design a 5-th order Bessel analog filter (fc = 100 Hz) and convert it to a
% digital filter.
Fs =1000; % Sampling frequency
N = 5;
fc = 100;
[z,p,k] = besself(N,fc); % Bessel analog filter design
[num,den]=zp2tf(z,p,k); % Convert to transfer function form
[numd,dend]=bilinear(num,den,Fs); % Analog to Digital conversion
% [sos] = zp2sos(zd,pd,kd); % Convert to SOS form
% fvtool(sos) % Visualize the digital filter
samples = 1e4;
signal = randn(samples,1);
dt = 1/Fs;
time = (0:samples-1)*dt;
signal_filtered_bessel = filtfilt(numd,dend,signal);
plot(time,signal,'b',time,signal_filtered_bessel,'r');
Mathieu NOE on 21 May 2021
hello again
sure, filtfilt is not a real time implementation, but I would not either recommend to use filter as is;
As we are dealing here with IIR filters, the best method to implement a IIR filter for real time filering is to convert is to so called "bi quad" form - a.k.a second order sections - , because they are best in terms of accuracy and stability (some other implementations like the direct form are much more sensitive to coefficients rounding and can therefore either not match the desired filter's characteristics, or even worse, they can become unstable)
to convert your filter into biquad sections , use the "sos" matlab command (sos = second order sections , also known as "biquad" in real time software words)
now if you intend to use that filter for anti aliasing purposes , you have to use an analog filter before you actually do the analog to digital conversion (after it's too late ! ) , or the other options is to oversample then digital low pass anti aliasing the decimation and you're good too; the only drawback of the second method is the necessity to make the ADC work at much higher sampling rates and also the implementation and running of the low pass digital filter at high sampling rate can be a significant burden on your processor