R - Approach to find outliers/artefacts in blood pressure curve Do you guys have an idea how to approach the problem of finding artefacts/outliers in a blood pressure curve? My goal is to write a program, that finds out the start and end of each artefact. Here are some examples of different artefacts, the green area is the correct blood pressure curve and the red one is the artefact, that needs to be detected:



And this is an example of a whole blood pressure curve:

My first idea was to calculate the mean from the whole curve and many means in short intervals of the curve and then find out where it differs. But the blood pressure varies so much, that I don't think this could work, because it would find too many non existing "artefacts".
Thanks for your input!
EDIT: Here is some data for two example artefacts:
Artefact1
Artefact2
 A: I'd suggest looking at the changepoint package, in particular cpt.var. At least based on your three examples, it looks like your artifacts involve breaks in variance (first two examples lower, last example higher).
On a more empirical note, you could also try the runmad (windowed MAD) from the caTools package.
A: Blood pressure traces have the advantage of containing a well defined nearly periodic structure. As I recall from my long-ago training in physiology there is a substantial history of frequency analysis of blood pressure traces.
So you might consider an application of time series frequency analysis. The artifacts seem to have either much lower or much higher frequency components (flat resp. noisy traces) than the normal blood pressure traces do, so detecting breaks over time in the frequency components of the signal might work well. See the Frequency Analysis and the Decomposition and Filtering sections of the CRAN Task View for Time Series. The kza package in particular includes facilities for break detection, with an example in its manual.
Distinguishing true signals from artifacts in blood pressure, pulse-oximeter and electrocardiogram traces is of great practical importance for clinical device manufacturers, medical professionals, and patients. I've seen artifacts cut out or noted electronically on pulse-oximeter and electrocardiogram traces when visiting friends in the hospital, so there probably already are real-time solutions for this problem, although they might be covered by intellectual property restrictions rather than being open-source.
