Skip to Main Content Skip to Search
Product Documentation

nextpow2 - Next higher power of 2

Syntax

p = nextpow2(A)

Description

p = nextpow2(A) returns the smallest power of two that is greater than or equal to the absolute value of A. (That is, p that satisfies 2^p >= abs(A)).

This function is useful for optimizing FFT operations, which are most efficient when sequence length is an exact power of two.

Examples

For any integer n in the range from 513 to 1024, nextpow2(n) is 10.

For vector input, nextpow2(n) returns an element-by-element result:

A = [1 2 3 4 5 9 519]
nextpow2(A)
ans =

     0     1     2     2     3     4    10

See Also

fft | log2 | pow2

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS