bugGNU Octave - Bugs: bug #50820, [octave forge] (signal) pwelch...


bug #50820: [octave forge] (signal) pwelch incorrectly discards DC component

Submitted by:  Shri <theillusiveman>
Submitted on:  Mon 17 Apr 2017 09:39:47 PM UTC  
Category:  Octave Forge Package Severity:  2 - Minor
Priority:  1 - Later Item Group:  Matlab Compatibility
Status:  Postponed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  other Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Wed 21 Mar 2018 01:57:14 AM UTC, comment #3:

Octave's pwelch already supports updated Matlab defaults, but via a strange "R11" or "R12" argument passed in.

I haven't really modified pwelch myself, but it might make sense to try to simplify all the code that tries to be compatible with different versions of Matlab and just go with the latest. It's hard enough keeping up with the changes that Matlab makes, but trying to keep code optionally backwards compatible with older versions doesn't seem worth it.

So someone might want to look at the "compatib" internal variable in pwelch.m and the various interpretations of positional arguments that is already done, and choose whichever is closest to the current Matlab way.

Mike Miller <mtmiller>
Project Administrator
Mon 17 Apr 2017 10:10:05 PM UTC, comment #2:

Thanks for reply.
I suspected as much, it looked as if the DC was being subtracted. Adding "no-strip" argument results in the expected figure.

Yes, MATLAB does indeed not remove DC from the input. As a suggestion, would it be possible to remove the DC if a "strip" option is specified rather than keep if "no-strip" is specified? It will make things more uniform across Octave and MATLAB.

Shri <theillusiveman>
Mon 17 Apr 2017 09:59:41 PM UTC, comment #1:

I think the issue here is that in octave's pwelch the default
is to subtract mean from the signal, and in matlab's apparently not.

Try to add "no-strip" option:

[X,f]=pwelch(x,fs,0,fs,fs, "no-strip");


Dmitri A. Sergatskov <dasergatskov>
Mon 17 Apr 2017 09:39:47 PM UTC, original submission:

Current setup:
Windows 10, GNU Octave 4.2.1, Signal Package 1.3.2.

Procedure to replicate issue:

Generate any signal (or use existing one if desired) with a non-zero DC. Use the pwelch() method using one second window, no overlap to get the power spectrum. Observe the DC coefficient on the result.

What to expect?:

The DC term to be the actual average of the signal.

What happens?:

The DC term is zero.

Additional info:

I used the attached code to test for the issue. I generated a sinusoid with some DC offset. As a comparison, I generated the same graph on MATLAB. MATLAB has the correct DC term while Octave does not. See the attached graphs to observe the results. The graph name *_ML.png was generated in MATLAB. This shows the proper DC term. Octave does not.

Shri <theillusiveman>


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

Attach Files:

Attached Files
file #40424:  pwtest.m added by theillusiveman (259B - application/octet-stream)
file #40425:  PW_Test_ML.png added by theillusiveman (23KiB - image/png)
file #40426:  PW_Test_Oct.png added by theillusiveman (14KiB - image/png)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by theillusiveman (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-21 mtmiller Severity3 - Normal => 2 - Minor
        Priority5 - Normal => 1 - Later
        Item GroupIncorrect Result => Matlab Compatibility
        StatusNone => Postponed
        Release4.2.1 => other
    2017-08-12 jwe Summarypwelch incorrectly discards DC component => [octave forge] (signal) pwelch incorrectly discards DC component
    2017-04-17 theillusiveman Attached File- => Added pwtest.m, #40424
        Attached File- => Added PW_Test_ML.png, #40425
        Attached File- => Added PW_Test_Oct.png, #40426

    Back to the top

    Powered by Savane 3.3