0

I am new to Octave so please bear with me..

I have a dataset with x and y values that I plot as a line. Then, I want to annotate selected minima by choosing a range and finding within this range the local minimum. How do I set a range within the x values of my dataset to look into? I figured out a way to find the total minimum or the local minima (by setting a y threshold) but beyond that I am lost.

How do I mark for example the peak at 1450 without marking the peak at 2850? (note that the x axis is inverted)

Thank you!

To find a minimum with a peak height above 0.11

iny=1-y; %invert the data
[pks dm]=findpeaks(invy,"MinPeakHeight",0.11); %look for a local maximum
hold on;
plot(t(dm),y(dm),"xm");
hold off

example of my data and the output when looking for the local minimum with a peak height of 0.11

PS. If someone knows a smart way for me to link my data (2000+ lines), I am happy to do so.

dimidola
  • 3
  • 2
  • 1
    I'm really not sure about what you are asking, is just how to select a sub-array? The first 10 elements: `y(1:10)`, the last 10 elements: `y(end-9:end)`, 51 elements in the middle: `y(150:200)` , the elements of y where x is greater than a value x0: `y(x > x0)`, ... – PierU Mar 02 '23 at 15:48
  • The function `findpeaks` in the `signal` package (https://octave.sourceforge.io/signal/function/findpeaks.html) may be what you are looking for. – Howard Rudd Mar 02 '23 at 16:52
  • @HowardRudd the OP is already using `findpeaks` – PierU Mar 02 '23 at 17:08
  • Doh! Anyway the documentation for `findpeaks` shows an example ("Demonstration 2") of finding the positions of multiple peaks on a similar noisy curve. It does this using the additional argument `MinPeakDistance`. – Howard Rudd Mar 02 '23 at 22:01
  • @PierU I think your suggestion is the right way to go but I am too dumb to figure it out. I want to ba able to annotate the peak at x=1450 but if I use the findpeaks as I did, I also annotate the peak at x=2850 because it is bigger. If I had a way of limiting the x range in which the findpeaks looks for a peaks to 1000-2000, then only the peak at 1450 would be found and I would be happy. – dimidola Mar 06 '23 at 08:35
  • You can input a subarray as suggested above, or you can filter the found peaks before plotting. Where is your difficulty? Do you understand basic indexing? Or is it the logic? – Cris Luengo Mar 06 '23 at 14:10
  • @CrisLuengo I am an absolute beginner.. – dimidola Mar 08 '23 at 14:28

1 Answers1

0

If you want to mark only peaks close to 1450, you could for example use a small range to filter the found peaks. t(dm) is the position, then sm = (t(dm) > 1400) & (t(dm) < 1500) selects elements in t(dm) that are within those limits. The corresponding y values are y(dm)(sm).

sm = (t(dm) > 1400) & (t(dm) < 1500);
plot(t(dm)(sm), y(dm)(sm), "xm");
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120