I'm trying to visualise downsampling in the frequency domain in matlab

I take a simple sinusoid, perform an fft and plot a two sided spectrum. Then I downsample the time domain signal (downsamplefactor D=2) and perform the same fft and two sided spectrum plot.

What i would expect to see: (This uses M, i use D as downsample factor)


(from: Frequency Representation of Downsampled Signal)

So i'm expecting my frequencies to get stretched by a factor D and the amplitude should get scaled by 1/D. The stretching works as expected, however my amplitude doesnt scale. What am I missing/not seeing? Matlab code:

% 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
  • $\begingroup$ The scaling effet happens without normalization of DFT. If you normalize your DFT, only strecthing effet is kept because downsampling does not change the power of sinusoide in continuos time domain. $\endgroup$
    – AlexTP
    Apr 19 '17 at 14:52

You are removing the scaling effect yourself when you perform the following operations:

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

If you don't divide by the length, then you'll see that one has half the amplitude of the other.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.