How to split data points into new numeric matrixs based on peaks

10 vues (au cours des 30 derniers jours)
Aaron Holiday
Aaron Holiday le 12 Juin 2018
I am trying to analysis finish dimension data of a machined part and create a control chart. However, the data is impacted by tool wear and must be analysed using linear regression. To do this I have to split data points between tool changes which can be seen in the data (based on troughs and peaks). See image of scatter plot below.
Obviously it would be time consuming to split the data in excel manually for 4 data sets each with 8000 points. I am hoping to code a way to identify the change between tool changes and place that data segment into a new numeric matrix and test for regression. For example dimensions will climb from 11.955 to 12 at which will drop back down to 11.949 after a tool change.
I know of the
findpeak(data)
But not sure how to split the data and place it into a new matrix.
How can I achieve this in MATLAB?
  2 commentaires
Mark Saad
Mark Saad le 13 Juin 2018
Modifié(e) : Mark Saad le 13 Juin 2018
If your goal is to make a separate matrix of data after every peak, you could try to first get the number of peaks:
[pks, locs] = findpeaks(data);
numpeaks = length(pks);
Then make an array for each peak:
start_point = 1;
for i = 1:numpeaks
end_point = locs(i);
for j = start_point:end_point
split_data = data(start_point:end_point, :);
end
start_point = end_point + 1;
end
start_point and end_point set the range of data that you want to collect, so initially, start_point begins at the first point and data is collected until the first peak, which is end point. Then in the second iteration, start_point is now the point after the first peak, and end_point is now at the second peak, and so on.
This makes a new array through each iteration, so you could just make a larger variable before the loops to store all of the split data arrays.
Aaron Holiday
Aaron Holiday le 14 Juin 2018
The find peaks is too sensitive, It returns too many results. I'll need a way to test for a extreme change in y values, signifies tool changes. For example, a drop from 12.10 to 11.50. Any ideas on how to do this?

Connectez-vous pour commenter.

Réponses (2)

Guillaume
Guillaume le 13 Juin 2018
You may need to tweak the options of findpeaks for you data (and finding the minimums by inverting your data may be more reliable), but once you've got the location of the peaks it trivial to split your vector into subvectors stored in a cell array:
[~, locs] = findpeaks(data); %maybe findpeaks(-data), or maybe use options
splitdata = mat2cell(data, 1, diff([1, locs, numel(data)+1])); %assumes data is a row vector
  5 commentaires
Guillaume
Guillaume le 15 Juin 2018
locs is a column vector. Hence you need to use semicolons for concatenation:
splitdata = mat2cell(LatheB_BPTO, 1, diff([1; locs; numel(LatheB_BPTO)+1]));
If data is also a column vector:
splitdata = mat2cell(LatheB_BPTO, diff([1; locs; numel(LatheB_BPTO)+1]), 1);
Aaron Holiday
Aaron Holiday le 15 Juin 2018
Modifié(e) : Aaron Holiday le 15 Juin 2018
Ok, Im not sure about this. However, I have a column vector that list the start and end points of each segment. I got this using the find function on the gradient results. All i really need is to either look at a certain range of indices to perform a mathematical function on or create new column vectors for each range.
For example, the first tool change in the LatheB_BPTO data is between index 88-246, the next is 247-359. etc... I need to perform a regression analysis on each of these. that is the end goal.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 15 Juin 2018
blocks = mat2cell(data, 1, diff(find([true,diff(data)<0,true])));

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by