fisher1D.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import numpy
  2. import matplotlib.pyplot
  3. import scipy.special
  4. def generateAlgebra(w,o,bw,FWHM,R):
  5. sigma=FWHM/2.35
  6. ctr=0.5*o.size
  7. #w=numpy.zeros([n,n])
  8. q=bw/numpy.sqrt(2)
  9. for i in numpy.arange(o.size):
  10. for j in numpy.arange(o.size):
  11. w[i,j]=0.5*(scipy.special.erf(q*(j-i+0.5)/sigma)-
  12. scipy.special.erf(q*(j-i-0.5)/sigma))
  13. #o=numpy.zeros(n)
  14. p=0
  15. for i in numpy.arange(o.size):
  16. if numpy.abs(i-ctr)<R/bw:
  17. o[i]=1
  18. p+=1;
  19. o/=numpy.sqrt(p)
  20. def SNR(o,w):
  21. return numpy.dot(numpy.dot(o,w),o)/\
  22. numpy.sqrt(numpy.dot(numpy.dot(numpy.dot(o,w),w),o))
  23. def Noise(o,w):
  24. return numpy.sqrt(numpy.dot(numpy.dot(numpy.dot(o,w),w),o))
  25. def Signal(o,w):
  26. return numpy.dot(numpy.dot(o,w),o)
  27. def graphSNR(n,bw,x,R,var):
  28. s=numpy.zeros(x.size)
  29. w=numpy.zeros([n,n])
  30. o=numpy.zeros(n)
  31. for i in numpy.arange(x.size):
  32. generateAlgebra(w,o,bw,x[i],R)
  33. if var=="SNR":
  34. s[i]=SNR(o,w)
  35. if var=="Signal":
  36. s[i]=Signal(o,w)
  37. if var=="Noise":
  38. s[i]=Noise(o,w)
  39. return s