/// <summary> /// Interpolation by the Newton Interpolation Polynomial. Factor must be >= 2 /// </summary> /// <returns></returns> public static Signal InterpolateNewtonForm(Signal signal, uint factor) { if (factor < 2) { return(signal.Clone()); } var n = signal.Samples.Length; var newSignal = signal.Copy(); var newSamples = MemoryPool.Pool.New <double>(Convert.ToInt32(signal.Samples.Length * factor - factor + 1)); var time = signal.GetTimeSeries(); var coeffs = NewtonDivDiff(n, time, signal.Samples); var newInterval = Convert.ToDecimal(signal.SamplingInterval / factor); var currentX = Convert.ToDecimal(signal.Start); for (var i = 0; i < newSamples.Length; i++) { newSamples[i] = NewtonEval(n, time, coeffs, Convert.ToDouble(currentX)); currentX += newInterval; } newSignal.Samples = newSamples; newSignal.SamplingInterval = Convert.ToDouble(newInterval); return(newSignal); }
/// <summary> /// Cubic interpolation. Factor must be >= 2 /// </summary> /// <returns></returns> public static Signal InterpolateCubic(Signal signal, uint factor) { if (factor < 2) { return(signal.Clone()); } var n = signal.Samples.Length; var newSignal = signal.Copy(); var newSamples = MemoryPool.Pool.New <double>(Convert.ToInt32(signal.Samples.Length * factor - factor + 1)); var time = signal.GetTimeSeries(); var b = MemoryPool.Pool.New <double>(n); var c = MemoryPool.Pool.New <double>(n); var d = MemoryPool.Pool.New <double>(n); CubicNak(n, time, signal.Samples, ref b, ref c, ref d); var newInterval = Convert.ToDecimal(signal.SamplingInterval / factor); var currentX = Convert.ToDecimal(signal.Start); for (var i = 0; i < newSamples.Length; i++) { newSamples[i] = SplineEval(n, time, signal.Samples, b, c, d, Convert.ToDouble(currentX)); currentX += newInterval; } newSignal.Samples = newSamples; newSignal.SamplingInterval = Convert.ToDouble(newInterval); MemoryPool.Pool.RegisterObject(b); MemoryPool.Pool.RegisterObject(c); MemoryPool.Pool.RegisterObject(d); return(newSignal); }
public sSensorSettings Copy() { sSensorSettings result = new sSensorSettings(); result.GlobalSignal = GlobalSignal.Copy(); result.Signal = Signal.Copy(); result.Scale = Scale; result.OpticalProbesBase = OpticalProbesBase; result.IpAddress = IpAddress; result.LedIntensity = LedIntensity; result.AutoConnectMode = AutoConnectMode; result.HighSpeed = HighSpeed.Copy(); result.Threshold = Threshold; result.Identification = Identification; return(result); }
/// <summary> /// Repeat samples /// </summary> public static Signal Repeat(Signal signal, uint frameSize, uint repetitionCount, bool keepSamplingRate) { var output = signal.Copy(); output.Samples = Repeat(signal.Samples, frameSize, repetitionCount); if (keepSamplingRate) { output.Finish = output.Start + output.SamplesCount * output.SamplingInterval - output.SamplingInterval; } else { output.SamplingInterval = Math.Abs(signal.Finish - signal.Start) / output.SamplesCount; } return(output); }
///<summary>Sets the specified buttonIndex to a color and attaches the signal responsible. This is also used for the manual ack to increase responsiveness. buttonIndex is 0-based.</summary> public void SetButtonActive(int buttonIndex, Color color, Signal activeSignal) { if (buttonIndex >= sigButStates.Length) { return; //no button to light up. } sigButStates[buttonIndex].CurrentColor = color; if (activeSignal == null) { sigButStates[buttonIndex].ActiveSignal = null; } else { sigButStates[buttonIndex].ActiveSignal = activeSignal.Copy(); } Invalidate(); }
/// <summary> /// Nearest interpolation. Factor must be >= 2 /// </summary> /// <returns></returns> public static Signal InterpolateNearest(Signal signal, uint factor) { if (factor < 2) { return(signal.Clone()); } var newSignal = signal.Copy(); var newSamples = MemoryPool.Pool.New <double>(Convert.ToInt32(signal.Samples.Length * factor - factor + 1)); var currentIndex = 0; var newInterval = signal.SamplingInterval / factor; var currentX = signal.Start; var newX = currentX; for (var i = 0; i < signal.SamplesCount; i++) { if (i == signal.SamplesCount - 1) { newSamples[currentIndex] = signal.Samples[i]; break; } var y0 = signal.Samples[i]; var y1 = signal.Samples[i + 1]; var x0 = currentX; var x1 = currentX + signal.SamplingInterval; for (var j = 0; j < factor; j++) { if (newX - x0 < x1 - newX) { newSamples[currentIndex] = y0; } else { newSamples[currentIndex] = y1; } currentIndex++; newX += newInterval; } currentX = x1; } newSignal.Samples = newSamples; newSignal.SamplingInterval = newInterval; return(newSignal); }
/// <summary> /// Repeat samples /// </summary> public static Signal Repeat(Signal signal, uint frameSize, uint repetitionCount, bool keepSamplingRate) { var output = signal.Copy(); output.Samples = Repeat(signal.Samples, frameSize, repetitionCount); if (keepSamplingRate) output.Finish = output.Start + output.SamplesCount * output.SamplingInterval - output.SamplingInterval; else output.SamplingInterval = Math.Abs(signal.Finish - signal.Start) / output.SamplesCount; return output; }