lin2log , log2lin (alias: dB)

From STX Wiki
Jump to navigation Jump to search

Convert the elements of x to logarithmic values (e.g. dB) and vice versa.

lin2log(x {, ref {, fac}})
log2lin(x {, ref {, fac}})
a scalar, vector or matrix
the reference value; must be a positive number (default=1)
the factor; must be a positive number (default=20)
The result r has the same type as x and contains the converted elements of x. The following conversion algorithms are used:
  • lin2log: ri,j = fac * log10(xi,j / ref)
  • log2lin: ri,j = ref * 10 ^ (xi,j / fac)
Note: The function dB is an alias for log2lin and is implemented for compatibility with the expressions used in the NUM and INT command.
See also
log, exp, fft, complex arithmetic (cr2p, cp2r, cr2len)

<function list>


// #spe is a vector containing a complex spectrum
#aref := set '20e-6' // reference value: 20 micro Pascal
#logamp := eval lin2log(cr2len($#spe), $#aref) // the log. amplitude spectrum in dB

// apply 6dB attenuation to the signal stored in the vector #sig
$#sig := eval $#sig * db(6)