I've written a program to compute the power spectral density of a signal. The problem I'm having is that the computed spectrum is quite a bit more noisy than it should be (comparing to the spectrum computed by Matlab), especially at low frequencies.
The red in this plot shows the spectrum computed by Matlab's cpsd
command (0 overlap, NFFT=window=8192, 200Hz signal), and the green shows my own. There's a constant offset (in the log domain) between them, but that's okay for now. What I'm more concerned about is that my implementation is noisier, especially in the 0-3Hz range. The algorithm I've implemented is
- Zero out a vector of length NFFT/2+1, for averaging.
- Until there are no more samples:
- Read NFFT samples (0-fill the remainder if there are less than NFFT)
- Compute the 1-dimensional real NFFT
- Compute the magnitude of each complex result, and divide by NFFT
- Add this to the corresponding position in the averaging vector
- Divide each sum by the twice the sampling frequency times the number of windows read
Sizing a window different than NFFT, and overlap, aren't included in the algorithm, but when compared to the Matlab output for window=NFFT and no overlap it shouldn't matter.
Can anyone speak as to why this results in low frequency instability?
cpsd
instead ofperiodogram
? $\endgroup$ – leonbloy Feb 17 '12 at 0:19