Skip to main content
added 7 characters in body
Source Link
MaxFrost
  • 403
  • 4
  • 12

Following is the code given in MATLAB's site to estimate PSD using FFT.

Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t) + randn(size(t));

N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;

plot(freq,10*log10(psdx))
grid on
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)'
  1. I know I might lack a proper understanding of the fundamentals, but can anyone explain in order to extract the first half of xdft why indicesdoes the index run from $1$ to $N/2 + 1$ and not $1$ to $N/2$? (I suppose the Nyquist frequency lies at $i = N/2$, am I right?)

  2. Some sources mention that the square of the magnitude should be scaled by $\frac{1}{N}$, while here it is scaled by $\frac{1}{Fs*N}$. I am unable to figure out which of these two should be used.

  3. I understand that the DC value should be left untouched when converting to single-sided spectrum. But why is the scaling by $2$ performed only till end-1 and not till end?

Following is the code given in MATLAB's site to estimate PSD using FFT.

Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t) + randn(size(t));

N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;

plot(freq,10*log10(psdx))
grid on
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)'
  1. I know I might lack a proper understanding of the fundamentals, but can anyone explain in order to extract the first half of xdft why indices run from $1$ to $N/2 + 1$ and not $1$ to $N/2$? (I suppose the Nyquist frequency lies at $i = N/2$, am I right?)

  2. Some sources mention that the square of the magnitude should be scaled by $\frac{1}{N}$, while here it is scaled by $\frac{1}{Fs*N}$. I am unable to figure out which of these two should be used.

  3. I understand that the DC value should be left untouched when converting to single-sided spectrum. But why is the scaling by $2$ performed only till end-1 and not till end?

Following is the code given in MATLAB's site to estimate PSD using FFT.

Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t) + randn(size(t));

N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;

plot(freq,10*log10(psdx))
grid on
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)'
  1. I know I might lack a proper understanding of the fundamentals, but can anyone explain in order to extract the first half of xdft why does the index run from $1$ to $N/2 + 1$ and not $1$ to $N/2$? (I suppose the Nyquist frequency lies at $i = N/2$, am I right?)

  2. Some sources mention that the square of the magnitude should be scaled by $\frac{1}{N}$, while here it is scaled by $\frac{1}{Fs*N}$. I am unable to figure out which of these two should be used.

  3. I understand that the DC value should be left untouched when converting to single-sided spectrum. But why is the scaling by $2$ performed only till end-1 and not till end?

Source Link
MaxFrost
  • 403
  • 4
  • 12

Question based on scaling the FFT for obtaining PSD

Following is the code given in MATLAB's site to estimate PSD using FFT.

Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t) + randn(size(t));

N = length(x);
xdft = fft(x);
xdft = xdft(1:N/2+1);
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;

plot(freq,10*log10(psdx))
grid on
title('Periodogram Using FFT')
xlabel('Frequency (Hz)')
ylabel('Power/Frequency (dB/Hz)'
  1. I know I might lack a proper understanding of the fundamentals, but can anyone explain in order to extract the first half of xdft why indices run from $1$ to $N/2 + 1$ and not $1$ to $N/2$? (I suppose the Nyquist frequency lies at $i = N/2$, am I right?)

  2. Some sources mention that the square of the magnitude should be scaled by $\frac{1}{N}$, while here it is scaled by $\frac{1}{Fs*N}$. I am unable to figure out which of these two should be used.

  3. I understand that the DC value should be left untouched when converting to single-sided spectrum. But why is the scaling by $2$ performed only till end-1 and not till end?