Magnitude scaling in FFT and Periodogram

15 views (last 30 days)
Hi all, I am trying to use to matlab(with signal processing tool box option) to look at FFT of sin waves.
It looks the fft function does not output magnitude correctly without a few more lines of code.
The code for scaling the fft correctly for DC and all frequency bins is given in the link below
Is there similar code for scaling the magnitude's when using the periodogram function ?
I understand the code listed in the link above essentially does the function of periodogram. But there is more is more than one reason why scaling the periodogram function similarly would be very helpful.
regards
SRS

Accepted Answer

Wayne King
Wayne King on 15 Sep 2011
Hi, If you are using the Signal Processing Toolbox, then the correct scaling is built into the periodogram function and the spectrum.periodogram object.
Fs = 1e3;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
plot(psd(spectrum.periodogram,x,'Fs',1e3,'NFFT',length(x)))
To produce the correct scaling for a one-sided periodogram with known sampling frequency using the DFT, you would have to enter:
xdft = fft(x);
psdx = 1/(length(x)*Fs).*abs(xdft(1:length(x)/2+1)).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
figure;
plot(10*log10(psdx)); grid on; axis tight;
Whether it is important for you to get the scaling theoretically correct really depends on what you are using the periodogram for and how you are using it.
Wayne
  2 Comments
S RS
S RS on 15 Sep 2011
Hi Wayne,
Thanks !
When i tried the above code and looked at the plot (one-sided periodogram) the signal frequency which in this case is 100 shows up in bin 101 which is equivalent to 101Hz.
Whereas in the first plot command it shows up as 100Hz.
thanks again
SRS
S RS
S RS on 16 Sep 2011
Hi Wayne,
I changed the sampling frequency and number of FFT points and even with the above code a bit and i cannot get the magnitude to scale correctly
Fs = 80e6;
NFFT = 64000;
t = (0:1:NFFT-1)*1/Fs;
x = 0.5 + 0.5*sin(2*pi*5000*t);
figure(1) ;
plot(x)
grid on ;
figure(2) ;
plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)))
I am expecting to see a frequency spectrum where the dc bin has 0.5 and the bin with 5KHz has 0.5 as well. The magnitude's are not what i expect.
It happens with the psd code as well the one-sided periodogram code you have listed as well.
Why is the magnitude scaling incorrect ?
Also, If possible i would like to apply windowing function by using psd command. But it looks like i have to use pwelch to do that. Is that correct ?

Sign in to comment.

More Answers (2)

Wayne King
Wayne King on 15 Sep 2011
Hi, bin 101 is not equivalent to 101 Hz. The bins are spaced in 1 Hz increments in this case, but you are forgetting that the first bin is DC, zero frequency.
Wayne
  1 Comment
S RS
S RS on 15 Sep 2011
You are right. Thanks for pointing it out.
One last question, when using
psd(spectrum.periodogram,x,'Fs',1e3,'NFFT',length(x))
what is the syntax to dump the spectral content into a variable/vector ?
You response has been very helpful.
regards
SRS

Sign in to comment.


Wayne King
Wayne King on 15 Sep 2011
psdest = psd(spectrum.periodogram,x,'Fs',1e3,'NFFT',length(x));
psdest.Data
has the periodogram values (not in dB),
psdest.Frequencies
has the frequencies.
The plot() method knows how to act on this object, so
plot(psdest)
produces a plot in dB.
Wayne

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!