How to get a window of signal data before and after its peak?

Illustration
Sophia - 2021-01-09T09:38:20+00:00
Question: How to get a window of signal data before and after its peak?

I have a 2 column array. It represents an exponential rise/fall of voltage and the time for each datapoint. In the voltage, I want to locate the data in a window between the first time the voltage exceeds 0.2*Vpeak up to when it falls below 0.4*Vpeak. The values before and after the window are then to be replaced with zeros.

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

First, you can use the "findpeaks" function to find all the local peaks in your data:
 
 
>> [pks, locs] = findpeaks(voltage);

Then, from all the peaks, determine the global peak:

>> [vPeak, iPeak] = max(pks);
>> locPeak = locs(iPeak);

Finally, use the "find" function to find the indices of when your  signal reaches 0.2*Vpeak and drops to 0.4*Vpeak of its peak:

>> idx_start = find(voltage(1:locPeak) < 0.2*vPeak, 1, 'last');
>> idx_end = locPeak + find(voltage(locPeak:end) < 0.4*vPeak, 1, 'first');


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!