Effacer les filtres
Effacer les filtres

How to remove a baseline without using sgolayfilt

12 vues (au cours des 30 derniers jours)
mabinj
mabinj le 5 Sep 2017
Commenté : mabinj le 7 Sep 2017
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)');

Réponses (2)

Star Strider
Star Strider le 5 Sep 2017
Modifié(e) : Star Strider le 6 Sep 2017
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 le 5 Sep 2017
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 commentaires
Image Analyst
Image Analyst le 6 Sep 2017
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 le 7 Sep 2017
Thank you, I will do so.
Thanks for all the help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Acoustics, Noise and Vibration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by