Trouble with time lag between peaks

S
Santiago · Mar 3, 2021 · 2K views
Question
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 PhD Expert
Answered Aug 14, 2026

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.

 

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!