RunMat
GitHub

db — Convert numeric values to decibels using MATLAB-compatible voltage, power, or resistance forms.

Y = db(X) converts magnitudes to decibels with 20*log10(abs(X)). db(X, 'power') uses 10*log10(abs(X)), and db(X, R) treats X as voltage across resistance R and returns 10*log10(abs(X).^2 ./ R).

Syntax

Y = db(X)
Y = db(X, 'voltage')
Y = db(X, 'power')
Y = db(X, R)
  • X may be real or complex numeric data.
  • R is a finite positive real numeric scalar or array.
  • The output shape follows X for mode arguments and the broadcasted shape of X and R for the resistance form.

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

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 works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat for free

Write code or describe what you want to compute. The sandbox is free, no account required.