22 views (last 30 days)

I have two questions regarding function "findchangepts" (DSP Toolbox):

1. How to effectively create additional output vector "x_hat" from standard output "ipt" of the "findchangepts" function at the same sample grid as input data "x". The "x_hat" vector corresponds to function which is piecewise constant or linear approximation of the input "x" signal with jumps at detected change points "ipt" and is produced only as graphics output by "findchangepts" in case of no output variables (see internal function "cpplot" at "findchangepts.m" source code file).

2. Any idea how to choose the input parameters of the "findchangepts" function to restrict output change points only for jump steps values less than some threshold value?

Greg Dionne
on 23 Nov 2016

#1 Maybe something like:

function y = fitchangepts(x, icp, statistic)

y = nan(size(x));

K = length(icp);

nseg = K+1;

istart = [1; icp(:)];

istop = [icp(:)-1; length(x)];

if strcmp(statistic,'mean') || strcmp(statistic,'std')

for s=1:nseg

ix = (istart(s):istop(s))';

y(ix) = mean(x(ix));

end

elseif strcmp(statistic,'rms')

for s=1:nseg

ix = (istart(s):istop(s))';

y(ix) = rms(x(ix));

end

else % linear

for s=1:nseg

ix = (istart(s):istop(s))';

y(ix) = polyval(polyfit(ix,x(ix),1),ix);

end

end

Test it:

load engineRPM.mat

plot(fitchangepts(x,findchangepts(x,'Statistic','linear','MinThreshold',var(x)/2),'linear'))

Greg Dionne
on 23 Nov 2016

#2 You can get close to this by running FINDCHANGEPTS once with a given threshold, finding all segments that are too long, and re-running on each of these with lower thresholds.

You'll probably want to explain the motivation behind the request though, so the solution works for you.

Greg Dionne
on 28 Nov 2016

Greg Dionne
on 18 Jan 2017

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

Start Hunting!
## 0 Comments

Sign in to comment.