本文整理汇总了C#中Sample.Skip方法的典型用法代码示例。如果您正苦于以下问题:C# Sample.Skip方法的具体用法?C# Sample.Skip怎么用?C# Sample.Skip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample.Skip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterData
public Sample<float>[] FilterData(Sample<float>[] input)
{
if (input == null)
return null;
Sample<float>[] output = new Sample<float>[input.Length];
// Get values and duration of the values
Sample<float>[] values = new Sample<float>[input.Length];
for (int i = 0; i < input.Length; i++)
{
TimeSpan startTime;
if (i == 0)
startTime = input[i].Time - halfWindowWidth;
else
startTime = TimeSpan.FromSeconds((input[i - 1].Time + input[i].Time).TotalSeconds / 2f);
values[i] = new Sample<float>(new Sample<float>(startTime, input[i].Value));
}
/*
for (int i = 0; i < input.Length; i++)
{
float value = input[i].Value;
TimeSpan startTime;
TimeSpan endTime;
if (i == 0)
{
startTime = input[i].Time - windowWidth;
endTime = (input[i].Time + input[i + 1].Time).TotalSeconds / 2f;
}
else if (i == input.Length - 1)
{
startTime = TimeSpan.FromSeconds((input[i - 1].Time + input[i].Time).TotalSeconds / 2f);
TimeSpan endTime = input[i].Time + windowWidth;
duration = (float)(endTime - startTime).TotalSeconds;
}
else
{
startTime = TimeSpan.FromSeconds((input[i - 1].Time.TotalSeconds + input[i].Time.TotalSeconds) / 2f);
double endTime = (input[i].Time + input[i + 1].Time).TotalSeconds / 2f;
duration = (float)(endTime - startTime.TotalSeconds);
}
values[i] = new Pair<Sample<float>,TimeSpan>(new Sample<float>(startTime, value), duration);
}
*/
// Filter data
int kernelStart = 0; // Points to first sample in kernel
int kernelEnd = 0; // Points to next sample that will be put into kernel
for (int i = 0; i < input.Length; i++)
{
Sample<float> inputSample = input[i];
TimeSpan windowStart = input[i].Time - halfWindowWidth;
TimeSpan windowEnd = input[i].Time + halfWindowWidth;
// Remove old samples from kernel
while(kernelStart < input.Length - 1 && values[kernelStart+1].Time <= windowStart)
{
kernelStart++;
}
// Add new samples to kernel
while (kernelEnd < input.Length && values[kernelEnd].Time < windowEnd)
{
kernelEnd++;
}
// Calculate weights for each sample
float[] weights = new float[kernelEnd - kernelStart];
for (int j = 0; j < weights.Length; j++)
{
double startTime = values[kernelStart + j].Time.TotalSeconds;
double endTime;
if(kernelStart + j == values.Length - 1)
endTime = windowEnd.TotalSeconds;
else
endTime = values[kernelStart + 1 + j].Time.TotalSeconds;
double intersectStart = Math.Max(startTime, windowStart.TotalSeconds);
double intersectEnd = Math.Min(endTime, windowEnd.TotalSeconds);
weights[j] = (float)((intersectEnd - intersectStart) / windowWidth.TotalSeconds);
}
//weights[0] = (float)((values[kernelStart+1].Time - windowStart).TotalSeconds / windowWidth.TotalSeconds);
//weights[weights.Length-1] = (float)((values[kernelEnd].Time - windowEnd).TotalSeconds / windowWidth.TotalSeconds);
// Apply kernel
float result = input.Skip(kernelStart).Take(kernelEnd - kernelStart).Zip(weights, (x,y) => x.Value * y).Sum();
// Set output
output[i] = new Sample<float>(input[i].Time, result);
}
return output;
}
示例2: GetMinimumSamplesPerSecond
public static float GetMinimumSamplesPerSecond(Sample<float>[] data)
{
// Find minimum time between samples
TimeSpan minTime = data.Skip(1).Zip(data, (x, y) => x.Time - y.Time).Min();
return (float)(1.0f / minTime.TotalSeconds);
}