Decibel log scale
![decibel log scale decibel log scale](https://mynewmicrophone.com/wp-content/uploads/2020/07/mnm_What_Are_Decibels_The_Ultimate_dB_Guide_For_Audio__Sound_large.jpg)
Logarithmic quantities can only be multiplied by pure numbers, linear units, or quantities, but not logarithmic "units" or quantities. Since 0dBm = 1mW, we better have that 0dBm * 2 = 2mW, implying: julia> 0u"dBm" * 2 Multiplying a dimensionful logarithmic quantity by a pure number acts differently than multiplying a gain/attenuation by a pure number. For an attenuation constant of 3dB/m, we better calculate 6dB for a length of 2m. We see that the attenuation in dB is linear in length. Struct Gain$, then the (power) attenuation in dB is $-10kx$. The type of this kind of logarithmic quantity is: Unitful.Gain - Type These can be constructed as, for example, 10*dB, which displays similarly ( 10 dB). Logarithmic quantities with no reference level specified typically represent some amount of gain or attenuation, i.e. Logarithmic quantities with no reference level specified Note that dBFS is defined to represent amplitudes relative to 1 in dB, hence the custom display logic.Īlso, you can of course use functions instead of macros: julia> using Unitful: dB, mWĮRROR: ArgumentError: when passing a final Bool argument, this can only be used with dimensionless numbers. Julia> 10/1 false # is not a root-power ratio is a power ratio You can only do this for dimensionless numbers: julia> 10/1 true # is a root-power (amplitude) ratio By providing an extra Bool argument to these macros, you can explicitly choose whether the resulting ratio should be considered a "root-power" or "power" ratio.
![decibel log scale decibel log scale](https://thumbs.dreamstime.com/z/decibel-scale-chart-vector-illustration-decibel-scale-chart-vector-illustration-measuring-noise-pollution-levels-work-safety-173114173.jpg)
In some cases it may nonetheless be convenient to have a dimensionless reference level. After all, usually it is the ratio that is dimensionless, not the numerator and denominator that make up the ratio. This is because the ratio could be of power quantities or of root-power quantities, leading to ambiguities. The and macros will fail if either a dimensionless number or a ratio of dimensionless numbers is used.
![decibel log scale decibel log scale](https://www.epd.gov.hk/epd/noise_education/web/ENG_EPD_HTML/m1/images/123c.gif)
This is because dB acts more like a constructor than a proper unit. This is done to avoid issues with commutativity and associativity, e.g. Note that logarithmic "units" can only multiply or be multiplied by pure numbers and linear units, not other logarithmic units or quantities. When there is ambiguity about what to do, we fall back to the underlying linear quantities, paying no mind to the reference levels: julia> using Unitful: mW It is important to keep in mind that the reference level is just used to calculate the logarithms, and nothing more. This can be avoided by constructing 0 dBm as 1mW/mW. When we construct 0dBm, the power in mW is calculated and stored, resulting in a lossy floating-point conversion. There is an important difference in these two approaches to constructing logarithmic quantities. In calculating the logarithms, the log function appropriate to the scale in question is used ( log10 for decibels, log for nepers). The scales themselves are callable as functions if you need to construct a level that way (they are not exported): julia> using Unitful: dB, mW, V When using the macros, the levels are constructed at parse time. These macros are exported by default since empirically macros are defined less often than variables and generic functions. One can also construct logarithmic quantities using the macros to use an arbitrary reference level: julia> using Unitful: mW, V
![decibel log scale decibel log scale](https://i.pinimg.com/originals/86/75/e9/8675e9ca26cd3c83e819e5f844e0f429.jpg)
julia> 3u"dB"Ĭurrently implemented are dB, B, dBm, dBV, dBu, dBμV, dBSPL, dBFS, cNp, Np. Left- or right-multiplying a pure number by a logarithmic "unit", whether dimensionful or dimensionless, is short-hand for constructing a logarithmic quantity. In the following discussion, for pedagogical purposes, we will assume prior familiarity with the definitions of dB and dBm. Some compromises have been made in striving for logarithmic quantities to be both usable and consistent. Unitful provides a way to use logarithmically-scaled quantities as of v0.4.0. Logarithmic scales are new to Unitful and should be considered experimental.