Signal Metrics

The mean of a signal $ x$ stored in a matlab row- or column-vector x can be computed in matlab as

mu = sum(x)/N
or by using the built-in function mean(). If x is a 2D matrix containing N elements, then we need mu = sum(sum(x))/N or mu = mean(mean(x)), since sum computes a sum along ``dimension 1'' (which is along columns for matrices), and mean is implemented in terms of sum. For 3D matrices, mu = mean(mean(mean(x))), etc. For a higher dimensional matrices x, ``flattening'' it into a long column-vector x(:) is the more concise form:
N = prod(size(x))
mu = sum(x(:))/N
mu = x(:).' * ones(N,1)/N
The above constructs work whether x is a row-vector, column-vector, or matrix, because x(:) returns a concatenation of all columns of x into one long column-vector. Note the use of .' to obtain non-conjugating vector transposition in the second form. N = prod(size(x)) is the number of elements of x. If x is a row- or column-vector, then length(x) gives the number of elements. For matrices, length() returns the greater of the number of rows or columns.I.1

Signal Energy and Power

In a similar way, we can compute the signal energy $ {\cal E}_x$ (sum of squared moduli) using any of the following constructs:

Ex = x(:)' * x(:)
Ex = sum(conj(x(:)) .* x(:))
Ex = sum(abs(x(:)).^2)
The average power (energy per sample) is similarly Px = Ex/N. The $ L2$ norm is similarly xL2 = sqrt(Ex) (same result as xL2 = norm(x)). The $ L1$ norm is given by xL1 = sum(abs(x)) or by xL1 = norm(x,1). The infinity-norm (Chebyshev norm) is computed as xLInf = max(abs(x)) or xLInf = norm(x,Inf). In general, $ Lp$ norm is computed by norm(x,p), with p=2 being the default case.

Next Section:
Inner Product
Previous Section:
Vector Interpretation of Complex Numbers