MATLAB Answers

FFT/ 2 blocks which second one is inverse of the first

2 views (last 30 days)
Sepideh Bamdad
Sepideh Bamdad on 30 Jun 2019
Edited: dpb on 3 Jul 2019
We have a polynomial function which results in nonlinear effect. In order to mitigate thr nonlinearity effect we have calculated the inverse of it. Then the main function and the inverse are chained, respectively.
We set the sinusoid input with 1MHz in the input and expect to see the input at the final output but this is not fulfilled at all. We wonder what may be the reason for it.
Note: the main fucntion is achieved with fitting 83 points. The inverse polynomial function is calculated by matlab best fitting feature.
''Main Function''
function f = fcn(v)
b0 = 0.18574;
b1 = -4.0378;
b2 = 37.697;
b3 = -197.21;
f = b0 + b1*v + b2*v.^2 + b3*v.^3;
''Inverse Function''
function v = fcn(f)
a0 = 0.139496297004442;
a1 = 2.221417777176022;
a2 = -5.958217030223240;
a3 = 6.549491033408650;
v = a0 + a1*f + a2*f.^2 + a3*f.^3;


Show 1 older comment
Sepideh Bamdad
Sepideh Bamdad on 1 Jul 2019
@dpb thanks for your reply What do you mean? Do I have to change the name? How?
dpb on 3 Jul 2019
See the link to Function Precedence Order in the doc at the reference page for function
But, yes, you need to have two different functions of different change the name simply by saving the m-file with a new name (and by convention, the function should be named the same as the file altho it is the filename that Matlab actually uses).
It's no different fundamentally than aliasing a builtin function like mean by using the name as a variable--
>> which -all mean
C:\ML_R2017\toolbox\matlab\timefun\@datetime\mean.m % datetime method
C:\ML_R2017\toolbox\matlab\timefun\@duration\mean.m % duration method
C:\ML_R2017\toolbox\matlab\bigdata\@tall\mean.m % tall method
C:\ML_R2017\toolbox\stats\stats\@ProbDistUnivParam\mean.m % ProbDistUnivParam method
C:\ML_R2017\toolbox\matlab\timeseries\@timeseries\mean.m % timeseries method
>> mean=mean(rand(3,1)); % alias function mean by accident...
>> which -all mean
mean is a variable.
C:\ML_R2017\toolbox\matlab\timefun\@datetime\mean.m % Shadowed datetime method
C:\ML_R2017\toolbox\matlab\timefun\@duration\mean.m % Shadowed duration method
C:\ML_R2017\toolbox\matlab\bigdata\@tall\mean.m % Shadowed tall method
C:\ML_R2017\toolbox\stats\stats\@ProbDistUnivParam\mean.m % Shadowed ProbDistUnivParam method
C:\ML_R2017\toolbox\matlab\timeseries\@timeseries\mean.m % Shadowed timeseries method
C:\ML_R2017\toolbox\matlab\datafun\mean.m % Shadowed
Initially there are a number of functions named mean.m, but they are distinguishable to the interpreter by the class of their inputs so the correct one eventually gets called.
After I aliased (shadowed) mean by making a variable, now all the functions of that name are not going to be available; they're masked by the variable of the same name.
Similarly, when you made the second m-file with the same name as the first but with nothing distinguishing it in class of inputs, then the second (first in the path search order) will be the only one that will be visible so you'll actually be calling it twice.
How is ML supposed to know to call version one once and version two the other time when they look completely identical from the outside? Too much to expect that it somehow knows your intent--you have to specifically write code that matches your intent.
Sepideh Bamdad
Sepideh Bamdad on 3 Jul 2019
Thanks for your kind reply.I got it.
Yours sincerely,

Sign in to comment.

Answers (0)


Translated by