The problem I'm dealing with is the removal of test equipment artifacts from experimentally derived datasets. In layman's terms, the sensing circuit has a tendency to oscillate a little occasionally; which introduces inflections into the data which must be removed before the data can be used for the next part of the processing which requires monotonic data.

This is a case where a picture is worth a thousand words: http://oi63.tinypic.com/2z72xbr.jpg. The blue is (a small subset of) the raw data and the red is the desired output.

This code performs the cleanup. (It runs as a pipe filter, and I've adapted it to use __DATA__ for the small subset shown in the graphic for posting purposes.):

The basic mechanism is to compare the points as successive pairs and look for a negative slope. When a negative slope is found, *both* points are removed from the dataset.

The complication is that pairwise comparisons have to continue with the next point against the *previous* unremoved point.

To (I hope) clarify, in the following:

H G F E D C B A

Resultant dataset: A, B, G, H.

The above code works; but is there a better way of coding it?

I'm not going to define "better"; I'd simply like to see a range of alternative codings.

(Please note: this is not about filtering or smoothing or interpolating the data; just removing spurious values.)

The output from the sample code:


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to How would you code this? by BrowserUk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.