本文整理汇总了C#中Sample.First方法的典型用法代码示例。如果您正苦于以下问题:C# Sample.First方法的具体用法?C# Sample.First怎么用?C# Sample.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sample
的用法示例。
在下文中一共展示了Sample.First方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sensor_DataAvailable
void sensor_DataAvailable(ISensor<Sample<EyeData>> sensor, Sample<EyeData>[] data)
{
Console.WriteLine(data.First().Time.TotalSeconds);
return;
}
示例2: FilterData
//!! Need to eliminate some high frequencies?
//!! Need to make real-time!
//!! Does not take into account the offset!
//!! Should allow cubic spline (matlab: spline() )
//!! Should start samples at the first uniform sample?
public SampleSet<float> FilterData(Sample<float>[] input)
{
if (AutoSampleRate)
{
// Find minimum time between samples
samplesPerSecond = GetMinimumSamplesPerSecond(input);
}
TimeSpan minTime = TimeSpan.FromSeconds(1.0f / samplesPerSecond);
// Get new sample times
float[] newSampleTimesArray =
Enumerable.Range(0, int.MaxValue).
Select(x => (float)(x / samplesPerSecond)).
TakeWhile(x => x <= input.Last().Time.TotalSeconds).
ToArray();
//float[] newSampleTimesArray =
// Enumerable.Range(0, int.MaxValue).
// Select(x => (float)(input.First().Time.TotalSeconds + (x / samplesPerSecond))).
// TakeWhile(x => x <= input.Last().Time.TotalSeconds).
// ToArray();
// Create a list of new samples
SampleSet<float> output = new SampleSet<float>(TimeSpan.Zero, samplesPerSecond, newSampleTimesArray.Length);
int outputCount = 0;
// Add first point
output.Values[0] = input.First().Value;
outputCount++;
// Linearly interpolate points
Sample<float> lastSample = new Sample<float>(TimeSpan.Zero, 0);
foreach (Sample<float> sample in input)
{
double m = (sample.Value - lastSample.Value) / (sample.Time - lastSample.Time).TotalSeconds;
double b = lastSample.Value;
double p = lastSample.Time.TotalSeconds;
while (outputCount < newSampleTimesArray.Length && newSampleTimesArray[outputCount] <= sample.Time.TotalSeconds)
{
float newTime = newSampleTimesArray[outputCount];
// Interpolate value
output.Values[outputCount] = (float)((newTime - p) * m + b);
outputCount++;
}
lastSample = sample;
}
//Return filtered data
return output;
}