当我对信号进行零填充时,原始信号和零填充信号的fft不再连接在同一点附近了怎么办?

时间:2019-04-10 19:25:19

标签: matlab signal-processing fft dft

我认为我执行的代码错误。我认为原始信号和零填充信号将在同一点附近连接,并具有相同的峰值。我对此是否理解错误,还是我的代码有问题?

clc;clear;
N=257; %number of points in the signal
f=330.5; %frequency of signal
fs=1024; %sampling frequency 
Ts=1/fs; %sampling period
ts=0:Ts:(N-1)/fs; %duration of signal
x=sin(f*ts);%generation of sampled signal
X=fftshift(fft(x)); %shifted FFT of signal
figure(5)
stem(abs(X))
M=2048; %number of points desired in the new signal that will be zero padded
zerovec=zeros(1,(M-N)); %creating enough 0's to add to the end of the original signal to achieve the desired length
x1=[x zerovec]; %concatenating original signal and 0's to get zero padded signal 
X1=fftshift(fft(x1)); %fft of zero padded signal

figure()
stem(abs(X)) %discrete plot of original signal
hold on 
stem(abs(X1)) %discrete plot of zero padded signal 

1 个答案:

答案 0 :(得分:1)

对信号进行零填充时,其频谱变得更加密集。从某种意义上说,当对空间域进行零填充时,您会在频域中进行插值。

如果沿x轴绘制具有正确频率的两个频谱,则会看到它们重叠:

N=257;
f=330.5;
fs=1024;
Ts=1/fs;
ts=0:Ts:(N-1)/fs;
x=sin(f*ts);

X=fftshift(fft(x));
F=0:fs/N:fs-fs/N;     % <<< NEW!

M=2048;
zerovec=zeros(1,(M-N));
x1=[x zerovec];
X1=fftshift(fft(x1));
F1=0:fs/M:fs-fs/M;    % <<< NEW!

figure()
stem(F,abs(X))        % <<< NEW! using F
hold on 
stem(F1,abs(X1))      % <<< NEW! using F1

plot