+ Reply to Thread
Results 1 to 6 of 6

Counting number of peaks in graph

  1. #1
    Registered User
    Join Date
    04-05-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    8

    Counting number of peaks in graph

    Hi,
    I have a large set of data which consists of only 0s and 1s, When plotting on a graph, the 1s represent peaks, but a single peak spans over a number of data points, and sometimes briefly drops to 0 but then continues. I cant figure out which function to use to count the number of peaks in my data, given that even if it drops to zero for a certain specified time frame, it still counts as one peak. Any help would be appreciated. Hope the example below helps:

    Here, the time frame for 0s between two peaks to still count as one peak is 1 second
    Time(s) Data
    1 0
    2 0
    3 0
    4 0
    5 0
    6 1 *
    7 0 * PEAK 1
    8 1 *
    9 1 *
    10 0
    11 0
    12 0
    13 1 * PEAK 2
    14 0
    15 0
    16 1 *
    17 1 * PEAK 3
    18 1 *
    19 0
    20 0
    21 1 * PEAK 4
    22 1 *
    23 0
    24 0
    Last edited by evydmb; 04-05-2013 at 03:40 PM.

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting number of peaks in graph

    Try this array formula**:

    =SUM(IF(FREQUENCY(IF(A2:A25=1,ROW(A2:A25)),IF(A2:A25<>1,ROW(A2:A25))),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    04-05-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Counting number of peaks in graph

    Thanks Tony Valko, but I forgot to mention something so I edited my post.

  4. #4
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting number of peaks in graph

    Well, that changes things considerably.

    At the moment I'm stumped!

  5. #5
    Registered User
    Join Date
    04-05-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Counting number of peaks in graph

    Thanks anyway, your initial function would work if there were no dips in the peaks. Heres a visualisation of the problem.

    peaks.png

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting number of peaks in graph

    The only thing I can think of is to use a helper column and then get the count from the helper column.

    Assuming your data is in the range A2:A25.

    Enter this formula in B2:

    =A2

    Enter this formula in B3 and copy down to B25:

    =IF(A3=1,1,IF(AND(A2=1,A4=1),1,0))

    Then, this array formula** to count the "peaks" in B2:B25:

    =SUM(IF(FREQUENCY(IF(B2:B25=1,ROW(B2:B25)),IF(B2:B25<>1,ROW(B2:B25))),1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

    Actually, all we're doing is counting how many groups of 1s there are. Each group has its peak so counting the number of groups also counts the number of peaks.

    I used to work in a lab where we used xray fluorescence analysis. We had to identify "plateaus" rather than peaks. The plateau was never perfectly "flat".
    Last edited by Tony Valko; 04-05-2013 at 06:17 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1