0
$\begingroup$

I have time series data with $x$, $y$, $z$ sampled at $50\textrm{ Hz}$ from a sensor and I would like to add a uniform and Laplace noise to it. How would I achieve this in Python?

$\endgroup$

closed as off-topic by MBaz, Matt L., Laurent Duval, Peter K. Dec 30 '16 at 19:07

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

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – MBaz, Matt L., Peter K.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Could you please recommend the right site for such a question? I posted a similar question on stackoverflow.com and I haven't gotten any response yet here I got someone who gave me a hint which I am trying out. $\endgroup$ – DSPNewbie Jan 2 '17 at 5:41
0
$\begingroup$

Some comments:

  1. I'm not sure if this is the right forum for python questions.
  2. You left some relevant information, like the type of variable your data is stored.
  3. I assume that "la place" is laplace distribution.

Please see if this helps, and make the necessary adjustments:

import numpy as np
def fn_addnoise(data):
    i = len(data)
    # create 1D numpy data:
    npdata = np.asarray(data).reshape((i))
    # add uniform noise:
    u = npdata + np.random.uniform(size=npdata.shape)
    # add laplace noise:
    p = npdata + np.random.laplace(loc=0.0, scale=1.0, size=npdata.shape)

    print npdata
    print u
    print p
    return u,p
# 'data' might be a tuple...
data = (1,2,3,4,5,6)
# or a list...
data = [1,2,3,4,5,6,7]
fn_addnoise(data)
$\endgroup$

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