public static LeastSquares ( double zValues, double xValues, double yValues, double &a, double &b, double &c ) : void | ||
zValues | double | z-value array |
xValues | double | x-value array |
yValues | double | y-value array |
a | double | the out a coefficient |
b | double | the out b coefficient |
c | double | the out c coefficient |
Результат | void |
/// <summary> /// Uses least squares linear regression to calculate the best fit sine wave for the given data. /// </summary> /// <param name="yValues">The y values of the data points.</param> /// <param name="tValues">The time values of the data points, in seconds.</param> /// <param name="frequency">The frequency of the sine wave, in Hz.</param> /// <returns>A <see cref="SineWave"/> approximated from the given data points.</returns> public static SineWave SineFit(double[] yValues, double[] tValues, double frequency) { double[] z = yValues; double[] x = new double[tValues.Length]; double[] y = new double[tValues.Length]; double a, b, d; double rad = 2.0D * Math.PI * frequency; for (int i = 0; i < tValues.Length; i++) { double angle = rad * tValues[i]; x[i] = Math.Sin(angle); y[i] = Math.Cos(angle); } CurveFit.LeastSquares(z, x, y, out d, out a, out b); return(new SineWave { Amplitude = Math.Sqrt(a * a + b * b), Frequency = frequency, Phase = Math.Atan2(b, a), Bias = d }); }
/// <summary> /// Uses least squares linear regression to calculate the best fit sine wave for the given data. /// </summary> /// <param name="yValues">The y values of the data points.</param> /// <param name="tValues">The time values of the data points, in seconds.</param> /// <param name="frequency">The frequency of the sine wave, in Hz.</param> /// <returns>A <see cref="SineWave"/> approximated from the given data points.</returns> public static SineWave SineFit(double[] yValues, double[] tValues, double frequency) { double[] z = yValues; double[] x = tValues.Select(t => Math.Sin(2.0 * Math.PI * frequency * t)).ToArray(); double[] y = tValues.Select(t => Math.Cos(2.0 * Math.PI * frequency * t)).ToArray(); double a, b, d; CurveFit.LeastSquares(z, x, y, out d, out a, out b); return(new SineWave() { Amplitude = Math.Sqrt(a * a + b * b), Frequency = frequency, Phase = Math.Atan2(b, a), Bias = d }); }