# Can I remove zeroth order baseline?

2 views (last 30 days)
Ardin Sacayanan on 18 May 2022
Commented: Ardin Sacayanan on 18 May 2022
I'm trying to clean up a signal using butterworth filter and baseline correction by subtracting absolute minimum value. However, my filtered data still has a few outliers that's causing a slight shift upwards away from zero. I was wondering if there's a way to remove those small outliers or have a zero order baseline so that the black lines are inline with zero?
Attached below are the code and the dataset that I used for this particular example.
Xcontractions = raw.rXcont;
Ycontractions = raw.rYcont;
Time = raw.Time;
%% Low-pass filter
%Set to remove frequencies higher than 5Hz
Fn = 35.55/2; %Frame rate for this particular video
Wp = 5/Fn;
Ws = 1.2*Wp;
Rp = 0.2;
Rs = 20;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a]=butter(n,Wn,'low');
Xcontractions = filtfilt(b,a,Xcontractions);
Ycontractions = filtfilt(b,a,Ycontractions);
%% Removes baseline
Xcontractions = Xcontractions-min(Xcontractions);
Ycontractions = Ycontractions-min(Ycontractions);
XYcontractions = Xcontractions + Ycontractions;
%% Plots graph
plot(raw.rXcont)
hold on
plot(Xcontractions)
legend('Original','Filtered')

Chunru on 18 May 2022
Xcontractions = raw.rXcont;
Ycontractions = raw.rYcont;
Time = raw.Time;
%% Low-pass filter
%Set to remove frequencies higher than 5Hz
Fn = 35.55/2; %Frame rate for this particular video
Wp = 5/Fn;
Ws = 1.2*Wp;
Rp = 0.2;
Rs = 20;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a]=butter(n,Wn,'low');
Xcontractions = filtfilt(b,a,Xcontractions);
Ycontractions = filtfilt(b,a,Ycontractions);
%% Removes baseline
Xcontractions = Xcontractions-min(Xcontractions);
Ycontractions = Ycontractions-min(Ycontractions);
XYcontractions = Xcontractions + Ycontractions;
%% Plots graph
plot(raw.rXcont)
hold on
plot(Xcontractions)
legend('Original','Filtered')
% find local min
tf = islocalmin(Xcontractions, 'MinSeparation', 5);
plot(find(tf), Xcontractions(tf), 'ok');
baseline = median(Xcontractions(tf));
yline(baseline, 'LineWidth', 2)
##### 1 CommentShowHide None
Ardin Sacayanan on 18 May 2022
This is exactly what I need, thank you!