2
$\begingroup$

List plot of data

The image above is the list plot of discrete data I'm working on. Please I need help on how to zero out all the high amplitudes signal from the data. That is all the data in areas circled, I want to make the zeros. The data has Dimensions {24,1400}. That is 24 traces versus 1400 samples. For example, the 3rd and 11th samples in the list below, I want to make them zero, irrespective of their signs(either +ve or -ve). And repeat the same for the whole 24 traces. In other word, I need a code that will search for certain range of values in the list and make them zero.

{{0.098952, 0.099761, 80, 0.18767, 0.06777, -0.20674, -0.14114, 0.091522, -0.040536, -0.37627, -60, -0.22996, -0.35529}}

$\endgroup$

closed as off-topic by Daniel Lichtblau, corey979, MarcoB, Henrik Schumacher, Bill Watts Feb 20 at 5:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Daniel Lichtblau, corey979, Henrik Schumacher, Bill Watts
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$
data = {{0.098952, 0.099761, 80, 0.18767, 0.06777, -0.20674, -0.14114, 
    0.091522, -0.040536, -0.37627, -60, -0.22996, -0.35529}};

If a symmetric threshold is known,

threshold = 1;

Map[If[Abs[#] > threshold, 0, #] &, data, {2}]

(* {{0.098952, 0.099761, 0, 0.18767, 0.06777, -0.20674, -0.14114, 
  0.091522, -0.040536, -0.37627, 0, -0.22996, -0.35529}} *)

Or for asymmetric thresholds

low = -3; hi = 4;

Map[If[low <= # <= hi, #, 0] &, data, {2}]

(* {{0.098952, 0.099761, 0, 0.18767, 0.06777, -0.20674, -0.14114, 
  0.091522, -0.040536, -0.37627, 0, -0.22996, -0.35529}} *)

If the thresholds must be determined on the fly, say within n standard deviations of the mean,

n = 1;

test[x_] := Module[
   {mu = Mean[x], s = StandardDeviation[x]}, 
   If[(mu - n*s) <= # <= (mu + n*s), #, 0] & /@ x];    

test /@ data


(* {{0.098952, 0.099761, 0, 0.18767, 0.06777, -0.20674, -0.14114, 
  0.091522, -0.040536, -0.37627, 0, -0.22996, -0.35529}} *)
$\endgroup$
3
$\begingroup$

You can use three-argument form of Clip with {0,0} as the third argument:

Clip[$x$,{$min$,$max$},{$v_{min}$, $v_{max}$}] gives $v_{min}$ for $x<min$ and $v_{max}$ for $x>max$.

ClearAll[cliP]
cliP[d_, lo_, hi_] := Clip[d, {lo, hi}, {0, 0}]

data = {0.098952, 0.099761, 80, 0.18767, 0.06777, -0.20674, -0.14114,
 0.091522, -0.040536, -0.37627, -60, -0.22996, -0.35529};
cliP[data, -1, 1]

{0.098952, 0.099761, 0, 0.18767, 0.06777, -0.20674, -0.14114, 0.091522, -0.040536, -0.37627, 0, -0.22996, -0.35529}

ListLinePlot[{ data, cliP[data, -1, 1]},
 PlotRange -> {-1, 1}, 
 ClippingStyle -> Dashed, 
 PlotStyle -> {Directive[Opacity[1], Blue, Thick, Dotted], 
   Directive[Opacity[.5], Red, Thick]} 
 PlotLegends -> {"data", "cliP[data, -1,1]"}]

enter image description here

$\endgroup$
2
$\begingroup$

You can accomplish this using Clip, and then sending the clipped values to zero. For example, if the extreme values are +1 and -1:

Clip[data, {-1, 1}] /. {1 -> 0, -1 -> 0}
$\endgroup$

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