1
$\begingroup$

I am plotting a dataset which is a Lorentzian, for the fitting, I need to subtract the background. I want to subtract a line from the dataset which connects the first and last points of my dataset. Here is the dataset Data. I do not know how to proceed with it.

Data = Import["Documents\\24.asc"];
Ampvsf1 = Data[[All, {1, 4}]];
graph = ListPlot[Ampvsf1, PlotRange -> Automatic]

I am attaching an image to make myself more clear

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$
iF = Interpolation[Ampvsf1[[{1, -1}]], InterpolationOrder -> 1];

dif = Ampvsf1 - Thread[{0, iF /@ Ampvsf1[[All, 1]]}];

ListPlot[{Ampvsf1, dif, Style[Ampvsf1[[{1, -1}]], Red]}, Joined -> {False, False, True}]

enter image description here

$\endgroup$
2
  • $\begingroup$ This works for me, Can we do the take the average of the first 10 points and the last 10 points to increase the accuracy. $\endgroup$
    – Bholu
    Sep 13, 2020 at 10:05
  • 1
    $\begingroup$ @Shelender, maybe you can try fit[x_] = Fit[Join[Ampvsf1[[;; 10]], Ampvsf1[[-10 ;;]]], {1, x}, x]; dif = Ampvsf1 - Thread[{0, fit /@ Ampvsf1[[All, 1]]}]; ListPlot[{Ampvsf1, dif, Style[Thread[{#, fit /@ #}] &@Ampvsf1[[All, 1]], Red]}, Joined -> {False, False, True}]? $\endgroup$
    – kglr
    Sep 13, 2020 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.