baseline correction using media filter
Show older comments
Hi
I have used median filter (medifilt1)to correct the baseline , is this method is correct ? or there is other methods that can give better results ?


close all
% plot default annotated peaks
subplot(2,1,1);
order =4 ;
framelen =13;
lx = 20;
% generate sinal
x = 1:1:1274;
y = (AV)';
y = sgolayfilt(y,order,framelen);
% get derivatives
dy = diff(y);
findpeaks(y -medfilt1(y,50) ,x,'Annotate','extents','MinPeakProminence',0.008);
[pks,locs,peakWidth1,p] = findpeaks(y -medfilt1(y,50),x,'MinPeakProminence',0.008);
subplot(212);
plot(x,y);
hold on
plot(locs,pks,'*m')
Thanks
Answers (1)
Star Strider
on 12 May 2017
0 votes
Your medfilt approach seems to be giving appropriate results, but is not the approach I would use.
For initial EKG signal processing, I usually use a Chebyshev Type II filter with a low-frequency cutoff of 1 Hz and a high-frequency of 100 Hz, since that eliminates the low-frequency baseline variations and d-c (constant) offset, and high-frequency noise. (Even abnormal EKGs — for example atrial flutter and fibrillation — have a bandwidth of 0+ to 100 Hz. Everything greater than 100 Hz is noise.)
Your original EKG appears to have atrial fibrillation, possibly contaminated with EMG noise. I would be reluctant to use a Savitzky-Golay filter on an EKG, since it has the tendency to obscure potentially clinically-relevant details.
8 Comments
sarmad m
on 15 May 2017
Star Strider
on 15 May 2017
The atrial waves should not be of sufficient amplitude to interfere with R-wave detection. (That record actually looks like flutter waves, since atrial fibrillation just looks like noise.)
I would use the Chebyshev Type II filter. It gives more predictable results, since you know exactly what it is doing.
sarmad m
on 15 May 2017
Star Strider
on 15 May 2017
I would use the Chebyshev Type II filter. The sgolayfilt approach can be difficult with physiological signals because it may not give the result you need, and the same is true for medfilt1. Both are essentially lowpass filters.
I always use specificallly-designed filters for physiological signals because I know exactly what the filters are doing.
sarmad m
on 16 May 2017
Star Strider
on 16 May 2017
Your data do not contain any time information, so I cannot calculate a sampling frequency from them. Filtering a signal without knowing the sampling frequency is pointless. The sampling frequency must be at least 250 Hz for this filter to work.
Here is the design for the Chebyshev Type II filter:
Fs = ...; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1.0 100]/Fn; % Passband Frequencies (Normalised)
Ws = [0.5 101]/Fn; % Stopband Frequencies (Normalised)
Rp = 10; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(1)
freqz(sosbp, 2^17, Fs)
(I tested this filter with a sampling frequency of 250 Hz, and it gave acceptable results with the freqz plot.)
Use the filtfilt function to do the actual filtering.
EKG_filt = filtfilt(sosbp, gbp, EKG_original); % Filter EKG Signal
I do not use medfilt1 for physiological signals (and I do not recommend it), so I will leave that to you to perform and compare with the Chebyshev filter results.
sarmad m
on 17 May 2017
Star Strider
on 17 May 2017
The Chebyshev filter would still be applicable. Do a fft (link) on your signal to determine the signal frequencies and the noise frequencies. Then, design the filter passband to include the signal and eliminate as much of the noise as possible, as well as eliminate baseline variation.
Experiment with both approaches to see what the best and most efficient is.
The plot looks like an EKG with atrial flutter. EKG signal processing questions are frequent here.
Categories
Find more on Signal Generation, Analysis, and Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!