Reputation: 3389
I have a dataset the red line. I'm trying to find the minimum points highlighted in yellow if I take the reflection/mirror image of a data set.
See example code / plot below I'm trying to find a way to find the minimum points highlighted in yellow of the reflection/mirror image of a dataset (the blue line) that is below the reflection line (the black line).
Please note this is just a simple dataset there will be much larger datasets around 100000+
PS: I'm using Octave 3.8.1 which is like matlab
clear all,clf, clc,tic
x1=[0.;2.04;4.08;6.12;8.16;10.2;12.24;14.28;16.32;18.36]
y1=[2;2.86;4;2;1;4;5;2;7;1]
x2=[0.;2.04;4.08;6.12;8.16;10.2;12.24;14.28;16.32;18.36]
y2=abs(y1-max(y1));
data1 = y2;
reflection_line=max(y1)/2
[pks3 idx3] = findpeaks(data1,"DoubleSided","MinPeakHeight",0.1);
line([min(x1) max(x1)], [reflection_line reflection_line]);
hold on;
plot(x1,reflection_line)
hold on;
plot(x1,y1,'-r',x2,y2,'-b')
Upvotes: 0
Views: 432
Reputation: 6084
I am not reflecting your original data, but rather find the local maxima of the original values, that are larger than your given line.
Using a DIY alternative to findpeaks
:
A value is a local maximum, if it's larger than (or equal to) its predecessor and successor.
%% Setup
x1 = [0.;2.04;4.08;6.12;8.16;10.2;12.24;14.28;16.32;18.36];
y1 = [2;2.86;4;2;1;4;5;2;7;1];
reflection_line = max(y1)/2;
%% Sort by x value
[x1, I] = sort(x1);
y1 = y1(I);
%% Compute peaks
maxima = @(y) [true; y(2:end)>=y(1:end-1)] & ... % Value larger than predecessor
[y(1:end-1)>=y(2:end); true]; % Value larger than successor
maximaLargerThanLine = maxima(y1) & (y1>reflection_line);
%% Plotting
plot(x1,y1);
hold on;
plot(x1(maximaLargerThanLine),y1(maximaLargerThanLine),'rx');
line([min(x1) max(x1)], [reflection_line reflection_line]);
Upvotes: 0