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

 
 

bug #63987: [octave forge] (signal) findpeaks mishandling flat valleys

Submitter:  John Wehle <jwehle>
Submitted:  Sat 01 Apr 2023 08:30:41 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  lostbard
Originator Name:  John Wehle Open/Closed:  * Closed
Release:  * stable Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 22 Jul 2023 10:35:26 PM UTC, comment #6: 

should be fixed in v1.4.5

John Donoghue <lostbard>
Group Member
Thu 29 Jun 2023 12:44:38 PM UTC, comment #5: 

Pushed change as below to repo

John Donoghue <lostbard>
Group Member
Tue 27 Jun 2023 01:25:04 PM UTC, comment #4: 

The flat valley gets pulled in with:


## <= in 1st derivative includes the case of oversampled signals.
  idx = find (df1.*[df1(2:end); 0] <= 0 & [df2(2:end); 0] < 0);


But changing the <= to < then causes the oversampled test to fail

If I add a check later on where it loops through each peak, and filter it out:


diff -r 31c4a47822c1 inst/findpeaks.m
--- a/inst/findpeaks.m  Mon Jun 05 08:33:32 2023 -0400
+++ b/inst/findpeaks.m  Tue Jun 27 09:20:05 2023 -0400
@@ -266,7 +266,11 @@
            ceil (min(idx(i)+minD/2,np))).';
     pp      = zeros (1,3);
     # If current peak is not local maxima, then fit parabola to neighbor
-    if any (data(ind) > data(idx(i)))
+    if any (data(idx(i)-1) == data(idx(i)))
+      # sample on left same as peak
+      xm    = 0;
+      pp    = ones (1,3);
+    elseif any (data(ind) > data(idx(i)))
       pp = polyfit (ind, data(ind), 2);
       xm = -pp(2)^2 / (2*pp(1));   # position of extrema
       H  = polyval (pp, xm);      # value at extrema


It passes the current tests as well as the fail of this bug

John Donoghue <lostbard>
Group Member
Wed 24 May 2023 04:15:25 AM UTC, comment #3: 

No ocl Octave

Anonymous
Wed 10 May 2023 04:44:01 AM UTC, comment #2: 

Using:

  d = [1 10 2 2 1 9 1];
  [ pks, loc ] = findpeaks(d, 'MinPeakHeight', 2*sqrt(eps));

produces the same problem.

John Wehle <jwehle>
Tue 09 May 2023 10:44:07 AM UTC, comment #1: 

Do you get rid of the flat valley by adapting the value of the parameter "MinPeakHeight"?
Try to increase it to 2*sqrt(eps). Does it fix the issue?

Juan Pablo Carbajal <juanpi>
Group Member
Sat 01 Apr 2023 08:30:41 AM UTC, original submission:  

Matlab documentation says regarding findpeaks:

  returns a vector with the local maxima (peaks) of the input signal vector, data.  A local peak is a data sample that is either larger than its two neighboring samples or is equal to Inf.

Using Matlab online to run:

  d = [1 10 2 2 1 9 1];
  [ pks, loc ] = findpeaks(d);

gives the results:

  loc [2, 6]
  pks [10, 9]

However using GNU Octave 8.1 on Windows 10 produces:

  loc [2, 4, 6]
  pks [10, 2, 9]

Octave seems to be treating the flat valley as a peak.

John Wehle <jwehle>

 

(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 lostbard (Posted a comment)
  • -email is unavailable- added by juanpi (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by jwehle (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-07-22 lostbard StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2023-06-29 lostbard StatusNone Ready For Test
        Assigned toNone lostbard
        Release8.1.0 stable
        Operating SystemMicrosoft Windows Any
    2023-04-08 mmuetzel Summarysignal - findpeaks mishandling flat valleys [octave forge] (signal) findpeaks mishandling flat valleys

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code