Files
DP44/Common/DTS.Common.Calculations/.svn/pristine/91/91c9dc003d72bb0a0b68f17d7743459a53906712.svn-base
2026-04-17 14:55:32 -04:00

29 lines
1.1 KiB
Plaintext

namespace DTS.Common.Calculations
{
public static class Integral
{
/// <summary>
/// integrates a channel over an interval
/// </summary>
/// <param name="input">data to integrate</param>
/// <param name="start">index to start integration at (inclusive)</param>
/// <param name="end">index to end integration at (inclusive)</param>
/// <returns></returns>
public static double DefiniteIntegral(double[] input, int start, int end, double SPS)
{
//we use trapezoidal summation to get integral, there is an assumption that the input data is
//tightly time aligned (otherwise we'd have to divide each interval by the actual distance, and not 1/2)
//=(SUMPRODUCT(H25:H56,A26:A57)-SUMPRODUCT(A25:A56,H26:H57)+A57*H57-A25*H25)/2
double d = 0;
for (int i = start + 1; i < end; i++)
{
d += 2D * input[i];
}
d += input[start];
d += input[end];
return .5D * d / SPS;
}
}
}