Trouble with time lag between peaks

Illustration
Santiago - 2021-03-03T11:04:50+00:00
Question: Trouble with time lag between peaks

I have two series of data: (time,x) and (time,y) . My intention is to  plot the time lag between the the peaks in x and y . Due to property of the system, the time interval between the successive peaks in X and Y is around 8. I have tried to use the function     [pks1,locs1]=findpeaks(x,'minpeakdistance',8); [pks2,locs2]=findpeaks(y,'minpeakdistance',8); In this way, after finding both peaks I could find the lag. The problem is due to the variation in noise level of both readings, I couldn't find the same number of peaks for both x and y, more to this, I can't maintain the distance 8 and some are way exaggerated. Is there anyway of tackling this problem , it's giving me hard time please help me.  

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

It sounds like you're trying to find and visualize the time lag between the peaks in two datasets. Here’s a step-by-step approach you can follow using MATLAB:

1. Find Peaks in Both Datasets:
   Use the `findpeaks` function to identify the peaks in both series.

   
   [pks_x, locs_x] = findpeaks(x, 'MinPeakDistance', 8);
   [pks_y, locs_y] = findpeaks(y, 'MinPeakDistance', 8);
   

2. Compute Time Lag:
   Calculate the time lags between corresponding peaks in `x` and `y`.

   
   time_lag = locs_y - locs_x;
   

3. Plot the Time Lag:
   Plot the time lag to visualize the differences.   

plot(locs_x, time_lag, 'o-');
   xlabel('Time (s)');
   ylabel('Time Lag (s)');
   title('Time Lag Between Peaks in x and y');

You might need to adjust the `MinPeakDistance` parameter in `findpeaks` according to your data. The example above assumes a distance of 8 based on your description.

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!