, j4 T/ ?3 a. d8 @. C4 W# b. s Z9 Z3 S9 i' L" q( U+ K0 H a9 L% S. S' j5 {
您可以使用nextpow2来填充传递给fft的信号。 这样做可以在信号长度不是2的精确幂次时加速FFT的计算。 8 _9 C1 _( y: ~; h, k; T0 m* M$ F8 W8 A. H( L% S: H) M
Optimize FFT with Padding / S4 M. e! C' p& l' S3 ` ; ^( U; D+ h. F1 f. N- E% y) o下面这个例子展示了 使用填充优化FFT的案例,通过使用函数nextpow2完成:) I, _3 @. O+ Q+ I$ {1 K1 q4 |
* t! ]# I W9 {7 C1 R
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.
* J' ^3 \& H" Q% F+ w6 O- z
x = gallery('uniformdata',[1,8191],0);
% Calculate the next power of 2 higher than 8191.
0 F v' l# ?$ J+ ^+ S
p = nextpow2(8191);
n = 2^p
%get n = 8192
% Pass the signal and the next power of 2 to the fft function.