Borrar filtros
Borrar filtros

How to remove a baseline without using sgolayfilt

12 visualizaciones (últimos 30 días)
mabinj
mabinj el 5 de Sept. de 2017
Comentada: mabinj el 7 de Sept. de 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)');

Respuestas (2)

Star Strider
Star Strider el 5 de Sept. de 2017
Editada: Star Strider el 6 de Sept. de 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 el 5 de Sept. de 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 comentarios
Image Analyst
Image Analyst el 6 de Sept. de 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 el 7 de Sept. de 2017
Thank you, I will do so.
Thanks for all the help!

Iniciar sesión para comentar.

Categorías

Más información sobre Acoustics, Noise and Vibration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by