How can I subtract the baseline to zero?
조회 수: 39 (최근 30일)
이전 댓글 표시
I need to compare peak heights of several spectra but they do not baseline at zero, is there a way I can revert the baseline to zero using code on MATLAB?

Thanks, Hannah (absolute matlab novice)
댓글 수: 0
채택된 답변
Image Analyst
2015년 1월 16일
If you have the Signal Processing Toolbox you can use a Savitzky-Golay filter and I've attached a demo for that, or medfilt1(). Or if you have the Curve Fitting Toolbox you can use smooth() or lowess() or rloess() or functions like that. (Not sure if I spelled them correctly since I don't have that toolbox.
Attach your data and tell us what toolboxes you have and you might get someone to write you some code.
댓글 수: 7
Image Analyst
2015년 1월 18일
Hannah, I don't know what variables you're talking about, but true, about half my code is to just synthesize data because you didn't supply me with any. The main code is just these two lines:
baselineY = sgolayfilt(y, polynomialOrder, windowWidth);
detrendedY = y - baselineY;
Everything else is just to make it fancy or initialize things.
I chose an order of 3 because the curve sort of looked like a sine wave which has orders 1, 3, 5, etc. if you know the Taylor series form of it. But really for the Savitzky-Golay filter you don't want too high an order because it just takes more time and doesn't improve the results any. If you make a higher order it will just follow the noisy wiggles more and you don't want that . A lower order like 1, 2, or 3 will give better smoothing.
추가 답변 (4개)
Matt J
2015년 1월 16일
If you have the Image Processing Toolbox, maybe a median filtering would give a good approximation of the baseline, e.g.,
X-medfilt2(X,[1,3])
댓글 수: 0
Muhammad Irfan
2016년 5월 30일
I never thought I could easily find the solution to this problem :)...thanks Hannah and image analyst..
댓글 수: 0
Muhammad Irfan
2016년 5월 30일
Hi image analyst,...could you kindly advise which filter would work with my signal below..im having difficulties with using the filter u suggested to hannah...
thanks a lot in advance

Ella
2017년 2월 20일
Dear Image Analyst,
Thank you for your help with Hannah's question. I tried this method with my data and obtained a flat line. I was wondering if you might be able to help me out with a general baseline removal. In case this is possible, I have attached an example spectrum in .txt format (TanX and TanY are to be plotted on the x and Y axis and are one above each other in the document). We're only concerned about the peaks which are obvious. It was an x-ray photo-electron spectroscopy measurement. Thank you very much!!
댓글 수: 4
Image Analyst
2017년 2월 23일
Since you didn't start your own question, I couldn't answer it, but you can still give me the same number of reputation points (2) by "Voting" for my answer to Hannah up above (below my avatar). It doesn't matter that it was not directed towards you. Thanks for considering that!
Ella
2017년 2월 23일
Ah I see! Actually I already voted for your answer when I read it first time because it was the closest I had got to something useful! Okay - then if I have another question one day I'll post it in a seperate question then. Thanks again.
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

