Measure the Power of a Signal

The power of a signal is the sum of the absolute squares of its time-domain samples divided by the signal length, or, equivalently, the square of its RMS level. The function bandpower allows you to calculate signal power in one step.

Initially, consider a noisy sinusoid. Verify that the power is the sum of the power of the signal and of the noise.

N = 1200;
Fs = 1000;
t = (0:N-1)/Fs;
w = 124;
A = 2.4;
sigma = 0.13;
s = A*sin(2*pi*w*t)+sigma*randn(size(t));

pTheory = A^2/2+sigma^2
pRMS = rms(s)^2
powbp = bandpower(s,Fs,[0 Fs/2])
pTheory =

    2.8969


pRMS =

    2.8849


powbp =

    2.8775

The power of the sinusoid is in the expected frequency band.

powband = bandpower(s,Fs,[122 126])
powband =

    2.8616

A nonlinear power amplifier is given a 60 Hz sinusoid as input and outputs a noisy signal with third-order distortion. The sample rate is 3.6 kHz. Subtract the zero-frequency (DC) component to concentrate on the spectral content.

load(fullfile(matlabroot,'examples','signal','AmpOutput.mat'))
Fs = 3600;
y = y-mean(y);

Because the amplifier introduces third-order distortion, the output signal is expected to have

  • A fundamental component with the same frequency as the input, 60 Hz;

  • Two harmonics -- frequency components at twice and three times the frequency of the input, 120 and 180 Hz.

Use bandpower to determine the power stored in the fundamental and the harmonics. Express each value as a percentage of the total power and in decibels. Display the values as a table.

pwrTot = bandpower(y,Fs,[0 Fs/2]);

Harmonic = {'Fundamental';'First';'Second'};

Freqs = [60 120 180]';

Power = zeros([3 1]);
for k = 1:3
    Power(k) = bandpower(y,Fs,Freqs(k)+[-10 10]);
end

Percent = Power/pwrTot*100;

inDB = pow2db(Power);

T = table(Freqs,Power,Percent,inDB,'RowNames',Harmonic)
T = 

                   Freqs     Power      Percent      inDB  
                   _____    ________    _______    ________

    Fundamental     60        1.0079    12.563     0.034136
    First          120       0.14483    1.8053      -8.3914
    Second         180      0.090023    1.1221      -10.456

See Also

| | |

Related Examples

Was this topic helpful?