How to find corresponding peaks between two datasets using timestamps

Hi everyone,
I have a 2 datasets (Dataset_Black and Dataset_Grey) of which peaks are known to follow each other up. Now I am trying to automatically select peaks throughout the whole dataset (which consists over 2018-2020). See below: the related peaks are circled, as you can see each peak of the black Dataset_Black is followed by a smaller peak in Dataset_Grey. In the end I need the maximums of each corresponding peak in order to test whether a larger peak in Dataset_Grey indeed is preceded by a larger peak in Dataset_Black.
I selected the peaks in the grey dataset I want to analyse using:
[pks_grey loc_grey]=findpeaks(Dataset_grey.fixed_10mins, 'MinPeakDistance', 1, 'MinPeakHeight', 350, 'MinPeakProminence', 200);
This gives me a dataset of 114 time locations and their value. How can i use this to find the accompying preceding peaks in the blackline?
Or does someone have a better way to find and select these peaks?

4 Comments

Thanks. I'm familiar with that function, thoug I'm not sure how it would help?
How many peaks are there in black curve? Grey you got 114.
250 peaks, of which some are not followed up with a signal in the grey curve.

Sign in to comment.

Answers (1)

Read about knnsearch. Provide the locations of Grey data and get the distance, nearest points to Black data. By checking the distance or the respective locations, you can pick your required values.

5 Comments

That definitely got me a couple steps further. I think it almost works.
At the moment it selects the values of Dataset_black right next to the locations of the peaks found in Dataset_grey, though I need it to select the maximum of the peaks in Dataset_Black preceding Grey.
This is how i've done it
[pksdb locdb]=findpeaks(Dataset_Grey, 'MinPeakDistance', 1, 'MinPeakHeight', 350, 'MinPeakProminence', 200);
[Idx, D]=knnsearch([Time Dataset_Grey], [locdo pksdo], 'K', 10, 'Distance', 'chebychev') %, 'includeTies', true)
X=[Time, Dataset_Black];
Y=[Time(locdb) (pksdb)] ;
[cIdx,cD] = knnsearch(X,Y,'K',1, 'SortIndices', 1);
figure; hold
plot(Time_10mins_fixed3, (Dataset_bGlack), 'k-')
plot(Time_10mins_fixed3, (Dataset_Grey), 'Color', [0.5 0.5 0.5])
line(X(cIdx,1),X(cIdx,2),'Color',[1 0 0],'Marker','x',...
'Linestyle','none','Markersize',10)
I tried all the 'Distance' metrics, such as 'chebychev' and 'hamming', though this doesn't solve the problem.
Is something missing here? or do I need a work around?
Pick the multiple data points and check by the locations...you need to pick those values for which
x_black < x_gray
By taking large amounts 'K' (number of nearest neighbour) and then filtering the largest value?
Not sure whether I get it right, most peaks are now selected though, though still some missing. somehow it doesn't select values above 12. very close though! is this what you meant?
[cIdx,cD] = knnsearch(X,Y,'K',100, 'SortIndices', 1, 'Distance', 'chebychev' );
Why you want to take 100 numbers? Make it 5 or 10 ...
Thanks a lot for all your help.
I got it working by determining the minimum and maximum lag of each peak, substracting this of the indices belonging to the peaks of Dataset_Grey. Then by using the Max() function, i found the value and the location of these peaks.
Cheers

Sign in to comment.

Asked:

on 15 Sep 2020

Commented:

on 16 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!