1 | /** |
---|
2 | * Gaussian function |
---|
3 | */ |
---|
4 | |
---|
5 | #include "gaussian.h" |
---|
6 | #include <math.h> |
---|
7 | #include <stdio.h> |
---|
8 | #include <stdlib.h> |
---|
9 | |
---|
10 | |
---|
11 | /** |
---|
12 | * Function to evaluate 1D Gaussian function. |
---|
13 | * The function is normalized to the 'scale' parameter. |
---|
14 | * |
---|
15 | * f(x)=scale * 1/(sigma^2*2pi)e^(-(x-mu)^2/2sigma^2) |
---|
16 | * |
---|
17 | * @param pars: parameters of the gaussian |
---|
18 | * @param x: x-value |
---|
19 | * @return: function value |
---|
20 | */ |
---|
21 | double gaussian_analytical_1D(GaussianParameters *pars, double x) { |
---|
22 | double sigma2 = pow(pars->sigma, 2); |
---|
23 | return pars->scale / sigma2 * exp( -pow((x-pars->center), 2) / (2*sigma2)); |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * Function to evaluate 2D Gaussian function |
---|
28 | * The function is normalized to the 'scale' parameter. |
---|
29 | * |
---|
30 | * f(x,y) = Gaussian(x) * Gaussian(y) |
---|
31 | * |
---|
32 | * where both Gaussians share the same parameters. |
---|
33 | * |
---|
34 | * @param pars: parameters of the gaussian |
---|
35 | * @param x: x-value |
---|
36 | * @param y: y-value |
---|
37 | * @return: function value |
---|
38 | */ |
---|
39 | double gaussian_analytical_2DXY(GaussianParameters *pars, double x, double y) { |
---|
40 | return gaussian_analytical_1D(pars, x) * gaussian_analytical_1D(pars, y); |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Function to evaluate 2D Gaussian function |
---|
45 | * The function is normalized to the 'scale' parameter. |
---|
46 | * |
---|
47 | * f(x,y) = Gaussian(x) * Gaussian(y) |
---|
48 | * |
---|
49 | * where both Gaussians share the same parameters. |
---|
50 | * |
---|
51 | * @param pars: parameters of the gaussian |
---|
52 | * @param length: length of the (x,y) vector |
---|
53 | * @param phi: angle relative to x |
---|
54 | * @return: function value |
---|
55 | */ |
---|
56 | double gaussian_analytical_2D(GaussianParameters *pars, double length, double phi) { |
---|
57 | return gaussian_analytical_2DXY(pars, length*cos(phi), length*sin(phi)); |
---|
58 | } |
---|