0
$\begingroup$

I have the graph below that is generated from a list of data ("data1"). If I have an equation that generates the second plot (see code below), which corresponds to the second peak of the first image, how can I subtract plot 1 from plot 2?.

    peak = amp2UserDefined*
      Exp[-(x - x02UserDefined)^2/sigma2UserDefined^2]
peakplot = Plot[peak, {x, 60, 120}, PlotRange -> {-0.1, 0.1}]

Edit: The output of "peak" is 0.077 E^(-0.0349375 (-93.4 + x)^2) and data1 is can be found here https://pastebin.com/tn8PAPTB

Plot 1

Plot 2

$\endgroup$
2
  • $\begingroup$ it will help to provide Data1 or code to generate it. $\endgroup$
    – Nasser
    Apr 22 '20 at 2:56
  • $\begingroup$ Thank you Nasser. I have added data1 in the edits $\endgroup$
    – John
    Apr 22 '20 at 3:04
1
$\begingroup$

Not very elegant:

data2 = Select[data1, 60 <= #[[1]] <= 120 &];
f[x_] := 0.077 E^(-0.0349375 (-93.4 + x)^2)
Union[Transpose[{data2[[;; , 1]], 
      data2[[;; , 2]] - f /@ data2[[;; , 1]]}], Complement[data1, data2]]//ListPlot

enter image description here

EDIT

To answer a comment about subtracting both peaks:

f1[x_] := 0.07 E^(-0.170753 (-78.4 + x)^2)
Union[Transpose[{data2[[;; , 1]], 
      data2[[;; , 2]] - f /@ data2[[;; , 1]] - f1 /@ data2[[;; , 1]]}], 
      Complement[data1, data2]];

enter image description here

$\endgroup$
6
  • $\begingroup$ Thank you Alx! This seems to work very well!. I am also open to other suggestions but this code does the job! $\endgroup$
    – John
    Apr 22 '20 at 3:31
  • $\begingroup$ Alx! One question, could you tell me how to modify your code in case I wanted to also subtract the first peak from the data1?. The output of the first peak is 0.07 E^(-0.170753 (-78.4 + x)^2). Thank you ! $\endgroup$
    – John
    Apr 22 '20 at 3:45
  • $\begingroup$ First you need to know x coordinates of that range in data1, next is the same, it should be simply a replacement of {60, 120} range. $\endgroup$
    – Alx
    Apr 22 '20 at 3:48
  • $\begingroup$ Got it! But what I mean is how to subtract both at the same time from data1. They both have the same coordinates. $\endgroup$
    – John
    Apr 22 '20 at 3:49
  • $\begingroup$ I've edited my answer to subtract both peaks. $\endgroup$
    – Alx
    Apr 22 '20 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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