/// <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); }
public override void MIDIProcess(Signal n) { Signal m = n.Clone(); MIDIExit?.Invoke(n); screen.MIDIEnter(m); }
/// <summary> /// Executes a relational operation between two or more signals /// </summary> public static Signal ExecuteRelationalOperation(RelationalOperatorEnum operation, Signal signal, double staticValue) { var newSignal = signal.Clone(); newSignal.Samples = ExecuteRelationalOperation(operation, newSignal.Samples, staticValue); return(newSignal); }
/// <summary> /// Executes a relational in a signal, comparing each sample with the next one /// </summary> public static Signal ExecuteRelationalOperationWithNextSample(RelationalOperatorEnum operation, Signal signal) { var newSignal = signal.Clone(); newSignal.Samples = ExecuteRelationalOperationWithNextSample(operation, newSignal.Samples); 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); }
protected override List <Signal> DefaultCalculate(List <Signal> values) { Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(2 * inputSignal); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(handle.GetState()); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; if (leftProduct) { outputSignal.Clone(gain * inputSignal); } else { outputSignal.Clone(inputSignal * gain); } // Results.Add(signal); // validation of input is done somewhere else return(Results); }
private List <Signal> DivisionCalculate(List <Signal> values) { Signal leftSignal = values[0]; Signal rightSignal = values[1]; Signal outputSignal = Results[0]; outputSignal.Clone(leftSignal / rightSignal); return(Results); }
public void TestClone() { var signal = new Signal(new double[] { 1, 2, 3, 4, 5 }, 1); var clone = signal.Clone(); Assert.IsTrue(TestUtils.SequenceEquals(signal.Samples, clone.Samples)); Assert.AreNotSame(signal, clone); Assert.AreNotSame(signal.Samples, clone.Samples); }
private List <Signal> BroadcastPowerCalculate(List <Signal> values) { Signal leftSignal = values[0]; Signal rightSignal = values[1]; Signal outputSignal = Results[0]; outputSignal.Clone(leftSignal.BroadcastPower(rightSignal)); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); // Results.Add(Math.Sign(values[0])); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(inputSignal.Apply((item) => Convert.ToDouble(Math.Sign(item)))); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); // Results.Add(Math.Tanh(values[0])); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(inputSignal.Apply(Math.Tanh)); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); // Results.Add(Math.Pow(values[0], power)); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(inputSignal.Apply((item) => Math.Pow(item, power))); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); Signal conditionSignal = values[0].Apply(item => item >= threshold ? 1 : 0); Signal firstSignal = values[1]; Signal secondSignal = values[2]; Signal resultSignal = Results[0]; resultSignal.Clone(conditionSignal.BroadcastMultiply(firstSignal) + (1 - conditionSignal).BroadcastMultiply(secondSignal)); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); // Results.Add(Math.Atan2(values[0], values[1])); Signal ySignal = values[0]; Signal xSignal = values[1]; Signal outputSignal = Results[0]; outputSignal.Clone(ySignal.ZipApply(xSignal, Math.Atan2)); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); // Results.Add(Math.Pow(values[0], values[1])); Signal baseSignal = values[0]; Signal indexSignal = values[1]; Signal outputSignal = Results[0]; outputSignal.Clone(baseSignal.ZipApply(indexSignal, Math.Pow)); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { Signal inputSignal = values[0]; Signal outputSignal = Results[0]; try { handle.SetClosedLoopInput(inputSignal); } catch (LigralException) { throw logger.Error(new ModelException(this)); } outputSignal.Clone(handle.GetInput()); return(Results); }
public override void Clear(bool manual = false) { if (!Available || (manual && PatternWindow != null)) { return; } CreateScreen(); Signal n = new Signal(this, this, 0, new Color(0)); for (int i = 0; i < 101; i++) { n.Index = (byte)i; Window?.SignalRender(n.Clone()); } }
/// <summary> /// Scales a signal /// </summary> public static Signal Scale(Signal signal, double amplitudeScalingFactor, double timeScalingFactor) { var output = signal.Clone(); if (Math.Abs(amplitudeScalingFactor - 1) > double.Epsilon) { for (var i = 0; i < output.SamplesCount; i++) { output[i] *= amplitudeScalingFactor; } } if (Math.Abs(timeScalingFactor - 1) > double.Epsilon && timeScalingFactor > 0) { output.Finish *= timeScalingFactor; output.SamplingInterval *= timeScalingFactor; } return(output); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; if (!ControlInput.IsOpenLoop) { Signal stackTop = stack[0]; stack.Remove(stackTop); stackTop.Clone(inputSignal); stack.Add(stackTop); } Signal newStackTop = stack[0]; outputSignal.Clone(newStackTop); return(Results); }
/// <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); }
protected override List <Signal> Calculate(List <Signal> values) { Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(inputSignal.Apply((item) => { if (item < right && item > left) { return(0); } else if (item <= left) { return(item - left); } else //item>=right { return(item - right); } })); return(Results); }
protected override List <Signal> Calculate(List <Signal> values) { // Results.Clear(); Signal inputSignal = values[0]; Signal outputSignal = Results[0]; outputSignal.Clone(inputSignal.Apply((item) => { if (item < upper && item > lower) { return(item); } else if (item <= lower) { return(lower); } else //item>=upper { return(upper); } })); return(Results); }
public void MIDIEnter(Signal n) { lock (locker) { if (n.Index != Index) { return; } int layer = -n.Layer; if (n.Color.Lit) { _signals[layer] = n.Clone(); } else if (_signals.ContainsKey(layer)) { _signals.Remove(layer); } else { return; } } }
/// <summary> /// Scales a signal /// </summary> public static Signal Scale(Signal signal, double amplitudeScalingFactor, double timeScalingFactor) { var output = signal.Clone(); if (Math.Abs(amplitudeScalingFactor - 1) > double.Epsilon) { for (var i = 0; i < output.SamplesCount; i++) { output[i] *= amplitudeScalingFactor; } } if (Math.Abs(timeScalingFactor - 1) > double.Epsilon && timeScalingFactor > 0) { output.Finish *= timeScalingFactor; output.SamplingInterval *= timeScalingFactor; } return output; }
private void button6_Click(object sender, EventArgs e) { //add signalList.Add((Signal)signal.Clone()); }