简体   繁体   中英

How to get log-normal distribution (i.e. a normal distribution in dB) with a zero mean and a standard deviation of σ = 2 dB for 600 values in python?

I tried looking at the following option.

numpy.random.lognormal(0, 2, 600) - My doubts in this method is that, are the input parameters in dB? If so, mu = 0, and sigma = 2. If the input parameters are supposed to be in linear values, the input parameters should be mu = 1, sigma = 10^0.2. Another question is, are the resulting random value in linear or in dB? If they are in linear, I need to take a 10*math.log10() of these values.

The documentation in http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.random.lognormal.html does not give any information regarding the input parameters being linear or in dB or neither about the nature of the output results.

If x is log-normally distributed then log(x) will be normally distributed. If you're unsure what the parameters refer to then you could just draw some samples, take the log of them and then compute the mean and standard deviation:

import numpy as np

np.random.seed(0)

mu, sigma = 1, 2
x = np.random.lognormal(mu, sigma, 10000)
logx = np.log(x)

print(logx.mean(), logx.std())
# 0.963132559683 1.97511313635

So np.random.lognormal(mu, sigma, ...) draws samples from a random variable whose logarithm is normally distributed with mean mu and standard deviation sigma . In other words, if mu and sigma are specified in logarithmic units then the samples will be in linear units.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM