octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bugs in periodogram.m (and proposed fixes)


From: Drew Abbot
Subject: bugs in periodogram.m (and proposed fixes)
Date: Mon, 21 Jul 2014 17:35:20 -0700

There are two bugs in the current periodogram() implementation, and here's a new version which fixes both.  The first bug is that, when using one-sided spectra (the default behavior), only column vectors are supported for the input signal, x.  Sending in row vectors causes a "vertical dimensions mismatch" error due to this one-sided conversion code:
  
  Pxx = Pxx(1:nfft/2+1) + [0; Pxx(end:-1:(nfft/2+2)); 0];

To witness the bug, simply attempt:

  pxx = periodogram( sin(1:10) )

The second also involves that one-sided conversion code.  Namely, it is incorrect when nfft is odd, since it yields 1/2 the correct value at the upper-most (non-Nyquist) frequency.

To see this, note that the following returns ~0.0171 for the third component, when it should return ~0.0342:

  pxx = periodogram( sin(1:5)', [], 5 )

The attached code fixes both issues (using similar one-sided conversion code to that found in the current pwelch() implementation), and also forces that the window (if non-empty) is a vector of the same length as the signal (which is the current MATLAB behavior).

Best,
Drew Abbot

Attachment: periodogram.m
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]