Skip to main content

CDF of Gaussian distribution

The cumulative distribution function (CDF) of Gaussian distribution with standard deviation (sig) and mean (cen) in python

Ref: 

https://www.mathworks.com/help/matlab/ref/erf.html

https://introcs.cs.princeton.edu/java/11gaussian/


===============================================

python code:

================================================

from scipy import special

import matplotlib.pyplot as plt

import numpy as np


def erfValue(x, cen, sig):

    #           1                 x - cen

    # erf(x) = --- (1 + erf(-----------------))

    #           2             sqrt(2) * sig

    return 0.5*(1+special.erf((x-cen)/(np.sqrt(2)*sig)))


def erfcValue(x, cen, sig):

    return 1-erfValue(x, cen, sig)


cen = 9.54

sig=2

xx = np.arange(0,20,step=.01)

erf = erfValue(xx, cen, sig)

plt.figure()

plt.plot(xx,erf,'r')


x1 = cen

y1 = erfValue(x1, cen, sig)

plt.plot(x1, y1, 'k.')

plt.text(x1, y1, "(%.2f, %.2f)"%(x1,y1))


x2 = cen+sig

y2 = erfValue(x2, cen, sig)

plt.plot(x2, y2, 'k.')

plt.text(x2, y2, "(%.2f, %.2f)"%(x2,y2))


x3 = cen-sig

y3 = erfValue(x3, cen, sig)

plt.plot(x3, y3, 'k.')

plt.text(x3, y3, "(%.2f, %.2f)"%(x3,y3))


plt.title("erf curve")

plt.show()


erfc = erfcValue(xx, cen, sig)

plt.figure()

plt.plot(xx,erfc,'b')


x1 = cen

y1 = erfcValue(x1, cen, sig)

plt.plot(x1, y1, 'k.')

plt.text(x1, y1, "(%.2f, %.2f)"%(x1,y1))


x2 = cen+sig

y2 = erfcValue(x2, cen, sig)

plt.plot(x2, y2, 'k.')

plt.text(x2, y2, "(%.2f, %.2f)"%(x2,y2))


x3 = cen-sig

y3 = erfcValue(x3, cen, sig)

plt.plot(x3, y3, 'k.')

plt.text(x3, y3, "(%.2f, %.2f)"%(x3,y3))


plt.title("erfc curve")

plt.show()


================================================




Comments

Popular posts from this blog

Top hat filter

The top_hat filter can be used to detect the relatively small edges/peaks superimposed on large background signals. The concept came from the EELS workshop during IMC19. Thanks to Prof. Nestor J. Zaluzec. -- // Using Top_hat digital filter to detect the  relatively small edges  //    superimposed on large background signals. // // ref: Ultramicroscopy 18 (1985) 185-190  //      Digital Filters  for Application to Data Analysis in EELS //      by Nestor J. ZALUZEC // Parameters: // win_s: signal window (default:3) // win_b: background window (default:3) //  a_s : amplitude of signal (fixed value) //  a_b : amplitude of background  (fixed value) // Renfong 2018/10/11 // Main function image Top_Hat_Filter(image img, number win_s, number win_b) { // read image string fname=img.GetName() number sx,sy img.getsize(sx,sy) // filter image img2 := imageclone(img)*0 //the area between...

HyperSpy - read the calibration information in a dm3/dm4 file

Some example of dm3 file reading by using Python HyperSpy package, which can read the detail information of the dm file. -- # import packages import numpy as np import hyperspy.api as hs # load file sp=hs.load('sp.dm3') # Read the axis information      # Print all the calibration detail print(sp.axes_manager) ''' <Axes manager, axes: (272|2042)>             Name |   size |  index |  offset |   scale |  units  ================ | ======= | ====== | ======= | ======= | ======                     x |    272 |      0 |       -0 |  0.0025 |     µm   --------------- |  ------ | ----- |  ------ | ------- | ------    Energy loss |  2042 |         | 3.2e+02 |       1 |     eV...

Drift correction in Matlab

In order to improve S/N ratio, microscopist uses several short acquisition time images, and then sum them up. So the drift correction is very important. Here is the demo of how to use Matlab do drift correction. In the first, load an image, and using circshift function to shift the object in the image. Then use fft cross correlation to compute the moving distance. Finally, shift the object to the origial position. Here is the testing code: == % Demo of drift correction % 2018/11/15  by Renfong im1= imread('cameraman.tif');    % reference image [sy,sx]=size(im1); % shift the object im2=circshift(im1,[20,10]);    % the object moved down 20 pixels and moved right 10 pixels. figure(1); subplot(121);imshow(im1); subplot(122);imshow(im2); % Using fft cross correlations to detect the moving distance[1] fftim1=fft2(im1); fftim2=fft2(im2); cc=fftshift(ifft2(fftim1.*conj(fftim2))); [shiftY,shiftX]=find(cc==max(cc(:))...