Finding Linearity
11 次查看(过去 30 天)
显示 更早的评论
Hi everyone ,
In the attached image you can see a curve initially a linear response at some point it is becoming nonlinear . Is there any simple procedure to find out that point at which it behavior become nonlinear ??
Regards
0 个评论
回答(3 个)
Grzegorz Knor
2011-9-19
My idea is as follows: fit line to x & y data, next fit to x(1:end-1) & y(1:end-1), next x(1:end-2) & etc. Then check to which point the data behave in linear way.
For example:
% generate example data
x = linspace(0,1,100);
y = smooth(interp1([0 .4 1],[0 .9 1],x),20);
x = x(:);
y = y(:);
plot(x,y)
% fit coefficients
hold on
nrm = zeros(length(x)-1,1);
coef = zeros(length(x)-1,2);
for k = length(x):-1:2
coef(k-1,:) = ([x(1:k) ones(k,1)]\y(1:k))';
nrm(k-1) = norm(x(1:k)*coef(k-1,1)+coef(k-1,2)-y(1:k));
end
% plot nrm vector
figure
plot(nrm)
% define critical value
crit = 5e-2;
% find the value that satisfies the given condition
idx = find(nrm<crit,1,'last');
% plot result
figure(1)
plot(x(1:idx),x(1:idx)*coef(idx,1)+coef(idx,2),'r')
bym
2011-9-19
perhaps a simple check of the derivative
find(abs(diff(y)) > tol) % where tol is a suitable tolerance
[edit]
maybe this will give you some ideas to build upon:
im = imread('http://img801.imageshack.us/img801/9980/unbenanntuhu.png');
imshow(im)
gimg = rgb2gray(im); % convert to gray
bw = gimg<50; % convert to BW
figure
bwt = bwmorph(bw,'thin','Inf'); % thin pixels to line
imshow(~bwt)
[r,c] = find(bwt);
figure
ddc = diff(diff(r)); %2nd derivative suggests 5 is a threshold
plot(ddc)
3 个评论
bym
2011-9-20
well, since you didn't provide any scaling it is difficult to say. Do you have the data points that generated this curve? Or, are you asking how to determine non-linearity from the image itself?
bym
2011-9-23
Here is one way of accomplishing your goal (with the caveat that I have not tested this on different curves. I used Jiro's FEX submission to convert your image into data points called Data001
plot(Data001(:,1),Data001(:,2))
hold
d = diff(Data001(:,2));
rd = flipud(d);
r = find(d-rd==0); % this line will need tweaking
plot(Data001(r+1,1),Data001(r+1,2),'ro')
I am sure this is not very robust to a great variety of curves, but might serve your purposes
Data001 =
1.2538 1.4481
1.2594 1.4528
1.2675 1.4609
1.2762 1.4704
1.2805 1.4744
1.2886 1.4832
1.2999 1.4967
1.3117 1.5096
1.3179 1.5177
1.3279 1.5292
1.3385 1.5420
1.3479 1.5528
1.3585 1.5636
1.3684 1.5737
1.3790 1.5832
1.3871 1.5899
1.3977 1.5987
1.4132 1.6081
1.4263 1.6149
1.4412 1.6209
1.4536 1.6242
1.4660 1.6269
1.4796 1.6282
1.4932 1.6295
1.5044 1.6302
1.5211 1.6315
1.5335 1.6314
1.5490 1.6327
1.5638 1.6327
1.5756 1.6333
1.5892 1.6339
1.5991 1.6339
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!