Extract subset of data between specified points

6 views (last 30 days)
Hi, I am working with a velocity time series signal that is generally sinusodial in nature. I am looking to extract the data points between the zero "up-crossings" (where the signal crosses the x-axis on a positive slope) to obtain phase-locked intervals. I was able to extract the coordinates of all of the crossings throughout the signal but now I am looking to extract the data between these coordinates.
Any suggestions for an efficient way to extract and output these sets of data?
Thanks in advance!

Accepted Answer

Image Analyst
Image Analyst on 26 May 2020
I'd use findpeaks() to find the peaks and valleys
[peakValues, indexesOfPeaks] = findpeaks(signal);
[valleyValues, indexesOfValley] = findpeaks(-signal);
valleyValues = -valleyValues;
Then you can extract just the part of the signal that goes from valley to peak
startingPeakIndex = 1;
% Make sure peak starts after valley.
if indexesOfPeaks(1) < indexesOfValley(1)
startingPeakIndex = 2;
end
% Scan signal extracting each uprising segment.
for k = 1 : length(indexesOfValley)
thisSegment{k} = signal(indexesOfValley(k) : indexesOfPeaks(startingPeakIndex + k - 1));
end
You will have to play around with findpeaks() to get the right parameters to pick out just the major peaks and not the small noise peaks. It might help to use sgolayfilt() with a polynomial order of 5 or more to smooth the sinusoid before calling findpeaks().
Attach your data in a .mat file if you need more help.
save('answers.mat', 'signal');
  2 Comments
Brie E.
Brie E. on 26 May 2020
Thank you so much for your response! Working with the code you suggested - does this output the individual segments in a single cell? I'd be looking to generate the output of each segment as a double to then average the velocity values across the columns (to obtain the phase average).
I've uploaded the signal data as well as the script I was using here, in case that helps clarify.
Brie E.
Brie E. on 26 May 2020
Oh okay I actually got it working now. Thanks again! Coming into matlab from the Python world...learning as I go so I appreciate the help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!