1. 程式人生 > >【 MATLAB 】nextpow2 函式用法之 Optimize FFT with Padding

【 MATLAB 】nextpow2 函式用法之 Optimize FFT with Padding

您可以使用nextpow2來填充傳遞給fft的訊號。 這樣做可以在訊號長度不是2的精確冪次時加速FFT的計算。

Optimize FFT with Padding

 

下面這個例子展示了 使用填充優化FFT的案例,通過使用函式nextpow2完成:

clc
clear
close all
% Use the nextpow2 function to increase the performance of fft when the length of a signal is not a power of 2.
% 
% Create a 1-D vector containing 8191 sample values.

x = gallery('uniformdata',[1,8191],0);
% Calculate the next power of 2 higher than 8191.

p = nextpow2(8191);
n = 2^p
%get  n = 8192
% Pass the signal and the next power of 2 to the fft function.

y = fft(x,n);





 

上述的程式中有一個產生測試矩陣的函式x = gallery('uniformdata',[1,8191],0);,關於它的介紹見博文:【 MATLAB 】gallery 中的 uniformdata