/* * The point on the Y - axis where the line Y = A + BX intercepts it is given by the equation: * A = [(SUM(Y))*(SUM(SQUARE(X))) - (SUM(X))*(SUM(X*Y))] / [N*SUM(SQUARE(X)) - SQUARE((SUM(X)))]. * * * * The slope of the line Y = A + BX is given by the equation: * B = N*SUM(X*Y) - (SUM(X))*(SUM(Y)) / [N*SUM(SQUARE(X)) - SQUARE((SUM(X))] * * * * The correlation coefficient of the line Y = A + BX where 0 means no correlation and 1 means perfect * correlation is given by the equation: * R = N*SUM(X*Y) - (SUM(X))*(SUM(Y)) / SQRT[N*SUM(SQUARE(X)) - SQUARE(SUM(X))]*SQRT[N*SUM(SQUARE(Y)) - SQUARE((SUM(Y)))] */ public void Coefficients(out double a, out double b, out double r) { double x2sum = ArrayMath.Sum(ArrayMath.Pow(X, 2)); double xsum2 = Math.Pow(ArrayMath.Sum(X), 2); double ysum = ArrayMath.Sum(Y); double y2sum = ArrayMath.Sum(ArrayMath.Pow(Y, 2)); double ysum2 = Math.Pow(ArrayMath.Sum(Y), 2); double xsum = ArrayMath.Sum(X); double xysum = ArrayMath.Sum(ArrayMath.Multiply(X, Y)); a = (ysum * x2sum - xsum * xysum) / (N * x2sum - xsum2); b = (N * xysum - xsum * ysum) / (N * x2sum - xsum2); r = (N * xysum - xsum * ysum) / (Math.Sqrt(N * x2sum - xsum2) * Math.Sqrt(N * y2sum - ysum2)); }
public Complex[] DoFFT(double[] d, WindowBase window) { double M = d.Length; double[] dwindow = window.Calc((int)M); ArrayMath.Multiply(ref d, ref dwindow); Complex[] fft = Run(d); Complex[] spec = new Complex[fft.Length / 2]; for (int i = 1; i < fft.Length / 2 + 1; i++) { spec[i - 1].Real = fft[i].Real * 2 / M; spec[i - 1].Imag = fft[i].Imag * 2 / M; } return(spec); }