4
$\begingroup$

I have a data set where I often get pairs of spikes that occur randomly but the pair is always separated within $n$ places of each other. I.e. the spacing between the pairs, in index, is always constant.

Is there a way, given some other condition to pick out the first spike (I use something like Select[IndexedData[[1;;,{1,2,3}]], #[[3]] > threshold &])to then remove the $n \pm1$ points after this peak?

$\endgroup$
  • 1
    $\begingroup$ Can you provide a sample of the data to work with? Also, do you know "n" or is that something that you don't know a priori? $\endgroup$ – Fraccalo Jun 7 '18 at 12:44
  • $\begingroup$ @Fraccalo I know that $n$ is always 41. I will attach a data sample now... $\endgroup$ – Q.P. Jun 7 '18 at 12:56
4
$\begingroup$

If I understand the question correctly, you may use something like

data[[Complement[Range@len, n + 1 + peaks]]]

where I'm assuming one-dimensional data for simplicity, len is the size of your dataset and peaks is a list of positions for your peaks.

For example, take

n = 3;
len = 20;
data = RandomInteger[100, len]

giving the following sample data:

{72, 5, 36, 57, 97, 95, 86, 11, 5, 4, 35, 82, 59, 88, 6, 53, 6, 100, 39, 53}

then you find the peak positions with

peaks = Select[Range@len, data[[#]] > 90 &]

giving in this case

{5, 6, 18}

Then the line above results in

{72, 5, 36, 57, 97, 86, 11, 4, 35, 88, 6, 53, 100, 39}
$\endgroup$
1
$\begingroup$

You may want to look at Pick. For example, using Fidel's data for consistency:

n = 3;
len = 20;
data = {72, 5, 36, 57, 97, 95, 86, 11, 5, 4, 35, 82, 59, 88, 6, 53, 6, 100, 39, 53};

mask = UnitStep[90 - data]
mask *= PadRight[mask, len, 1, n]

Pick[data, mask, 1]
{1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1}
{1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1}

{72, 5, 36, 57, 86, 4, 35, 82, 59, 88, 6, 53, 6, 39, 53}

Note that here I drop both the detected peaks at positions 5, 6, 18 and also the elements offset by three. If you choose this method reference UnitStep, PadRight, TimesBy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.