How to remove a baseline without using sgolayfilt

16 ビュー (過去 30 日間)
mabinj
mabinj 2017 年 9 月 5 日
コメント済み: mabinj 2017 年 9 月 7 日
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.
mabinj
mabinj 2017 年 9 月 7 日
Thank you, I will do so.
Thanks for all the help!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by