nextpow2
Exponent of the next power of two at or above abs(x).
Category: Mathematics > Elementary Math
Syntax
P = nextpow2(X)
Returns the smallest integer P such that 2^P >= abs(X).
Description
It is the ceiling of the base-2 logarithm of the magnitude, with exact powers of two returned exactly: nextpow2(1024) is 10 and nextpow2(1025) is 11. The classic use is padding a signal to a power-of-two length before an FFT: fft(x, 2^nextpow2(numel(x))).
Input arguments
X- Numeric array. Signs are ignored.
Output arguments
P- Array of integer-valued doubles. Values of
Xbelow 1 give zero or negative exponents.
Example
Padding length for an FFT
nextpow2([1 5 100 1000 1025])
n = 2^nextpow2(100)
Output
ans = 1×5
0 3 7 10 11
n = 128