2
$\begingroup$

I have a such graphics enter image description here

which plot by this data,and its range of x is from 10 to 90 commonly:

data = (Uncompress@*FromCharacterCode@*
    Flatten@*(ImageData[#1, "Byte"] &)@*Import)[
  "http://ooo.0o0.ooo/2016/12/14/5850ba5019da8.png"];

I want make an artificial peak in some specified place,such as the red arrow point. enter image description here

I can made it by Photoshop,but little troublesome: enter image description here

But can I do it in Mathematica?

Current try

range = Select[data, 42 < First[#] < 49 &];
gapData = Complement[data, range];
xpos = Round[Length[range]/2];
range[[xpos - 10 ;; xpos + 10]] = {range[[xpos, 1]], 2000};
range = Transpose[{First /@ range, MeanFilter[Last /@ range, 3]}];
smoothData = SortBy[Join[gapData, range], First];
ListLinePlot[smoothData, PlotRange -> All]

enter image description here

If I use MeanFilter,I will get a little fat peak sometimes,but actually it cannot be that.

$\endgroup$
6
$\begingroup$

If a simple ReplacePart is not sufficient here, you can define a function that uses a window to add a peak around a neighbourhood. Here is an example of what I mean:

ClearAll[addPeak]
addPeak[position_Integer, {size_, width_Integer}][data : {{_, _} ..}] /;
  ((position > width) && (position < (Length@data - width))) := 
  ReplacePart[data, 
   Table[q -> {data[[q, 1]], 
      data[[q, 2]] + size BartlettWindow[(q - position)/width]}, {q, 
     position - width, position + width}]];
addPeak[position_Integer, {size_, width_Integer}][data : {{_, _} ..}] := 
  data;

You can change BartlettWindow to any preset windowing function (or pass it on as an option).

Here's the result of adding a peak of magnitude 1000 at position 2025 of width 840 data points:

ListLinePlot[addPeak[2025, {1000, 420}][data], PlotRange -> All]

enter image description here

and here is the result of adding a narrower peak of width 100 points and magnitude 4000 to the same point:

ListLinePlot[addPeak[2025, {4000, 50}][data], PlotRange -> All]

enter image description here

Even if it's not precisely what you are looking for, it should get you started.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Maybe we should rescale that 2025 to {10,90}. :) $\endgroup$ – yode Dec 14 '16 at 5:04
  • $\begingroup$ I don't quite understand? 2025 refers to the position of the centre of the peak $\endgroup$ – gpap Dec 14 '16 at 5:06
  • $\begingroup$ Yep,I got that.I mean,it is not easy to know that position is 2025.:) $\endgroup$ – yode Dec 14 '16 at 5:07
  • $\begingroup$ Ah, I see now. Well, all you need is to call it like (if, say you want the peak at 45.): addPeak[Sequence @@ First@Position[data, {45., _}], {4000, 50}][data] $\endgroup$ – gpap Dec 14 '16 at 5:11

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.