Main Content

db

Convert energy or power measurements to decibels

Description

dbOutput = db(x) converts the elements of x to decibels (dB). This syntax assumes that x contains voltage measurements across a resistance of 1 Ω.

dbOutput = db(x,signalType) specifies the signal type represented by the elements of x as either "voltage" or "power".

dbOutput = db(x,R) specifies the resistance, R, for voltage measurements.

example

dbOutput = db(x,"voltage",R) is equivalent to db(x,R).

Examples

collapse all

Express a unit voltage in decibels. Assume that the resistance is 2 ohms. Compare the answer to the definition, 10log1012.

V = 1;
R = 2;
dboutput = db(V,2);
compvoltage = [dboutput 10*log10(1/2)]
compvoltage = 1×2

   -3.0103   -3.0103

Convert a vector of power measurements to decibels. Compare the answer to the result of using the definition.

rng default
X = abs(rand(10,1));
dboutput = db(X,'power');
comppower = [dboutput 10*log10(X)]
comppower = 10×2

   -0.8899   -0.8899
   -0.4297   -0.4297
   -8.9624   -8.9624
   -0.3935   -0.3935
   -1.9904   -1.9904
  -10.1082  -10.1082
   -5.5518   -5.5518
   -2.6211   -2.6211
   -0.1886   -0.1886
   -0.1552   -0.1552

Since R2026a

Calculate the power of four voltage measurements at three different resistive loads. Display the powers in decibels.

V = [3.7 7.4 18.5 37]';
R = [10 50 75];

PdB = db(V,R);
PdbTable = array2table(PdB);
PdbTable.Properties.RowNames(1:numel(V)) = ("V = "+ V + " V");
PdbTable.Properties.VariableNames(1:numel(R)) = ("R = "+ R + " Ω")
PdbTable=4×3 table
                  R = 10 Ω    R = 50 Ω    R = 75 Ω
                  _________________________    _________________________    _________________________

    V = 3.7 V               1.364                       -5.6257                      -7.3866         
    V = 7.4 V              7.3846                       0.39493                       -1.366         
    V = 18.5 V             15.343                        8.3537                       6.5928         
    V = 37 V               21.364                        14.374                       12.613         

Input Arguments

collapse all

Signal measurements, specified as a scalar, vector, matrix, or N-D array.

Data Types: single | double
Complex Number Support: Yes

Type of signal measurements, specified as either "voltage" or "power". If you specify signalType as "power", then all elements of x must be nonnegative.

Resistive load, specified as a positive scalar, vector, matrix, or N-D array.

  • All the elements in R must be positive and expressed in ohms.

  • If you specify R as a vector, matrix, or N-D array, its size must be compatible with the size of x. For more information, see Compatible Array Sizes for Basic Operations.

  • The db function ignores this argument if you specify signalType as "power".

Data Types: single | double

Output Arguments

collapse all

Energy or power measurements in decibels, returned as an array with the same dimensions as x.

  • If x contains voltage measurements, then dbOutput is 10log10(|x|2/R).

  • If the input x contains power measurements, then dbOutput is 10log10x.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2011b

expand all

See Also

| | |