Detrending still leaves a slope
Show older comments
I am attaching two line profile examples for my case. After using detrend, I obtain the profile given in 'detrend_lineprofile' photo for the original data shown in 'lineprofile' photo. Although detrending seems it is working, still there is a slope towards the end of the profile after the detrend.
I want to get rid of this slope and bring the base of the profile to an even, flat condition. Is there a way to get rid of this slope after detrending?
Thanks in advance for all the help.
4 Comments
Steven Lord
on 7 Sep 2023
How did you call detrend? In particular, what value did you specify for the n input argument? Or did you call it with only one input?
Bugrahan Guner
on 7 Sep 2023
dpb
on 7 Sep 2023
Don't attach pictures, attach a .mat file of the raw data.
Have you just tried successively detrending?
Bugrahan Guner
on 7 Sep 2023
Accepted Answer
More Answers (1)
John D'Errico
on 7 Sep 2023
Edited: John D'Errico
on 7 Sep 2023
It depends on how you define detrend. Clearly, you have a different definition from me, at least, as well as the author of the function detrend.
On average, there is no slope. No overall trend. Yes, if you look at the baseline of that curve, there is an overall trend. But that is not how detrend is defined to work. Of course you can always find some subset of points on any scattered curve that will appear to have a trend.
My guess would be, IF you passed a straight line fit (using, for example, polyfit) through the detrended curve, the slope of that fit would be exactly zero.
help detrend
So, called with only one argument, detrend will remove a linear trend from the overall curve. For example, since you give no data...
t = linspace(0,1,100);
y0 = exp(t) + randn(size(t))/10;
plot(t,y0)
y1 = detrend(y0);
plot(t,y1)
So a linear trend has been removed. I might have done this instead:
P1 = polyfit(t,y0,1);
y1b = y0 - polyval(P1,t);
norm(y1-y1b)
As you can see, the two curves are identical (since the difference is zero.) As well, if you read the help for detrend, it says nothing at all about finding, AND removing a baseline trend.
Finally, let me test my claim that the slope of the detrended curve will be zero. The first coefficient out of polyfit should be zero, to within floating point trash.
polyfit(t,y1,1)
As well, the second coefficient is also zero, since detrending also removed any constant, DC component in the curve.
Anyway, feel free to define detrending in any way you wish. But don't expect software to read your mind. And if that day ever comes when software can read my mind, I'm heading for the hills anyway. But then, it probably knows that already.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



