# powermeter

## Description

The `powermeter`

System object™ computes the power measurements of a voltage signal. When you set the
`ComputeCCDF`

property to `true`

, the object also
calculates the complementary cumulative distribution function (CCDF) of the power of a voltage
signal. The CCDF measurements that the object outputs are relative power and probability (in
percentage). The power measurements include average power, peak power, and peak-to-average
power ratio.

For more details on how the object computes the power measurements and the CCDF measurements, see Algorithms.

To measure the power and the CCDF of the power of a voltage signal:

Create the

`powermeter`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

## Creation

### Description

returns a
`meter`

= powermeter`powermeter`

system object that computes power, peak-to-average power
ratio (PAPR), and the complementary cumulative distribution function (CCDF) of the power
of voltage signal. The CCDF helps find the probability that the instantaneous signal power
exceeds a specified level above the average signal power.

sets the `meter`

= powermeter(`Len`

,`Overlap`

,Name=Value)`WindowLength`

property to `Len`

and the `OverlapLength`

property to `Overlap`

.

To enable this syntax, set the `ComputeCCDF`

property to
`false`

.

returns a `meter`

= powermeter(`Name=Value`

)`powermeter`

system object with each specified property set to
the specified value. Enclose each property name in quotes. You can use this syntax with
the previous input argument.

## Properties

Unless otherwise indicated, properties are *nontunable*, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
`release`

function unlocks them.

If a property is *tunable*, you can change its value at
any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

`Measurement`

— Desired power measurement

`'Average power'`

(default) | `'Peak power'`

| `'Peak-to-average power ratio'`

| `'All'`

Desired power measurement, specified as `'Average power'`

,
`'Peak power'`

, `'Peak-to-average power ratio'`

or
`'All'`

.

For more details on how the object computes these measurements, see Algorithms.

`ReferenceLoad`

— Reference load

`1`

(default) | positive scalar

Reference load used by the power meter to compute the power values in ohms, specified as a positive scalar.

**Tunable: **Yes

**Data Types: **`single`

| `double`

`ComputeCCDF`

— Compute CCDF

`false`

(default) | `true`

Specify whether to calculate CCDF as:

`false`

–– The object does not calculate the CCDF measurements. The object computes the power measurements using the Sliding Window Method.`true`

–– The object computes the CCDF measurements.All input samples since object creation or reset are used to compute statistics. The power measurements are stationary.

The

`WindowLength`

and`OverlapLength`

properties become read-only and are set to`Inf`

and 0 respectively.

**Data Types: **`logical`

`PowerRange`

— Power range

`50`

(default) | positive scalar

The *x*-axis range of the computed CCDF curves in dB, specified as
a positive scalar. The computed CCDF curves end at the maximum relative power, namely,
peak-to-average power ratio (PAPR) of the signal, and start at PAPR - `PowerRange`

. For the CCDF capability of the
`powermeter`

object, relative power is the power in dB by which the
instantaneous signal power is above the average signal power.

#### Dependencies

To enable this property, set the `ComputeCCDF`

property to `true`

.

**Data Types: **`single`

| `double`

`PowerResolution`

— Power Resolution in dB

`0.1`

(default) | positive scalar

The *x*-axis resolution of the computed CCDF curves in dB,
specified as a positive scalar.

#### Dependencies

To enable this property, set the `ComputeCCDF`

property to `true`

.

**Data Types: **`single`

| `double`

`WindowLength`

— Window length

`256`

(default) | nonnegative integer

Sliding window length over which the measurement is computed, specified as a nonnegative integer.

#### Dependencies

If the `ComputeCCDF`

property is `true`

, then `WindowLength`

property is set to `Inf`

and
is read-only.

**Data Types: **`single`

| `double`

`OverlapLength`

— Overlap length between windows

`WindowLength`

− 1 (default) | nonnegative integer

Overlap length between sliding windows, specified as a nonnegative integer. The
value of overlap length varies in the range [0, `WindowLength`

− 1]. If not specified, the overlap length is `WindowLength`

− 1.

#### Dependencies

If the `ComputeCCDF`

property is `true`

, then `OverlapLength`

property is set to 0 and is read-only.

**Data Types: **`single`

| `double`

`OutputPowerUnits`

— Output power units

`'dBm'`

(default) | `'dBW'`

| `'Watts'`

Units of the measured power values, specified as `'dBm'`

,
`'dBW'`

, or `'Watts'`

.

## Usage

### Description

computes the peak-to-average power ratio of the input signal `papr`

= meter(`x`

)`x`

when
the `Measurement`

property is set to
`'Peak-to-average power ratio'`

. Each column of `x`

is treated as an independent channel. The object computes the peak-to-average power ratio
of each channel of the input signal independently.

`[`

computes the average power, peak power, and the peak-to-average power ratio of the input
signal `avgpwr`

,`peakpwr`

,`papr`

] = meter(`x`

)`x`

when the `Measurement`

property is set to `'All'`

. Each column of `x`

is
treated as an independent channel. The object computes the power measurements of each
channel of the input signal independently.

### Input Arguments

`x`

— Input voltage signal

vector | matrix

Input voltage signal, specified as a vector or a matrix in volts. If
`x`

is a matrix, the object treats each column as an independent
channel and computes the power measurements along each channel.

The object also accepts variable-size inputs. That is, once the object is locked, you can change the size of each input channel, but you cannot change the number of channels.

**Data Types: **`single`

| `double`

**Complex Number Support: **Yes

### Output Arguments

`avgpwr`

— Average power

scalar | vector | matrix

Average power of the voltage signal, returned as a scalar, vector or a matrix,
with the units determined by the `OutputPowerUnits`

property.

If you set the `ComputeCCDF`

property to
`false`

, the object computes the moving average power using the
Sliding Window Method.

When you input a signal of size *m*-by-*n* to
the object when the `ComputeCCDF`

property is set to
`false`

, the output has an upper bound size of
`ceil`

(*m*/hop size)-by-*n*.
Hop size is window length − overlap length. In other cases, the output has a size of
*m*-by-*n*.

When you generate code from this object, the variable-size behavior of the output in the generated code depends on the input frame length and whether the size of the input signal is fixed or variable. For more details, see Code Generation.

If you set the `ComputeCCDF`

property to
`true`

, the object computes the stationary average power of the
entire signal along each channel. In this case, the size of the output is
1-by-*M*, where *M* is the number of channels in
the input signal.

For details on how the object computes the average power, see Average Power.

**Data Types: **`single`

| `double`

`peakpwr`

— Peak power

scalar | vector | matrix

Peak power of the voltage signal, returned as a scalar, vector or a matrix, with
the units determined by the `OutputPowerUnits`

property.

If you set the `ComputeCCDF`

property to
`false`

, the object computes the moving peak power using the Sliding Window Method.

When you input a signal of size *m*-by-*n* to
the object when the `ComputeCCDF`

property is set to
`false`

, the output has an upper bound size of
`ceil`

(*m*/hop size)-by-*n*.
Hop size is window length − overlap length. In other cases, the output has a size of
*m*-by-*n*.

When you generate code from this object, the variable-size behavior of the output in the generated code depends on the input frame length and whether the size of the input signal is fixed or variable. For more details, see Code Generation.

If you set the `ComputeCCDF`

property to
`true`

, the object computes the stationary peak power of the entire
signal along each channel. In this case, the size of the output is
1-by-*M*, where *M* is the number of channels in
the input signal.

For details on how the object computes the peak power, see Peak Power.

**Data Types: **`single`

| `double`

`papr`

— Peak-to-average power ratio

scalar | vector | matrix

Peak-to-average power ratio of the voltage signal, returned as a scalar, vector or a matrix.

If you set the `ComputeCCDF`

property to
`false`

, the object computes the moving peak-to-average power ratio
using the Sliding Window Method.

When you input a signal of size *m*-by-*n* to
the object when the `ComputeCCDF`

property is set to
`false`

, the output has an upper bound size of
`ceil`

(*m*/hop size)-by-*n*.
Hop size is window length − overlap length. In other cases, the output has a size of
*m*-by-*n*.

When you generate code from this object, the variable-size behavior of the output in the generated code depends on the input frame length and whether the size of the input signal is fixed or variable. For more details, see Code Generation.

If you set the `ComputeCCDF`

property to
`true`

, the object computes the stationary peak-to-average power
ratio of the entire signal along each channel. In this case, the size of the output is
1-by-*M*, where *M* is the number of channels in
the input signal.

For details on how the object computes the peak-to-average power ratio, see Peak-to-Average Power Ratio.

**Data Types: **`single`

| `double`

## Object Functions

To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named `obj`

, use
this syntax:

release(obj)

### Specific to powermeter

`plotCCDF` | Plot CCDF curves |

`ccdf` | Get coordinates of CCDF curves |

`relativePower` | Use CCDF to find relative power for specified probability |

`probability` | Use CCDF to find probability for specified relative power |

## Examples

### Compute Power Measurements of Voltage Signal

Compute the power measurements of a noisy sinusoidal signal using a power meter. These measurements include average power, peak power, and peak-to-average power ratio.

Assume the maximum voltage of the signal to be 100 V. The instantaneous values of a sinusoidal waveform are given by the equation $\mathrm{Vi}=\mathrm{Vmax}\times \mathrm{sin}\left(2\pi \mathrm{ft}\right)$, where$$Vi$$ is the instantaneous value, $$Vmax$$ is the maximum voltage of the signal, and $\mathit{f}$ is the frequency of the signal in Hz.

**Initialization**

The input signal is a sum of two sine waves with frequencies set to 1 kHz and 10 kHz, respectively. The frame length and the sampling frequency of the generated signal is 512 samples and 44.1 kHz, respectively.

To measure the power in this signal, create a `powermeter`

object. Set `Measurement`

to `'All'`

. This setting enables the object to measure the average power, peak power, and peak-to-average power ratio. Set the length of the sliding window to 16 samples and the reference load to 50 `Ohms`

. Use this object to measure the power in `dBm`

units. Visualize the power measurements using the `timescope`

object.

FrameLength = 512; Fs = 44.1e3; A = 100; sine1 = dsp.SineWave(Amplitude=A, ... Frequency=1e3, ... SampleRate=44.1e3, ... SamplesPerFrame=FrameLength); sine2 = dsp.SineWave(Amplitude=A, ... Frequency=10e3, ... SampleRate=44.1e3, ... SamplesPerFrame=FrameLength); pm = powermeter(16,Measurement="All", ... ReferenceLoad=50, ... OutputPowerUnits="dBm"); scope = timescope(NumInputPorts=4,SampleRate=Fs, ... TimeSpanSource="property", ... TimeSpan=96, ... YLabel="dBm", ... YLimits=[-30 90]); title = 'Power Measurements'; scope.ChannelNames = {'Average power', ... 'Peak power','Peak-to-average power ratio', ... 'Expected Average Power'}; scope.Title = title;

**Compute the Power Measurements**

Add zero-mean white Gaussian noise with a standard deviation of 0.001 to the sum of sine waves. Vary the amplitude of the sine waves. Measure the average power, peak power, and the peak-to-average power ratio of this noisy sinusoidal signal that has a varying amplitude. For details on how the object measures these power values, see Algorithms. Compare the measured values to the expected value of the average power.

The expected value of the average power $\mathit{P}$ of the noisy sinusoidal signal is given by the following equation.

$$\mathit{P}=\frac{{\mathit{A}}_{1}^{2}}{2\mathit{R}}+\frac{{\mathit{A}}_{2}^{2}}{2\mathit{R}}+\mathrm{var}\left(\mathrm{noise}\right),$$

where,

${\mathit{A}}_{1}$ is the amplitude of the first sinusoidal signal.

${\mathit{A}}_{2}$ is the amplitude of the second sinusoidal signal.

$\mathit{R}$ is the reference load in ohms.

In `dBm`

, the expected power is computed using the following equation:

$${\mathrm{expPwr}}_{\mathrm{dBm}}=10{\mathrm{log}}_{10}\left(\mathit{P}\right)+30.$$

Compare the expected value with the value computed by the object. All values are in `dBm`

. These values match very closely. To verify, view the computed measurements using the `timescope`

object.

Vect = [1/8 1/2 1 2 1 1/2 1/8 1/16 1/32]; for index = 1:length(Vect) V = Vect(index); for i = 1:1000 x = V*sine1()+V*sine2()+0.001.*randn(FrameLength,1); P = (((V*A)^2)/100)+(((V*A)^2)/100)+(0.001)^2; expPwr = (10*log10(P)+30)*ones(FrameLength,1); [avgPwr,pkPwr,papr] = pm(x); scope(avgPwr,pkPwr,papr,expPwr); end end

### Compute and Plot CCDF Measurements of Voltage Signal

Compute the CCDF measurements of a voltage signal. The CCDF measurements include the relative power and the probability. Relative power is the amount of power in dB by which the instantaneous signal power is above the average signal power. Probability in percentage refers to the probability that the instantaneous signal power is above the average signal power by the relative power in dB.

Initialize a `powermeter`

object and set the `ComputeCCDF`

property to `true`

. The input to the object is a random voltage signal.

x = complex(rand(10000,1)-0.5,rand(10000,1)-0.5); pm = powermeter(ComputeCCDF=true)

pm = powermeter with properties: Measurement: 'Average power' ReferenceLoad: 1 ComputeCCDF: true PowerRange: 50 PowerResolution: 0.1000 OutputPowerUnits: 'dBm' Read-only properties: WindowLength: Inf OverlapLength: 0

By default, the `powermeter`

object computes the average power of the signal in dBm. The reference load is 1 ohm.

averagePower = pm(x)

averagePower = 22.2189

Using the `probability`

function, find the probability that the instantaneous power of the signal is 3 dB above the average power. The relative power in this case is 3 dB.

prob = probability(pm,3)

prob = 7.6009

Compute the relative power using the `relativePower`

function. Verify that the relative power for the computed probability is indeed 3 dB.

relpwr = relativePower(pm,prob)

relpwr = 3.0000

Using the `plotCCDF`

function, plot the CCDF curve. Set the reference curve to Gaussian.

plotCCDF(pm,GaussianReference=true)

## Algorithms

### Sliding Window Method

When you do not configure the power meter to compute the CCDF measurements, the power meter computes the moving power measurements using the sliding window method.

In the sliding window method, the block computes the power measurement over a finite duration
of the signal. The window length defines the length of the data over which the algorithm
computes the power value. The window moves as new data comes in. The output for each
input sample is the measurement over the current sample and *Len* – 1 previous samples. *Len* is the
length of the sliding window in samples. To compute the first output sample, the
algorithm waits until it receives the hop size number of input samples. Hop size is
defined as window length – overlap length. Remaining samples in the window are
considered to be zero. As an example, if the window length is 5 and the overlap length
is 2, then the algorithm waits until it receives 3 samples of input to compute the first
sample of the output. After generating the first output, it generates the subsequent
output samples for every hop size number of input samples.

For a more detailed example, see Sliding Window Method.

If the window is large, the power that the block computes is closer to the stationary power of the data. For data that does not change rapidly, use a long window to get a smoother measurement. For data that changes fast, use a smaller window.

When you configure the power meter to compute the CCDF measurements, the algorithm
computes the stationary power of the data. It sets the window length to
`Inf`

and the overlap length to `0`

, making both
the parameters read-only.

### Average Power

When you do not configure the power meter to compute the CCDF measurements, the power meter computes the moving average power of the voltage signal across each channel using the Sliding Window Method. When you do configure the power meter to compute the CCDF measurements, the power meter computes the stationary average power of the voltage signal across each channel.

These equations give the average power in `dBm`

,
`dBW`

, and in `Watts`

units.

$$AvgPowe{r}_{dBm}=10{\mathrm{log}}_{10}\left(Avg\left({\left|x\right|}^{2}\right)/R\right)+30$$

$$AvgPowe{r}_{dBW}=10{\mathrm{log}}_{10}\left(Avg\left({\left|x\right|}^{2}\right)/R\right)$$

$$AvgPowe{r}_{Watts}=Avg\left({\left|x\right|}^{2}\right)/R$$

where,

*x*is the input voltage signal.*R*is the reference load (in ohms) that the block uses to compute the power value.`Avg`

represents the moving average power when the power meter does not compute the CCDF measurements. The`powermeter`

object in MATLAB^{®}uses the`dsp.MovingAverage`

object and the Power Meter block in Simulink^{®}uses the Moving Average block.When the power meter does compute the CCDF measurements,

`Avg`

represents the stationary average power across each channel.

### Peak Power

When you do not configure the power meter to compute the CCDF measurements, the power meter computes the moving peak power of the voltage signal across each channel using the Sliding Window Method. When you do configure the power meter to compute the CCDF measurements, the power meter computes the stationary peak power of the voltage signal across each channel.

These equations give the peak power in `dBm`

, `dBW`

,
and in `Watts`

units.

$$PeakPowe{r}_{dBm}=10{\mathrm{log}}_{10}\left(Max\left({\left|x\right|}^{2}\right)/R\right)+30$$

$$PeakPowe{r}_{dBW}=10{\mathrm{log}}_{10}\left(Max\left({\left|x\right|}^{2}\right)/R\right)$$

$$PeakPowe{r}_{Watts}=Max\left({\left|x\right|}^{2}\right)/R$$

where,

*x*is the input voltage signal.*R*is the reference load (in ohms) that the block uses to compute the power value.`Max`

represents the moving peak power when the power meter does not compute the CCDF measurements. The`powermeter`

object in MATLAB uses the`dsp.MovingMaximum`

object and the Power Meter block in Simulink uses the Moving Maximum block.When the power meter does compute the CCDF measurements,

`Max`

represents the stationary peak power across each channel.

### Peak-to-Average Power Ratio

When you do not configure the power meter to compute the CCDF measurements, the power meter computes the moving peak-to-average power ratio of the voltage signal across each channel using the Sliding Window Method. When you do configure the power meter to compute the CCDF measurements, the power meter computes the stationary peak-to-average power ratio of the voltage signal across each channel.

These equations give the peak-to-average power ratio in `dBm`

,
`dBW`

, and in `Watts`

units.

$$pkAvgPw{r}_{dBm}=10{\mathrm{log}}_{10}\left(Max\left({\left|x\right|}^{2}\right)/Avg\left({\left|x\right|}^{2}\right)\right)$$

$$pkAvgPw{r}_{dBW}=10{\mathrm{log}}_{10}\left(Max\left({\left|x\right|}^{2}\right)/Avg\left({\left|x\right|}^{2}\right)\right)$$

$$pkAvgPw{r}_{Watts}=Max\left({\left|x\right|}^{2}\right)/Avg\left({\left|x\right|}^{2}\right)$$

where,

*x*is the input voltage signal.`Avg`

represents the moving average power when the power meter does not compute the CCDF measurements. The`powermeter`

object in MATLAB uses the`dsp.MovingAverage`

object and the Power Meter block in Simulink uses the Moving Average block.When the power meter does compute the CCDF measurements,

`Avg`

represents the stationary average power across each channel.`Max`

represents the moving peak power when the power meter does not compute the CCDF measurements. The`powermeter`

object in MATLAB uses the`dsp.MovingMaximum`

object and the Power Meter block in Simulink uses the Moving Maximum block.When the power meter does compute the CCDF measurements,

`Max`

represents the stationary peak power across each channel.

### Relative Power

The power meter computes the relative power only when you configure the algorithm to compute the CCDF measurements. The algorithm uses a window of infinite duration to compute the relative power.

Relative power is the amount of power in dB by which the instantaneous signal power is above the average signal power. The block calculates the relative power using these equations:

If output power is in `dBm`

,

$$relPower=10{\mathrm{log}}_{10}\left({\left|x\right|}^{2}/R\right)+30-AvgPowe{r}_{dBm}$$

If output power is in `dBW`

,

$$relPower=10{\mathrm{log}}_{10}\left({\left|x\right|}^{2}/R\right)-AvgPowe{r}_{dBW}$$

If output power is in `Watts`

,

$$relPower=\left({\left|x\right|}^{2}/R\right)-AvgPowe{r}_{Watts}$$

where,

*x*is the input voltage signal.*R*is the reference load (in ohms) that the block uses to compute the power value.*|x|*/^{2}*R*is the instantaneous signal power in Watts.*AvgPower*is the average power of the voltage signal. For more details on how the algorithm computes this measurement, see Average Power.

### Probability

The power meter computes the probability only when you configure the algorithm to compute the CCDF measurements. Probability in percentage refers to the probability that the instantaneous signal power is above the average signal power by the relative power in dB.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

See System Objects in MATLAB Code Generation (MATLAB Coder).

When you set the

`ComputeCCDF`

property to`false`

and generate code from this object, the variable-size behavior of the output depends on the input frame length and whether the size of the input signal is fixed or variable.See this table for more details.

Input Signal Input Size Output Signal Fixed-size *m*-by-*n*When the input frame length is a multiple of the hop size, the output signal has a fixed-size of (

*m*/hop size)-by-*n*.When input frame length is not a multiple of the hop size, the output signal is variable-sized and has an upper bound of

`ceil`

(*m*/hop size)-by-*n*.Variable-size *m*-by-*n*Output is a variable-size signal.

Output has an upper bound size of

`ceil`

(*m*/hop size)-by-*n*.

## Version History

**Introduced in R2021a**

### R2022b: Change in variable-size behavior for output signal in generated code

Starting in R2022b, if you generate code from this object with the
`ComputeCCDF`

property set to `false`

, and if you
input a signal with a frame length that is a multiple of the hop size (window length −
overlap length), this object generates a fixed-size output signal in the generated code. For
more details, see Code Generation.

## See Also

### Functions

`plotCCDF`

|`ccdf`

|`relativePower`

|`probability`

### Objects

### Blocks

### Topics

- Compute Average Power of 256 QAM Signal in MATLAB (Communications Toolbox)

## Comando MATLAB

Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:

Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)