nashynash
nashynash

Reputation: 375

How to measure the period between the peaks or lows of waves?

I want to measure the period between the peaks/lows of the adjacent waves shown in the figure.

enter image description here

This is an oscillatory behavior of calcium concentration in a cell. The peaks are not the same, hence I would need to calculate the peak/lows for each wave, obtain the corresponding time associated with the peaks/lows, and find the difference between adjacent peaks/lows. I have stored the calcium concentration values for every time "0.01".

Can anyone suggest me how I should code it? I would prefer to use smaller lines of code.

Upvotes: 1

Views: 1050

Answers (1)

JimR
JimR

Reputation: 2225

Look into the inbuilt findpeaks function that can return you the index of peaks in your signal.

You could use this to also find the lows in your signal by first squaring your signal. Something like this could work (I haven't tried this in MATLAB so there could possibly be some syntax issues):

% Square the signal so that the lows become peaks
signal = signal .^ 2;

% Get the location of the peaks in terms of t (your time vector)
[~, peaksAndLows] = findpeaks(signal,t)

% Find the difference between consecutive peaks/lows
periodsBetweenPeaksAndLows = diff(peaksAndLows);

Upvotes: 1

Related Questions