db — Convert numeric values to decibels in MATLAB and RunMat.
Y = db(X) converts magnitudes to decibels using voltage form 20*log10(abs(X)). db(X, 'power') uses power form 10*log10(abs(X)), and db(X, R) applies resistance-based voltage conversion under MATLAB semantics.
Syntax
yDb = db(y)
yDb = db(y, "voltage")
yDb = db(y, "power")
yDb = db(y, R)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
y | Any | Yes | — | Input signal magnitude or power quantity. |
modeOrR | Any | No | "voltage" | Mode string ('voltage' or 'power') or resistance reference. |
Returns
| Name | Type | Description |
|---|---|---|
yDb | NumericArray | Decibel-converted output. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:db:InvalidArgument | Inputs do not match supported db invocation forms. | db: invalid argument |
RunMat:db:InvalidMode | Mode string is not recognized or is not a scalar text value. | db: invalid mode |
RunMat:db:InvalidInput | Input signal cannot be interpreted as numeric magnitude data. | db: invalid input |
RunMat:db:InvalidResistance | Resistance reference is non-numeric, complex, non-finite, or non-positive. | db: invalid resistance |
RunMat:db:SizeMismatch | Signal and resistance inputs are not broadcast compatible. | db: array sizes are not compatible for broadcasting |
RunMat:db:Internal | Internal tensor conversion or allocation failed. | db: internal error |
How db works
db(X)anddb(X, 'voltage')compute voltage-style decibels with20*log10(abs(X)).db(X, 'power')computes power-style decibels with10*log10(abs(X)).db(X, R)computes power through a finite positive resistance with10*log10(abs(X).^2 ./ R).- Complex inputs are converted through their magnitude before applying the decibel formula.
- The resistance form supports MATLAB implicit expansion between
XandR. - Zero input returns
-Inf, matching the logarithm singularity at zero. - Integer and logical inputs are promoted to double precision.
Examples
Voltage-style decibel conversion
y = db(10)Expected output:
y = 20Power-style decibel conversion
p = db(100, 'power')Expected output:
p = 20Voltage across a reference resistance
p = db(10, 50)Expected output:
p = 3.0103Complex magnitude conversion
z = db(3 + 4i)Expected output:
z = 13.9794Using db with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how db changes the result.
Run a small db example, explain the result, then change one input and compare the output.
FAQ
What is the default mode?⌄
The default is voltage mode, equivalent to db(X, 'voltage').
How does db handle complex values?⌄
RunMat first computes abs(X) and then applies the selected decibel formula, so complex outputs are not produced.
What happens for zero input?⌄
db(0) returns -Inf because log10(0) is negative infinity.
Can resistance be an array?⌄
Yes. The resistance form broadcasts X and R using MATLAB implicit expansion. Resistance values must be finite and positive.
Related Control functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how db is executed, line by line, in Rust.
- View the source for db in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.