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

 
 

bug #51657: [octave forge] (signal) gausswin produces slightly wrong result

Submitter:  None
Submitted:  Fri 04 Aug 2017 11:55:32 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  juanpi
Originator Name:  Håkon A. Hjortland Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 21 Mar 2018 08:42:56 AM UTC, comment #7: 

I made some style fixes and added some more test cases based on this bug report.

https://hg.mtmxr.com/octave-signal/rev/41291950c2c2

Can we close this as fixed? I think the function is behaving correctly now and should not accept m as a vector.

Mike Miller <mtmiller>
Group Member
Mon 11 Dec 2017 09:26:26 PM UTC, comment #6: 

The "current" development version refers to revision ae7ace06b8c6

Juan Pablo Carbajal <juanpi>
Group Member
Mon 11 Dec 2017 09:25:44 PM UTC, comment #5: 

Hi,

To speed up the process you can send patches against the current development version of signal.

I implemented a fix for the matlab 2017a incompatibility for scalar input. If their text help says m should be a scalar, their function has a bug!

With the development version you get


octave-gui:1> gausswin(0)
error: gausswin: M must be a positive integer
error: called from
    gausswin at line 35 column 5
octave-gui:1> gausswin(1)
ans =  1
octave-gui:2> gausswin(2)
ans =

   0.0439369336234074
   0.0439369336234074


I am not sure we want to copy the behavior for the non-scalar input. My guess is that this is an undesired behavior that they got when introducing automatic broadcasting. They will probably fix it in the future.

Juan Pablo Carbajal <juanpi>
Group Member
Mon 11 Dec 2017 12:56:30 PM UTC, comment #4: 

Any updates on this?

Is the proposed fix for signal 1.3.2 of changing a/m to a/(m-1) in the specified line of gausswin.m the correct one (assuming normal window sizes)?

Is there anything I can do to help?

Kenneth Hoste <kehoste>
Fri 11 Aug 2017 08:27:18 PM UTC, comment #3: 

Ok, the last one is just weird.  Matlab documentation mentions that N (M in the octave version) must be a positive integer.  So the warning and rounding is not unexpected.  but the fact that it accepts an array is odd, and odd results come about:


>> gausswin(1)
ans =
     1
>> gausswin([1 1 1 1 1])
ans =
     1
>> gausswin([1 1 2 1 1])
ans =
   0.043936933623407
>> gausswin([1 1 2 1 1]')
ans =
  Columns 1 through 3
   1.000000000000000   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000   0.043936933623407
   1.000000000000000   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000   1.000000000000000
  Columns 4 through 5
   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000
   1.000000000000000   1.000000000000000


best as I can guess from the formula on the help page is that there's a matrix multiplication or division that is allowed to occur


>> a = [1 1 2 1 1];

>> a/a
ans =
   1.000000000000000

>> a'/a'
ans =
  Columns 1 through 3
                   0                   0   0.500000000000000
                   0                   0   0.500000000000000
                   0                   0   1.000000000000000
                   0                   0   0.500000000000000
                   0                   0   0.500000000000000
  Columns 4 through 5
                   0                   0
                   0                   0
                   0                   0
                   0                   0
                   0                   0


I don't think that is at all intended. and it's not documented.  So I'm going to ignore it and leave it as an error in octave for now unless matlab documentation changes.

Nicholas Jankowski <nrjank>
Group Member
Fri 11 Aug 2017 06:41:52 PM UTC, comment #2: 

checking the current tests in octave's gausswin, the following expect to produce errors, but don't in Matlab:


>> gausswin(0.5)
Warning: Rounding order to nearest integer.
> In check_order (line 27)
  In gausswin (line 33)

ans =

     1

>> gausswin (ones (1, 4))

ans =

     1


will include these in updated sets of tests

Nicholas Jankowski <nrjank>
Group Member
Fri 11 Aug 2017 06:35:56 PM UTC, comment #1: 

additionally:

matlab 2017a:

>> gausswin(0)

ans =

  0×1 empty double column vector

>> gausswin(1)

ans =

     1

>> gausswin(2)

ans =

   0.043936933623407
   0.043936933623407


Octave 4.2.1, signal 1.3.2, without your suggested change

>> gausswin(0)
error: gausswin: M must be a positive integer
error: called from
    gausswin at line 35 column 5
>> gausswin(1)
ans =  1
>> gausswin(2)
ans =

   0.457833361771614
   0.457833361771614


Octave 4.2.1, signal 1.3.2, after making your suggested change to gausswin:

>> gausswin(0)
error: gausswin: M must be a positive integer
error: called from
    gausswin at line 35 column 5
>> gausswin(1)
warning: division by zero
warning: called from
    gausswin at line 40 column 5
ans = NaN
>> gausswin(2)
ans =

   0.0439369336234074
   0.0439369336234074


so there would be a few other compatibility wrinkles to work out.  I'll try to generate some tests that a patch can be worked against.

Nicholas Jankowski <nrjank>
Group Member
Fri 04 Aug 2017 11:55:32 AM UTC, original submission:  


MATLAB: gausswin(3)' = [0.0439  1.0000  0.0439]
Octave: gausswin(3)' = [0.24935 1.00000 0.24935]

This is less pronounced for normal window lengths, though.

Looking at the algorithms section at
https://www.mathworks.com/help/signal/ref/gausswin.html
it seems that in signal-1.3.2/gausswin.m in the line

w = exp ( -0.5 * ( a/m * [ -(m-1) : 2 : m-1 ]' ) .^ 2 );

the expression a/m should be changed to a/(m-1).

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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 jwe (Updated the item)
  • -email is unavailable- added by juanpi (Posted a comment)
  • -email is unavailable- added by kehoste (Posted a comment)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by nrjank (pkg maintainer)
  • -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 group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-02 jwe Summary[octave-forge] (signal) gausswin produces slightly wrong result [octave forge] (signal) gausswin produces slightly wrong result
    2018-04-02 mtmiller StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2017-12-11 juanpi Item GroupInaccurate Result Matlab Compatibility
        StatusConfirmed In Progress
        Assigned toNone juanpi
    2017-08-11 mtmiller StatusNone Confirmed
        Summarygausswin produces slightly wrong result [octave-forge] (signal) gausswin produces slightly wrong result
    2017-08-11 nrjank Carbon-Copy- Added mtmiller

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code