How to automatically find the function that linearizes another function.
이전 댓글 표시
Hi, I have the problem of finding the function that linearizes another function. I have hardware that measures a voltage, but the analog front end is not linear, so instead of having a linear response, I have a response like this:

What I would like to have instead is something like this, a linear function:

Now, I have many hardware, and each one has a slightly different response from each other, what I would like to do is create a Matlab script that can find the correction function that allows to have a linear response for each hardware.
That is, I would like to create a script that given this curve as input:

find the function that multiplied by that curve gives me a linear response.
Is it possible to do this with Matlab?
채택된 답변
추가 답변 (1개)
John D'Errico
2023년 9월 4일
편집: John D'Errico
2023년 9월 4일
0 개 추천
If, given the function f(x), your problem is simply to find a new function g(x), such that f(x)*g(x) is linear, then it is absolutely trivial.
g(x) = x / f(x)
Ok, as long as f(x) is never zero.
If, by linearization, you mean to find a transformation function g, such that g(f(x)) is linear, that becomes more difficult. As well, finding g(x), such that f(g(x)) is linear. Because in either case, you are effectively asking to find a functional inverse, and that will often be mathematically impossible. We can easily prove that, since we can make f(x) to be a polynomial model of degree 5 or higher. And we can prove a functional inverse does not exist for that general class of problems.
However, you did say the former.
" find the function that multiplied by that curve gives me a linear response."
If you want it to look like a straight line approximation to f(x), then use polyfit, to first find the linear function that approximates f(x), as p1*x+p0. Then your solution will be:
g(x) = (p1*x+p0) / f(x)
Again, the product will be as you desire.
If you want a specific solution, that perhaps deals with f(x) being zero, then you need to provide a little more information. Is f given as a general FUNCTION, or is f given as a list of numbers, thus samples from some unknown function?
댓글 수: 4
Torsten
2023년 9월 4일
I guess OP means to determine "m" to minimize
sum_i (f(x_i)-m*x(i))^2
which is given by
m = x\f
John D'Errico
2023년 9월 4일
편집: John D'Errico
2023년 9월 4일
@Torsten I'm not sure that is clear at all. In fact, I think you are incorrect. I think you have decided you know the question is something other than what was asked, and you want to answer the question as you want it to look.
However, we see this speciifc statement:
"find the function that multiplied by that curve gives me a linear response."
So the goal would be to find g(x), such that f(x)*g(x) is LINEAR. And the answer is as I gave. You can choose any linear polynomial p(x), then g(x) = p(x)/f(x), and the product will be linear. The simple solution is just
g(x) = x/f(x)
but a better one might be to use polyfit, AS I SUGGESTED, to then determine the linear polynomial which best approximates f(x). Something like:
P = polyfit(x,f,1);
Which assumes that x and f are vectors of numbers.
Again, all of this works only if f(x) is never zero, which somewhat complicates things, but it is still repairable.
John D'Errico
2023년 9월 4일
편집: John D'Errico
2023년 9월 4일
You can rewrite the question to be anything you want. But then the question becomes yours, and not what was asked. The question very clearly states:
That is, I would like to create a script that given this curve as input:
...
find the function that multiplied by that curve gives me a linear response.
The answer is exactly as I stated, with only the caveat that if f(x) is ever zero, then you need to get slightly trickier to deal with the point at zero to avoid a divide by zero.
카테고리
도움말 센터 및 File Exchange에서 Linearization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




