Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Power Spectral Density Estimates Using FFT

Subject: Power Spectral Density Estimates Using FFT

From: Eva Bal

Date: 19 Apr, 2013 21:22:09

Message: 1 of 3

Hi,

I have been looking at this example for quite some time but I still cannot figure out why when the power spectrum density is calculated, it is multiplied by (1/(Fs*N))

http://www.mathworks.se/help/signal/ug/psd-estimate-using-fft.html

The part of the code that troubles me is marked below:

rng default;
Fs = 1000;
t = linspace(0,1,1000);
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; % HERE is the point that I do not understand
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;
plot(freq,10*log10(psdx));


I have been reading a lot of answers on fft scaling but it is the first time that I see the sampling frequency (Fs) as a scaling factor. What purpose does it serve? Is it just for normalisation?

Thank you,
Eva

Subject: Power Spectral Density Estimates Using FFT

From: Nasser M. Abbasi

Date: 19 Apr, 2013 22:23:41

Message: 2 of 3

On 4/19/2013 4:22 PM, Eva Bal wrote:
> Hi,
>
> I have been looking at this example for quite some time but I still cannot
>figure out why when the power spectrum density is calculated, it is multiplied by (1/(Fs*N))
>
> http://www.mathworks.se/help/signal/ug/psd-estimate-using-fft.html
>
> The part of the code that troubles me is marked below:
>
> rng default;
> Fs = 1000;
> t = linspace(0,1,1000);
> 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; % HERE is the point that I do not understand
> psdx(2:end-1) = 2*psdx(2:end-1);
> freq = 0:Fs/length(x):Fs/2;
> plot(freq,10*log10(psdx));
>
>
> I have been reading a lot of answers on fft scaling but it is the first time that I
>see the sampling frequency (Fs) as a scaling factor. What purpose does it serve? Is
>it just for normalisation?
>
> Thank you,
> Eva
>


If you read the answer to this question here

http://www.mathworks.com/matlabcentral/answers/43548

You'll see this is answered there. Look at the answer by Wayne King there,
where L==N in your case. It is the same question.

--Nasser

Subject: Power Spectral Density Estimates Using FFT

From: TideMan

Date: 19 Apr, 2013 23:14:42

Message: 3 of 3

On Saturday, April 20, 2013 9:22:09 AM UTC+12, Eva Bal wrote:
> Hi,
>
>
>
> I have been looking at this example for quite some time but I still cannot figure out why when the power spectrum density is calculated, it is multiplied by (1/(Fs*N))
>
>
>
> http://www.mathworks.se/help/signal/ug/psd-estimate-using-fft.html
>
>
>
> The part of the code that troubles me is marked below:
>
>
>
> rng default;
>
> Fs = 1000;
>
> t = linspace(0,1,1000);
>
> 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; % HERE is the point that I do not understand
>
> psdx(2:end-1) = 2*psdx(2:end-1);
>
> freq = 0:Fs/length(x):Fs/2;
>
> plot(freq,10*log10(psdx));
>
>
>
>
>
> I have been reading a lot of answers on fft scaling but it is the first time that I see the sampling frequency (Fs) as a scaling factor. What purpose does it serve? Is it just for normalisation?
>
>
>
> Thank you,
>
> Eva

The area under the spectrum must equal the variance (Parseval's Law).
Therefore, you must divide the energy by the interval in frequency, df=Fs/N to get PSD.

BTW, your frequencies are wrong. Since you're using psdx(2:end-1), they should be:
freq = df:df:Fs/2;
you've thrown away the zero frequency (i.e., the mean).

There are a couple of other things wrong as well:
No windowing
No ensemble or frequency averaging

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us