How can I estimate the delay between peaks above a threshold value in two datasets ?

I have two datasets (water level and wave height) with a recording time of 20 years with an 1-hour temporal resolution. The purpose of my analysis is: To determine if peak water level values coincide with high wave energy events (peak wave height values) or if there is a delay between the two signals. If there is a time-delay I would like to estimate the average value of this.

 Accepted Answer

Use findpeaks to get the peaks of both of them. Since I doubt that over 20 years you will have exactly the same number of peaks in the water level and energy arrays, I suggest you make a scatterplot of the indexes of the water level peaks versus the indexes of the energy plots. Then see if they fall along a line with a slight vertical offset (meaning a time delay between the two sets of peaks). Do that and come back here and insert your scatterplot.

2 Comments

Thanks for the answer.
I found the peaks by pks=findpeaks(data) and got 19990 values for wave heights and 9614 peaks for water level. Since X and Y are not the same length I can't plot the peak data.
Do you have any suggestions to make the peak X and Y vectors the same length? And how do I find the peak above values above a certain threshold value?
Oliver, I think I did give you a good suggestion. But you didn't understand it and did a scatterplot in your answer that was not what I suggested. You do NOT want to do a scatterplot of the energy versus the wave height, or "water level" vs. "significant wave height". Doing that will not tell you of any time delay between the signals.
What you need to do to get the time delay is to basically plot the time of one versus the time of the other. So you need to get the second return argument of findpeaks. We do not care what the wave height or energy was, only when it ocurred. SO get the second return argument which is the index in the array where the peaks occurred, which is proportional to the time.
% Find times of the waves and energy.
[peakHeight1, indexes1] = findpeaks(waveHeight);
[peakHeight2, indexes2] = findpeaks(waveEnergy);
% Now scatter the two time arrays against each other.
% If they happen at exactly the same time, with no delay,
% then the points will lie along a perfectly straight 45 degree line.
% If the Energy is delayed by one hour from the heights,
% then the scattered points will lie along a line that is
% "lifted" along the y axis by the number of indexes
% that correspond to one hour (for example 10 or 20 indexes or whatever).
scatter(indexes1, indexes2);
Now you can plot a line through them and find the intercept, which is the average time lag
% Fit to a straight line.
coefficients = polyfit(indexes1, indexes2, 1);
% Find # of indexes corresponding to the lag.
numLagIndexes = coefficients(2);
slope = coefficients(1);
For example, if a peak for energy happens at index 40 and the peak for the height happens at 37, then there is a 3 index lag between them. You can find the average lag by looking at a line through all the points and seeing how much it's "lifted". Now numLagIndexes is in indexes, not real world time units such as minutes, hours, or days. So you need to multiply numLagIndexes by the time increment per index. For example if the numLagIndexes = 4.6 and each reading is separated in time by 50 minutes, then the time would be 4.6 * 50 = 230 minutes.
OK, what if the slope is not 1? Let's say that the slope is 1.5. That would mean that the lag increases as the wave height increases. So maybe the lag is 5 units for small wave heights, but 7 units for much larger wave heights. In that case the slope would be greater than 1. So then you'll have a function that describes how to get lag (time delay) as a function of wave height.
By the way, in the newsgroup (which I don't monitor much anymore) there is a tides expert, Tideman from New Zealand, who answers a lot of questions.

Sign in to comment.

More Answers (1)

I sorted my values from highest to lowest and plotted them in a scatter plot. It looks like some of the values correlate and others doesn't.
Best regards Oliver

Community Treasure Hunt

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

Start Hunting!