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)Xmay be real or complex numeric data.Ris a finite positive real numeric scalar or array.- The output shape follows
Xfor mode arguments and the broadcasted shape ofXandRfor the resistance form.
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.9794FAQ
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 works, line by line, in Rust.
- View db.rs on GitHub
- Learn how the 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 — 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.