Can I remove zeroth order baseline?

3 views (last 30 days)
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')

Accepted Answer

Chunru
Chunru on 18 May 2022
raw = readtable('raw.xlsx');
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)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!