Main Content

pow2db

Convert power to decibels

Description

example

ydb = pow2db(y) expresses in decibels (dB) the power measurements specified in y. The relationship between power and decibels is ydb = 10 log10(y).

Examples

collapse all

Generate 1024 samples of a noisy sinusoid having a normalized frequency of 2π/3 rad/sample. Estimate the power spectrum of the signal using pwelch. Express the estimate in decibels and plot it.

n = 0:1024-1;
x = cos(2*pi*n/3) + randn(size(n));

[pxx,w] = pwelch(x,'power');

dB = pow2db(pxx);

plot(w/pi,dB)
xlabel('\omega / \pi')
ylabel('Power (dB)')

Figure contains an axes object. The axes object contains an object of type line.

Repeat the computation using pwelch without output arguments.

pwelch(x,'power')

Figure contains an axes object. The axes object with title Welch Power Spectrum Estimate contains an object of type line.

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or N-D array. When y is nonscalar, pow2db is an element-wise operation.

Data Types: single | double

Output Arguments

collapse all

Power measurements in decibels, returned as a scalar, vector, matrix, or N-D array of the same size as y.

Extended Capabilities

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

See Also

| | |

Introduced in R2007b