I am trying to understand the difference between the Power Spectral Density and the Fourier transform. Specifically, I am trying to understand why the power spectral density is useful and in what scenarios it is useful.
For example, suppose I have some time series and I want to get a better understanding of the frequency content of the time series. I can either take the Fourier transform (e.g. FFT), or I can compute the power spectral density. The power spectral density involves windowing, computing the autopowers for each window and summing. It seems to involve many more steps than a straight-forward FFT.
Below is a MATLAB script I wrote to examine this;
T = 1; %Length of time series in seconds Fs = 1000; %sample frequency dt = 1/Fs; %sample length N = T/dt; %Number of time samples t = (0:N-1)*dt; %Time vector f = (0:N/2)*Fs/N; %Frequency vector %Frequency content of the signal (three frequencies in Hz) F1 = 200; F2 = 400; F3 = 350; sigma = 3; %Standard deviation of the noise to be added %Create time series r = sin(2*pi*F1*t)+sin(2*pi*F2*t)+sin(2*pi*F3*t)+sigma*randn(1,N); %Time series %Compute one-sided FFT R = fft(r); %Fourier transform of time series R2 = abs(R/N); R1 = R2(1:N/2+1); R1(2:end-1) = 2*R1(2:end-1); %Compute power spectral density (autospectrum) [pxx,fxx] = cpsd(r,r,bartlett(256),128,2048,Fs); %Plot results subplot(3,1,1) plot(t,r,'-'); %Time Series title('Time series'); xlabel('Time (s)'); ylabel('Amplitude'); subplot(3,1,2) plot(f,R1,'-') %One-sided FFT amplitude spectrum title('Fourier transform'); xlabel('Frequency (Hz)'); ylabel('Amplitude'); axis([0 Fs/2 0 1.1]) subplot(3,1,3) plot(fxx,2*pi*pxx) %Autospectrum title('Power Spectral Density') xlabel('Frequency (Hz)') ylabel('Power / Hz')
The output from this script is the following figure:
Both the FFT spectrum and the autopower spectrum show peaks at 200, 350, and 400 Hz which is good because that is what the true signal contains. But the peaks are more obvious in the FFT. So why would I use the power spectral density method?
Can anyone provide a simple example where the FFT fails to show the correct spectrum but the autopower is able to recover it?