MATLAB: Need to normalize time from ‘find max’ Tidal peaks within a natural cycle

estuarine sciencelunar cycletides

I have continuous (every 15 minutes) water level data from a tidal creek. I am no hydrographer. I am basing this on a method in K. Ellis et al (2017 Journal of South Carolina Water Resources). I am trying to process my tidal creek data to obtain accurate discharge. I deployed an instrument to measure discharge over a week and I have a rating curve that I can only use on HWS-normalized data.
I need to normalize time to high-water slack (HWS), which means detect the (max) high water mark every 9-14 hours (the tidal cycle time varies with wind).
What I was trying to do with Matlab give the initial high-water slack (HWS), because my water level data doesn't start at a peak, and then tell Matlab to find the next HWS 7-14 hours later (samples are every 15 minutes), so starting at 28 and ending at 56 cells after the last HWS index and I don't know how to do a moving window based on moving index of (max).
Ultimately, I need to make a new column of normalized time: time 0 (at high water), +0.25hrs, cum +0.25hr for each time step until the next HW (or 0)
There are 2 high waters and 2 high waters per lunar day- not a 24 hour cycle. Also of note… My average tidal cycle was 12.375 hrs… so 50 measurements
Sometimes the cycles are hard to detect, if there is a strong wind blowing the water out or keeping the water in. So I go with the 12.5 hour cycle as the default there.

Best Answer

You can use findpeaks() to locate the peak of each cycle. One of the outputs to findpeaks() is the peak's index location which can be used to interpolate the time points by 0.25 hr intervals between peaks.