adding noise to a signal in python
Question: I want to add some random noise to some 100 bin signal that I am simulating in
Python - to make it more realistic.

On a basic level, my first thought was to go bin by bin and just generate a
random number between a certain range and add or subtract this from the
signal.

I was hoping (as this is python) that there might a more intelligent way to do
this via numpy or something. (I suppose that ideally a number drawn from a
gaussian distribution and added to each bin would be better also.)

Thank you in advance of any replies.

* * *

I'm just at the stage of planning my code, so I don't have anything to show. I
was just thinking that there might be a more sophisticated way of generating
the noise.

In terms out output, if I had 10 bins with the following values:

Bin 1: 1 Bin 2: 4 Bin 3: 9 Bin 4: 16 Bin 5: 25 Bin 6: 25 Bin 7: 16 Bin 8: 9
Bin 9: 4 Bin 10: 1

I just wondered if there was a pre-defined function that could add noise to
give me something like:

Bin 1: 1.13 Bin 2: 4.21 Bin 3: 8.79 Bin 4: 16.08 Bin 5: 24.97 Bin 6: 25.14 Bin
7: 16.22 Bin 8: 8.90 Bin 9: 4.02 Bin 10: 0.91

If not, I will just go bin-by-bin and add a number selected from a gaussian
distribution to each one.

Thank you.

* * *

It's actually a signal from a radio telescope that I am simulating. I want to
be able to eventually choose the signal to noise ratio of my simulation.


Answer: You can generate a noise array, and add it to your signal

    
    
    import numpy as np
    
    noise = np.random.normal(0,1,100)
    
    # 0 is the mean of the normal distribution you are choosing from
    # 1 is the standard deviation of the normal distribution
    # 100 is the number of elements you get in array noise
    

