123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import numpy
- import matplotlib.pyplot
- import scipy.special
- def generateAlgebra(w,o,bw,FWHM,R):
- sigma=FWHM/2.35
- ctr=0.5*o.size
- #w=numpy.zeros([n,n])
- q=bw/numpy.sqrt(2)
- for i in numpy.arange(o.size):
- for j in numpy.arange(o.size):
- w[i,j]=0.5*(scipy.special.erf(q*(j-i+0.5)/sigma)-
- scipy.special.erf(q*(j-i-0.5)/sigma))
- #o=numpy.zeros(n)
- p=0
- for i in numpy.arange(o.size):
- if numpy.abs(i-ctr)<R/bw:
- o[i]=1
- p+=1;
- o/=numpy.sqrt(p)
- def SNR(o,w):
- return numpy.dot(numpy.dot(o,w),o)/\
- numpy.sqrt(numpy.dot(numpy.dot(numpy.dot(o,w),w),o))
- def Noise(o,w):
- return numpy.sqrt(numpy.dot(numpy.dot(numpy.dot(o,w),w),o))
- def Signal(o,w):
- return numpy.dot(numpy.dot(o,w),o)
- def graphSNR(n,bw,x,R,var):
- s=numpy.zeros(x.size)
- w=numpy.zeros([n,n])
- o=numpy.zeros(n)
- for i in numpy.arange(x.size):
- generateAlgebra(w,o,bw,x[i],R)
- if var=="SNR":
- s[i]=SNR(o,w)
- if var=="Signal":
- s[i]=Signal(o,w)
- if var=="Noise":
- s[i]=Noise(o,w)
- return s
|