Noisefloor in a Signal


I am trying to get Tensor Flow to apply a vairable noise floor to some X & Y data. Essentially this:

The problem I am having is that the Boolean Masking function does not return a tensor of the same shape that i fed it. Moreover, I cannot assign a NULL, ZERO or some default value to the cells that are below the cut off. Here is the code I have:

def NoiseFloor(x):
NFValue = tf.Variable(1.,dtype=tf.float64,constraint=lambda t: tf.clip_by_value(t, 10, 20))
y = tf.fill(tf.shape(x), NFValue)
y = tf.cast(y, np.float32)
return(tf.math.greater(x, y))

InputLayer = layers.Dense(5, activation=NoiseFloor, name=“Input_layer”)(TensorRFPower)

The issue is that this returns a T,F array that is of a different overall shape.

So I have been trying to solve this issue with no luck so far. I switched to trying to gain access to the elements in the tensor, so I could use an IF statement to make the element assignments. I tried a couple different functions:

  • tf.tensor_scatter_nd_add(
  • tf.assign_sub(
  • tf.assign(

Accessing the elements in the tensor itself (in v2) seems to be limited. Like I said I can:

  • Get a Bool Array of values above and below the cutoff
  • Apply a Bool Mask to that array and then get the values. But this array is not the same shape.

I also looked at recursive code to step through the elements in this array

def my_elementwise_func(tensorelement):
return tensorelement + 1

def NoiseFloor(x):
if tf.shape(x).ndims > 0:
return tf.map_fn(NoiseFloor, x)
return my_elementwise_func(x)

result = NoiseFloor(x)

I just do not think their isn’t an existing function that works with Tensorflow that does not already do this. I am going to look at SciPy if nobody gets back to me.

Something like this?

def NoiseFloor(x):
     mask = tf.greater(x, 7)
     zeros = tf.zeros(x.shape, tf.int32)
     return tf.where(mask, x, zeros)
inp = tf.constant([1,2,3,4,5,6,7,8,9,10])
out = NoiseFloor(inp)