How to remove a baseline without using sgolayfilt

36 次查看(过去 30 天)
I have around 1000 files, see attached graphs, and I want them to all be on the same baseline for direct comparison. I have tried the sgolayfilt with code below, however that removes a lot of features in my data as it is essentially a damping technique aswell. I was wondering if there was a baseline function that let you manually input points for fitting?
windowWidth = 101
polynomialOrder = 3
baselineY = sgolayfilt(y, polynomialOrder, windowWidth);
figure(1)
plot(x, baselineY,'r');
title('Baseline graph');
xlabel('Wavenumber (cm-1)');
ylabel('Absorbance (a.u)');

回答(2 个)

Star Strider
Star Strider 2017-9-5
编辑:Star Strider 2017-9-6
It depends on what you intend by ‘baseline’ (that you did not define).
The detrend function could be what you want.
EDIT
To illustrate detrend:
x = linspace(900, 1900);
y1 = randn(size(x)) + cumsum(ones(size(x)))*0.3 + 1;
y2 = randn(size(x)) + cumsum(ones(size(x)))*0.9 + 2;
y1d = detrend(y1);
y2d = detrend(y2);
figure(1)
subplot(2,1,1)
plot(x, y1, x, y2)
title('Original')
grid
subplot(2,1,2)
plot(x, y1d, x, y2d)
title('Detrended')
grid

Luuk van Oosten
Luuk van Oosten 2017-9-5
As far as I know, sgolayfilt does not subtract the background signal (what I think you mean when you refer to 'same baseline'), but just smooths the data (sometimes also referred to as "noise reduction").
If you want an easy plug-and-play function to correct the baseline of your signals I would suggest the following :
Y_subtracted = msbackadj(X_yoursignal,Y_yoursignal);
  4 个评论
Image Analyst
Image Analyst 2017-9-6
Use this code to ask your user to manually/interactively enter the 2 y values you need.
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter y1 : ', 'Enter y2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
Adapt as needed.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Acoustics, Noise and Vibration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by