Skip to content

Bug: findPeaks minima branch does not negate data #12

@iahncajigas

Description

@iahncajigas

Bug Description

In SignalObj.m, the findPeaks method's 'minima' branch (line 1630) is identical to the 'maxima' branch (line 1626). The minima case does not negate the data before calling findpeaks, so it returns maxima instead of minima.

Location

SignalObj.m, lines 1624–1631:

if(strcmp(type,'maxima'))
    for i=1:sObj.dimension
        [values{i},indices{i}] = findpeaks(sObj.data(:,i),'MINPEAKDISTANCE',minDistance);
    end
elseif(strcmp(type,'minima'))
    for i=1:sObj.dimension
        [values{i},indices{i}] = findpeaks(sObj.data(:,i),'MINPEAKDISTANCE',minDistance);  % BUG: same as maxima
    end

Expected Behavior

The minima branch should negate the signal before calling findpeaks, then return the original (non-negated) values at those indices:

elseif(strcmp(type,'minima'))
    for i=1:sObj.dimension
        [~,indices{i}] = findpeaks(-sObj.data(:,i),'MINPEAKDISTANCE',minDistance);
        values{i} = sObj.data(indices{i},i);
    end

Found During

Python port (cajigaslab/nSTAT-python) — fixed in the Python implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions