Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Not that hard. If you want an absolute cutoff (500) rather than percentage (6% of max), just change the lines assigning values to $cutoff.
use strict; use warnings; my @n = (101, 203, 321, 45, 67, 156, 203, 502, 899, 2003, 5007, 8020, +7301, 5030, 3045, 1243, 567, 321, 234, 45, 123, 453); my $cutoff = .06; my $max = 0; for (@n) { $max = $_ if $_ > $max; } $cutoff = $max * $cutoff; for (@n) { $_ = 0 if $_ < $cutoff; print $_ ? '-' x ($_ * 50 / $max) : '', "\n"; }
Returns:
--- ----- ------------ ------------------------------- -------------------------------------------------- --------------------------------------------- ------------------------------- ------------------ ------- ---
EDIT: Hmm, you're right, the background noise could theoretically vary, as well as the height of the peaks. I guess a more complicated algorithm is needed. Perhaps the cutoff level could be set to some percentage of the closest peak, then any islands remaining would be removed if they had a bad width-height aggregate (this would be the complicated part). The idea is to set the cutoff low enough so you don't lose much of the edges of the islands, but also to remove any islands which are just background noise.

Then any parts which have been removed can be analyzed to see if there's a regular pattern. If there is, that pattern is extrapolated and removed from the remaining islands.

Altogether too much work, imho :) I'm sure there is a utility written in C or C++ somewhere that does this already, probably faster and better than anything we can write on the spur of the moment. Unless what you're trying to do is something simple like automatically trimming sound files, I'd personally just get a third-party utility and write a wrapper for it.


In reply to Re: How do I find peaks in noisy data? by TedPride
in thread How do I find peaks in noisy data? by tamaguchi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (9)
    As of 2014-10-20 21:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (92 votes), past polls