diff --git a/src/yapsut/colored_noise.py b/src/yapsut/colored_noise.py index 1ddfc2d012ac86a190e3e415a0e60e55b8a4e41f..8b5b2bbc179ad40259d37f3fe90a30efb158d681 100644 --- a/src/yapsut/colored_noise.py +++ b/src/yapsut/colored_noise.py @@ -49,6 +49,14 @@ class gaussian_colored_noise : def seed(self) : """the seed of the random number generator""" return self._seed + @property + def ps_shape_integral(self) : + """the spectral shape: ps_shape=P(f)**0.5""" + x=self._freq + y=self._S + out=(x[1:]-x[:-1])*(y[1:]+y[:-1]) + out=out.sum()/2. + return out*2 def __init__(self,N,wn_mean,wn_sigma,fknee,alpha,zero_policy='I',seed=None) : """ Creates a gaussian_colored_noise_generator. @@ -76,7 +84,7 @@ Keywords: '100x1' : P(0)**0.5=(1+100*fknee/freq[1])**alpha/2 'midf1' : P(0)=P(f[1]/2) = exp((log P[2]-log P[1])/(log f2 - log f1)*(log f1/2 - log f1)+log P(1)) note that zero_policy affects the mean value of the chunck but not its variance - default value is 'I' that for alpha > 0 gives P(0)=1 + default value is 'I' :seed: the seed for the random number generator, if None no seed is applied otherwise the same seed is applied to any generated sequence """ @@ -87,11 +95,6 @@ Keywords: self._alpha=alpha self._seed=seed # - if str(zero_policy) in ['0','1','M','I','100x1'] : - self._zero_policy = str(zero_policy) - else : - raise Error("Error: invalid zero policy, valid values: '0','1','M','I','100x1'") - # self._freq=np.fft.rfftfreq(self.N) # pl=self.alpha @@ -99,6 +102,7 @@ Keywords: x=self.fknee/np.where(self._freq==0, np.inf , self._freq) self._S=(1+x**pl)**0.5 # + self._zero_policy=zero_policy if self._zero_policy=='0' : self._S[0]=0. elif self._zero_policy=='1' : @@ -115,9 +119,10 @@ Keywords: r=(y2-y1)/(x2-x1) z=r*(np.log(self._freq[1]/2)-x1)+y1 self._S[0]=np.exp(z) - else : # self._zero_policy=='I' : - # left things as they are + elif self._zero_policy=='I' : pass + else : + raise Error("Error: invalid zero policy, valid values: '0','1','M','I','100x1','mid1f'") # def __call__(self,OutAll=False) : """computes the colored noise, if OutAll == False returns just the cn if True returns