fft
实数的信号是围绕奈奎斯特频率对称的(实际上是复共轭)。奈奎斯特频率是采样频率的一半,在您的例子中采样是在3000赫兹,因此奈奎斯特频率是1500赫兹。如果你仔细观察峰值,你会发现它在2940赫兹(3000-60赫兹),因为
快速傅里叶变换
镜像在1500赫兹左右。
here
).
fft
给你快速傅里叶变换,它是围绕奈奎斯特频率镜像的。你可以用
fftshift
把频谱集中在零频率附近。
我冒昧地缩短了代码,避免了几个for循环的重复,并添加了
. 既然你的信号是真实的,你也可以选择只显示fft的一侧,但我将由你来决定。
Lvl=[0.5,0.9,0.5,0.5,0.1,0.1,0.9,0.5];
fa=60; % the frequency of the parasitic source in hertz
np=2; % number of periods per bit
kl = length(Lvl);
dt = 0.01*np/fa; % time step
Tend = np*kl/fa - dt; % time span
t = 0:dt:Tend; % time vector
N = length(t); % number samples
Sig=sin(2*pi*fa*t);
for n = 1:kl
ids = (1:100) + (n-1)*100;
Sig(ids) = Sig(ids).*Lvl(n);
end
% FFT
Y = fft(Sig);
fv = (0:N-1)/(N*dt); % frequency range
% FFT shift:
Y_shift = fftshift(Y);
fv_shift = (-N/2:N/2-1)/(N*dt); % zero centered frequency vector
% Plot
figure(1); clf
subplot(311)
plot(t,Sig)
title('Signal')
subplot(312)
plot(fv,abs(Y))
title('FFT Magnitude')
subplot(313)
plot(fv_shift,abs(Y_shift))
title('FFT Magnitude zero shift')