Clear Filters
Clear Filters

Estimate different trend lines and its slopes from a set of points

4 views (last 30 days)
Hello, I have evaluate different signals as there is an example in the attached image for one of them. As you can see, three trend lines (l1, l2, l3, ....ln)) can be indentified with theree different slopes (m1, m2, m3, ... mn) for this example as there could be more. Is there an automatic command where you can identified these lines (it could me more than 3) and their respectives slopes (it could be more than 3) for each of them to identify a suddenly kink in the slopes like m2 in the example compared to m1 and m3. I attached an example of the data for one of the plots as txt file to obtain this trend lines. I would appreciate your help.
Kind regards

Accepted Answer

Matt J
Matt J on 16 Dec 2023
Edited: Matt J on 16 Dec 2023
This FEX download,
can be used to fit first order splines to the data, including estimation of the knot positions. However, you have to know in advance how many kinks the curve is to have.

More Answers (1)

Image Analyst
Image Analyst on 16 Dec 2023
help findchangepts
FINDCHANGEPTS finds abrupt changes in a signal IPOINT = FINDCHANGEPTS(X) returns the index in X that corresponds to the most significant change in mean. If X is a vector with N elements, FINDCHANGEPTS partitions X into two regions, X(1:IPOINT-1) and X(IPOINT:N), that minimize the sum of the residual (squared) error of each region from its local mean. If X is an M-by-N matrix, FINDCHANGEPTS partitions X into two regions, X(1:M,1:IPOINT-1) and X(1:M,IPOINT:N), returning the columnar index that minimizes the sum of the residual error of each region from its local (M-dimensional) mean. IPOINTS = FINDCHANGEPTS(..., 'MaxNumChanges', Kmax) returns the largest number of significant changes, not exceeding Kmax, that minimize the sum of the residual error and an internal fixed penalty for each change. The indices of the changes are returned in IPOINTS. IPOINTS is empty if no significant changes less than or equal to Kmax are detected. If Kmax is empty or unspecified, FINDCHANGEPTS will always return one changepoint. IPOINTS = FINDCHANGEPTS(..., 'Statistic', STAT) specifies the type of change to detect. The default is 'mean': 'mean' detect changes in mean 'rms' detect changes in root-mean-square level 'std' detect changes in standard deviation 'linear' detect changes in mean and slope IPOINTS = FINDCHANGEPTS(..., 'MinDistance', Lmin) specifies the minimum allowable number of samples, Lmin, between changepoints. If unspecified, Lmin will be 1 for changes in mean, and 2 for other changes. IPOINTS = FINDCHANGEPTS(..., 'MinThreshold', BETA) specifies the minimum improvement in total residual error for each changepoint. If specified, FINDCHANGEPTS finds the smallest number of changes that minimizes the sum of the residual error with an additional penalty of BETA for each change. 'MinThreshold' cannot be specified with the 'MaxNumChanges' parameter. [IPOINTS, RESIDUAL] = FINDCHANGEPTS(...) additionally returns the residual error of signal against the modeled changes. FINDCHANGEPTS(...) without output arguments plots the signal and the detected change point(s). % Example 1: % Find the most significant change in mean load('meanshift.mat','x') findchangepts(x) % Example 2: % Find the 12 most significant changes in linear regression of % engine speed. load('engineRPM.mat','x') findchangepts(x,'Statistic','linear','MaxNumChanges',12) % Example 3: % Find the smallest number of changes in linear regression % applying a penalty to each change by the variance of the signal. load('engineRPM.mat','x') findchangepts(x,'Statistic','linear','MinThreshold',var(x)) % Example 4: % Partition a handwriting sample into a small number of segments % that occupy roughly the same position in space. load('cursiveex.mat','data') x = [real(data); imag(data)]; findchangepts(x,'MaxNumChanges',20) % Example 5: % Break a handwriting sample into a small number of segments % that are piecewise linear load('cursiveex.mat','data') x = [real(data); imag(data)]; findchangepts(x,'Statistic','linear','MaxNumChanges',100) % Example 6: % Find the locations where the power changes in the % spectrogram of a of a train whistle load('train.mat','y','Fs') [S,F,T,Pxx] = spectrogram(y,128,120,128,Fs); findchangepts(pow2db(Pxx),'MaxNumChanges',10) See also CUSUM, FINDPEAKS. Documentation for findchangepts doc findchangepts




Community Treasure Hunt

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

Start Hunting!