nextpow2
Exponent of next higher power of 2
Syntax
Description
Examples
Next Power of 2 of Double Integer Values
Define a vector ofdouble
integer values and calculate the exponents for the next power of 2 higher than those values.
a = [1 -2 3 -4 5 9 519]; p = nextpow2(a)
p =1×70 1 2 2 3 4 10
Calculate the positive next powers of 2.
np2 = 2.^p
np2 =1×71 2 4 4 8 16 1024
Preserve the sign of the original input values.
np2.*sign(a)
ans =1×71 -2 4 -4 8 16 1024
Next Power of 2 of Unsigned Integer Values
Define a vector of unsigned integers and calculate the exponents for the next power of 2 higher than those values.
a = uint32([1020 4000 32700]); p = nextpow2(a)
p =1x3 uint32 row vector10 12 15
Calculate the next powers of 2 higher than the values ina
.
2.^p
ans =1x3 uint32 row vector1024 4096 32768
Optimize FFT with Padding
Use thenextpow2
function to increase the performance offft
when the length of a signal is not a power of 2.
Create a 1-D vector containing 8191 sample values.
rngdefault; x = rand([1,8191]);
Calculate the next power of 2 higher than 8191.
p = nextpow2 (8191);n = 2 ^ p
n = 8192
Pass the signal and the next power of 2 to thefft
function.
y = fft(x,n);
Input Arguments
A
—Input values
scalar, vector, or array of real numbers
Input values, specified as a scalar, vector, or array of real numbers of any numeric type.
Example:15
Example:[-15.123 32.456 63.111]
Example:int16([-15 32 63])
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, seeTall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, seeRun MATLAB Functions on a GPU(Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, seeRun MATLAB Functions with Distributed Arrays(Parallel Computing Toolbox).
版本嗨story
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)