Matlab中的下采样简单示例

信息处理 matlab 频谱 下采样
2022-01-29 05:00:11

我正在尝试在matlab中可视化频域中的下采样

我采用一个简单的正弦曲线,执行 fft 并绘制一个两侧频谱。然后我对时域信号进行下采样(下采样因子 D=2)并执行相同的 fft 和两侧频谱图。

我希望看到的:(这使用 M,我使用 D 作为下采样因子)

公式

(来自: 下采样信号的频率表示

所以我希望我的频率会被因子 D 拉伸,并且幅度应该按 1/D 缩放。拉伸按预期工作,但是我的幅度没有缩放。我错过/没有看到什么?Matlab代码:

% normal signal -> fft -> plot
Fs = 100; %sampling frequency
T = 1/Fs; %sampling time
L = 500;  %signal length
f = 5;    %sine frequency

dF = Fs/L;      %frequency bin step
t = (0:L-1)*T;  %time vector
y = 2*sin(f*2*pi*t);    %sine

Y = fft(y);     %fft
P = abs(Y/L);   %extract magnitude plot

P2 = fftshift(P); %rearranges P to 2sided spectrum:negfreq,0component,posfreq

F2 = dF*(-L/2:1:L/2-1); %for when L is even
%F2 = dF*((-L+1)/2:1:(L+1)/2-1); %for when L is odd
F2rad = F2*pi/(Fs/2); % *pi /Nyquist to convert to [-pi pi]

figure, hold on
%plot(F2,P2) %frequency plot
plot(F2rad,P2) %radian plot

% downsampled signal -> fft -> plot

D = 2;
yd = y(1:D:L); %can also use downsample command
yd = downsample(y,D); %equal to above

Ld = length(yd); %downsampled length

Yd = fft(yd);

Pd = abs(Yd/Ld); %0component,posfreq,nyquist,negfreq
Pd2 = fftshift(Pd); %rearranges P to nyquist,negfreq,0component,posfreq

dFd = (Fs/D)/Ld; %frequency bin step

Fd2 = dFd*(-Ld/2:1:Ld/2-1); %for when L is even
%Fd2 = dF*((-L+1)/2:1:(L+1)/2-1); %for when L is odd
Fd2rad = Fd2*pi/(Fs/(2*D)); % *pi /Nyquist to convert to [-pi pi]

%plot(Fd2,Pd2) %frequency plot
plot(Fd2rad,Pd2) %radian plot
1个回答

当您执行以下操作时,您将自己移除缩放效果:

Pd = abs(Yd/Ld)
P = abs(Y/L)

如果你不除以长度,那么你会看到一个幅度是另一个幅度的一半。