bugGNU Octave - Bugs: bug #62095, periodogram: gives wrong result...


bug #62095: periodogram: gives wrong result (namely 0)

Submitter:  None
Submitted:  Tue 22 Feb 2022 12:31:18 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Documentation
Status:  Need Info Assigned to:  None
Originator Name:  Tim van Zon Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * GNU/Linux
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Wed 09 Mar 2022 12:20:54 AM UTC, comment #3: 

As a second reference, I also tried the sample code in Matlab and results are the same as in Octave.  Octave must maintain compatibility with Matlab and so the function must keep its current behavior.

I second the suggestion in comment #1 to find a better explanation for how the function behaves.

Rik <rik5>
Project Administrator
Tue 08 Mar 2022 11:27:49 PM UTC, comment #2: 

Hi, the periodogram function is part of Octave, not the signal processing package, just a slight update to bug description.

Yes, the result for your example is a zero vector, and as far as I can tell this is compatible with Matlab's periodogram function.

If there is a bug regarding this example, it might be that the documentation isn't clear in some way. Can you help improve the help text, or maybe help explain your expected result versus what the function is doing so the help text can be more helpful?

Mike Miller <mtmiller>
Project Administrator
  Spam posted by anonymous
Tue 22 Feb 2022 12:31:18 PM UTC, original submission:  

I constructed an example where periodogram gives the wrong answer. The bug is that periodogram averages the segments before taking the fft, instead of averaging the fft output.

++ verbatim ++

N = 8;  % windowsize
Fs_Hz = 10; % sample rate in Hz
dt_sec = 1./Fs_Hz;
a = randn(N,1);

% make a signal by replicating 'a' with a minus sign
signal = [a;-1.*a];

pxx = periodogram(signal,[],N,Fs_Hz)
% this will result in sum(pxx)==0, while it should not be zero, as there is amplitude there.
% this is because periodogram averages the segments BEFORE taking the fft.
% this example is constructed to show this, as the average of the 2 segments is now zero.

% And there is a second bug, namely that the documentation says it gives the
% POWER spectral density (PSD), while it actually gives the ENERGY spectral density.
% (please recall that  power * time = energy)
energy_a = sum(a.*conj(a) * dt_sec);  % Not necessary to use conj here. so this is the Es from https://en.wikipedia.org/wiki/Energy_(signal_processing)
pA = periodogram(a,[],N,Fs_Hz);
% summing over all frequencies in pxx should give the same number as energy_a,
assert( sum(pA), energy_a, 1e-9) % so this is as expected

% Note: do not compare against pwelch, as that will give the energy per windowlength, which can
% be different from energy and from power!

-- verbatim --



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.





    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-23 rik5 Priority5 - Normal 3 - Low
        Item GroupIncorrect Result Documentation
    2022-03-08 mtmiller CategoryOctave Forge Package Octave Function
        StatusNone Need Info
        Release4.2.1 dev
        Summary/usr/local/share/octave/4.2.1/m/signal/periodogram.m (version 1.4.1) gives wrong result (namely 0) periodogram: gives wrong result (namely 0)

    Back to the top

    Powered by Savane 3.9