How to detect the fluctuating point (cut-off point) of a signal?
Show older comments
Dear all,
I have a simple signal that I show below with blue color:

I want to find the point Xc. Any idea how find this point? Is it the same point which I will get from the first derivative of the signal?
Thank you very much.
Meshoo
Accepted Answer
More Answers (2)
Image Analyst
on 21 Dec 2014
Try this code. It will produce the image that follows it.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 25;
% Make up some demo equation.
x = 1 : 500;
y = sqrt(x);
% Plot it.
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
title('Y = Sqrt(X)', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Extract left and right segments of the curve.
numPoints = 15; % Whatever.
x1 = x(1:numPoints);
y1 = y(1:numPoints);
x2 = x(end-numPoints : end);
y2 = y(end-numPoints : end);
% Draw a green line going down from there.
line([x1(end), x1(end)], [0, y1(end)], 'Color', [0, .5, 0], 'LineWidth', 2);
line([x2(1), x2(1)], [0, y2(1)], 'Color', [0, .5, 0], 'LineWidth', 2);
% Find the equations of the line for each segment.
leftCoefficients = polyfit(x1,y1,1)
rightCoefficients = polyfit(x2,y2,1)
% Plot the lines in red.
yl = ylim(); % Save original y axis range.
hold on;
yLeft = polyval(leftCoefficients, x);
plot(x, yLeft, 'r-', 'LineWidth', 2);
yRight = polyval(rightCoefficients, x);
plot(x, yRight, 'r-', 'LineWidth', 2);
ylim(yl);
% Then set the two equations to each other and solve for xc:
xc = (rightCoefficients (2) - leftCoefficients (2)) / (leftCoefficients(1) - rightCoefficients(1))
yc = leftCoefficients(1) * xc + leftCoefficients(2);
% Draw a green line going down from there.
line([xc, xc], [0, yc], 'Color', [0, .5, 0], 'LineWidth', 3);
plot(xc, yc, 'o', 'MarkerSize', 25, 'Color', [0, .5, 0], 'LineWidth', 3);
% Put up text
message = sprintf('(xc, yc) = (%.1f, %.1f)', xc, yc);
text(1.1*xc, 0.5*yc, message, 'Color', [0, .5, 0], 'FontSize', fontSize);

2 Comments
Meshooo
on 22 Dec 2014
I used the piecewise regression on your example dataset, IA, with initial guesses for the two slopes as
>> m1=Y(npts)/X(npts);
>> m2=(Y(end)-Y(end-npts+1))/(X(end)-X(end-npts+1));
>> b1=0;
>> c=X(end)/10;
>> coeff=nlinfit(X,Y,@piecewise,[b1 m1 c m2])
coeff =
1.1459 0.1940 58.0548 0.0225
The yc value is then
>> xc=coeff(3); yc=xc*coeff(2)+coeff(1)
yc =
12.4087
>>
Image Analyst
on 20 Dec 2014
Take the first and last 10% or so of the points and fit a line.
numPoints = 10; % Whatever.
x1 = x(1:numPoints);
y1 = y(1:numPoints);
x2 = x(end-numPoints : end);
y2 = y(end-numPoints : end);
leftCoefficients = polyfit(x1,y1,1);
rightCoefficients = polyfit(x2,y2,1);
Then set the two equations to each other and solve for xc:
xc = (rightCoefficients (2) - leftCoefficients (2)) / (leftCoefficients(1) - rightCoefficients(1));
3 Comments
Meshooo
on 21 Dec 2014
Image Analyst
on 21 Dec 2014
All right, I made it easy for you. See the code below in my other answer. Vote for my answer if it's useful to you.
Meshooo
on 6 Jan 2015
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

