Programmer Guide/Command Reference/EVAL/log2lin: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(7 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:lin2log, log2lin}}
{{DISPLAYTITLE:lin2log , log2lin (alias: dB)}}
Convert the elements of ''x'' to logarithmic values (e.g. dB) and vice versa.
Convert the elements of ''x'' to logarithmic values (e.g. dB) and vice versa.
;Usage: '''<code>lin2log(<var>x</var> {, <var>ref</var> {, <var>fac</var>}})</code>
;Usage: <code>lin2log(<var>x</var> {, <var>ref</var> {, <var>fac</var>}})</code>
:'''<code>log2lin(<var>x</var> {, <var>ref</var> {, <var>fac</var>}})</code>
:<code>log2lin(<var>x</var> {, <var>ref</var> {, <var>fac</var>}})</code>
:;<var>x</var>: a scalar, vector or matrix
:;<var>x</var>: a scalar, vector or matrix
:;<var>ref</var>: the reference value; must be a positive number (default=1)
:;<var>ref</var>: the reference value; must be a positive number (default=1)
:;<var>fac</var>: the factor; must be a positive number (default=20)
:;<var>fac</var>: the factor; must be a positive number (default=20)
;Result: The result ''r'' has the same type as ''x'' and contains the converted elements of ''x''.
;Result: The result ''r'' has the same type as ''x'' and contains the converted elements of ''x''. The following conversion algorithms are used:
::*lin2log: ''r''<sub>i,j</sub> = ''fac'' * log<sub>10</sub>(''x''<sub>i,j</sub> / ''ref'')
::*'''lin2log''': ''r''<sub>i,j</sub> = ''fac'' * log<sub>10</sub>(''x''<sub>i,j</sub> / ''ref'')
::*log2lin: ''r''<sub>i,j</sub> = ''ref'' * 10 ^ (''x''<sub>i,j</sub> / ''fac'')
::*'''log2lin''': ''r''<sub>i,j</sub> = ''ref'' * 10 ^ (''x''<sub>i,j</sub> / ''fac'')
:Note: The function '''dB''' is an alias for '''log2lin''' and is implemented for compatibility with the expressions used in the [[Programmer_Guide/Command_Reference/NUM|NUM]] and [[Programmer_Guide/Command_Reference/INT|INT]] command.
 
;See also: [[../log|log]], [[../exp|exp]], [[../fft|fft]], [[../complex arithmetic|complex arithmetic (cr2p, cp2r, cr2len)]]
 
[[../#Functions|<function list>]]
 


;See also: [[Programmer_Guide/Command_Reference/EVAL/npow2|log]], [[Programmer_Guide/Command_Reference/EVAL/exp|exp]]
[[Programmer_Guide/Command_Reference/EVAL/fft|fft]], [[Programmer_Guide/Command_Reference/EVAL/cr2len|cr2len]],
Example:
Example:
<pre>
<pre>
Line 17: Line 21:
#aref := set '20e-6' // reference value: 20 micro Pascal
#aref := set '20e-6' // reference value: 20 micro Pascal
#logamp := eval lin2log(cr2len($#spe), $#aref) // the log. amplitude spectrum in dB
#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)
</pre>
</pre>
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]

Latest revision as of 12:16, 21 April 2011

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

Usage
lin2log(x {, ref {, fac}})
log2lin(x {, ref {, fac}})
x
a scalar, vector or matrix
ref
the reference value; must be a positive number (default=1)
fac
the factor; must be a positive number (default=20)
Result
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>


Example:

// #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)

Navigation menu

Personal tools