当前位置: 首页>>代码示例>>C#>>正文


C# Sample.Last方法代码示例

本文整理汇总了C#中Sample.Last方法的典型用法代码示例。如果您正苦于以下问题:C# Sample.Last方法的具体用法?C# Sample.Last怎么用?C# Sample.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sample的用法示例。


在下文中一共展示了Sample.Last方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reset

        /*
        public override void Reset()
        {
            oldData = new Sample<float>(TimeSpan.MinValue, 0);
            return;
        }
        */
        public Sample<float>[] FilterData(Sample<float>[] data)
        {
            Sample<float>[] output = new Sample<float>[data.Length];
            for (int i = 0; i < output.Length; i++)
            {
                Sample<float> firstValue;
                if (i == 0)
                    firstValue = oldData;
                else
                    firstValue = data[i - 1];

                Sample<float> secondValue = data[i];

                output[i] = new Sample<float>(secondValue.Time, (secondValue.Value - firstValue.Value) / (float)(secondValue.Time - firstValue.Time).TotalSeconds);
            }

            oldData = data.Last();
            return output;
        }
开发者ID:Faham,项目名称:emophiz,代码行数:26,代码来源:NonUniformDifferentiator.cs

示例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;
        }
开发者ID:Faham,项目名称:emophiz,代码行数:59,代码来源:InterpolatingFilter.cs


注:本文中的Sample.Last方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。