RunMat
GitHub

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

NameTypeRequiredDefaultDescription
yAnyYesInput signal magnitude or power quantity.
modeOrRAnyNo"voltage"Mode string ('voltage' or 'power') or resistance reference.

Returns

NameTypeDescription
yDbNumericArrayDecibel-converted output.

Errors

IdentifierWhenMessage
RunMat:db:InvalidArgumentInputs do not match supported db invocation forms.db: invalid argument
RunMat:db:InvalidModeMode string is not recognized or is not a scalar text value.db: invalid mode
RunMat:db:InvalidInputInput signal cannot be interpreted as numeric magnitude data.db: invalid input

How db works

  • db(X) and db(X, 'voltage') compute voltage-style decibels with 20*log10(abs(X)).
  • db(X, 'power') computes power-style decibels with 10*log10(abs(X)).
  • db(X, R) computes power through a finite positive resistance with 10*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 X and R.
  • 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 = 20

Power-style decibel conversion

p = db(100, 'power')

Expected output:

p = 20

Voltage across a reference resistance

p = db(10, 50)

Expected output:

p = 3.0103

Complex magnitude conversion

z = db(3 + 4i)

Expected output:

z = 13.9794

Using 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how db is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.