Why does a
is not the same as b
in matlab
??
a = signal;
b = exp(log(signal));
if I plot a and b, the signal is not the same, any help?
The logarithm of a negative number, -x
, is y = log(x)+pi*1i
. Thus when you apply the exponential function to y
you will be left with a zero imaginary part (or something that looks like zero). Try this for example:
format long
x = -1;
y = exp(log(x))
abserr = abs(x-y)
Read more about the complex logarithm here.
There can also be inaccuracy due to floating point of course. The absolute error can be especially significant if your signal
has values anywhere near to 1/eps
(or -1/eps
). Try
x = 1/eps;
y = exp(log(x));
abserr = abs(y-x)
relerr = abs(y-x)/abs(x)
which returns
abserr =
11.500000000000000
relerr =
2.553512956637860e-15
Note that the relative error is tiny. In floating point calculations relative error is generally what we wish to control.