How to make a Gaussian filter in Matlab

here’s an alternative: Create the 2D-Gaussian: function f=gaussian2d(N,sigma) % N is grid size, sigma speaks for itself [x y]=meshgrid(round(-N/2):round(N/2), round(-N/2):round(N/2)); f=exp(-x.^2/(2*sigma^2)-y.^2/(2*sigma^2)); f=f./sum(f(:)); Filtered image, given your image is called Im: filtered_signal=conv2(Im,gaussian2d(N,sig),’same’); Here’s some plots: imagesc(gaussian2d(7,2.5)) Im=rand(100);subplot(1,2,1);imagesc(Im) subplot(1,2,2);imagesc(conv2(Im,gaussian2d(7,2.5),’same’));

JavaScript Math.random Normal distribution (Gaussian bell curve)?

Since this is the first Google result for “js gaussian random” in my experience, I feel an obligation to give an actual answer to that query. The Box-Muller transform converts two independent uniform variates on (0, 1) into two standard Gaussian variates (mean 0, variance 1). This probably isn’t very performant because of the sqrt, … Read more

Gaussian fit for Python

Here is corrected code: import pylab as plb import matplotlib.pyplot as plt from scipy.optimize import curve_fit from scipy import asarray as ar,exp x = ar(range(10)) y = ar([0,1,2,3,4,5,4,3,2,1]) n = len(x) #the number of data mean = sum(x*y)/n #note this correction sigma = sum(y*(x-mean)**2)/n #note this correction def gaus(x,a,x0,sigma): return a*exp(-(x-x0)**2/(2*sigma**2)) popt,pcov = curve_fit(gaus,x,y,p0=[1,mean,sigma]) plt.plot(x,y,’b+:’,label=”data”) … Read more

Overlay normal curve to histogram in R

Here’s a nice easy way I found: h <- hist(g, breaks = 10, density = 10, col = “lightgray”, xlab = “Accuracy”, main = “Overall”) xfit <- seq(min(g), max(g), length = 40) yfit <- dnorm(xfit, mean = mean(g), sd = sd(g)) yfit <- yfit * diff(h$mids[1:2]) * length(g) lines(xfit, yfit, col = “black”, lwd = … Read more