How to determine onset and offset for a continuous data?
    10 views (last 30 days)
  
       Show older comments
    
Hi, I have a set of sinusoidal-like data as in attachment, may I know any functions to locate the onset and offset of peaks in each of the cycles?
I have tried 'ischange' and 'findchangepts', but not able locate the points precisely 

0 Comments
Answers (1)
  Suraj Kumar
 on 1 Apr 2025
        Hi Lim,
To determine the onset and offset of peaks for each cycle in sinusoidal-like continuos data, you can go through the following steps and the attached code snippets with sample data:
1. Ensure your data is loaded into MATLAB workspace.
t = 0:0.01:10;  
data = sin(2*pi*1*t) + 0.1*randn(size(t));  
2. Use the 'findpeaks' function to locate the peaks in your data.You can adjust parameters like 'MinPeakProminence' to ensure you are capturing significant peaks. 
For more information on 'findpeaks' function in MATLAB, please refer to the following documentation :
[peaks, locs] = findpeaks(data, 'MinPeakProminence', 0.5);
3. Then you can define criteria for onset and offset. A common approach is to use a threshold method where you identify points crossing a specific amplitude level before and after each peak.
threshold = 0.5;  
onset_indices = find(data(1:end-1) < threshold & data(2:end) >= threshold);
offset_indices = find(data(1:end-1) >= threshold & data(2:end) < threshold);
4. Plot the data along with identified peaks, onset, and offset points to verify the results visually.
figure;
plot(t, data);
hold on;
plot(t(locs), peaks, 'ro');  
plot(t(onset_indices), data(onset_indices), 'g^');  
plot(t(offset_indices), data(offset_indices), 'kv'); 
xlabel('Time');
ylabel('Amplitude');
title('Sinusoidal Data with Peaks, Onset, and Offset');
legend('Data', 'Peaks', 'Onset', 'Offset');
Hope this works for you!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!