public DataCapsule(DataCapsule dataCapsule) { XValues = new List <double>(dataCapsule.XValues); YValues = new List <Complex>(dataCapsule.YValues); SamplingFrequency = dataCapsule.SamplingFrequency; }
internal DataCapsule GenerateSignalComeBack(DataCapsule signalBefore, double signalSpeed, double objectPosition, double objectSpeed, double momentInTime, double timeFrequency = 0.01) { double objRoad = objectPosition + objectSpeed * momentInTime, signalRoad = signalSpeed * momentInTime; if (signalRoad < objRoad * 2) { MessageBox.Show("W zadanym czasie sygnał nie zdąrzy powrócić."); return(null); } else if (signalRoad > objRoad * 2) { signalRoad = objRoad * 2; } int samplesToMove = (int)(signalRoad / signalSpeed * signalBefore.SamplingFrequency); while (samplesToMove >= signalBefore.XValues.Count) { samplesToMove -= signalBefore.XValues.Count; } if (samplesToMove == 0) { return(new DataCapsule(signalBefore)); } else { return(new DataCapsule(signalBefore, samplesToMove)); } }
public ComplexCapsule GetWalsh() { DataCapsule loaded = SerializationLogics.Deserialize(); List <Complex> result = new List <Complex>(); Complex sum; int m = 0; while (Math.Pow(2, m) <= loaded.XValues.Count) { m++; } loaded.Take((int)Math.Pow(2, --m)); double[][] matrix = TransformationsLogics.GetMatrix(m); for (int i = 0; i < loaded.XValues.Count; i++) { sum = Complex.Zero; for (int j = 0; j < Math.Pow(2, m); j++) { sum += loaded.YValues[j] * matrix[i][j]; } sum /= loaded.YValues.Count;//(double)(Math.Pow(Math.Sqrt(2.0), m)); result.Add(sum); } return(new ComplexCapsule(loaded.XValues, result, loaded.SamplingFrequency)); }
public ComplexCapsule GetFourier() { DataCapsule loaded = SerializationLogics.Deserialize(); List <Complex> results = new List <Complex>(); Complex sum; int m = 0; while (Math.Pow(2, m) <= loaded.XValues.Count) { m++; } loaded.Take((int)Math.Pow(2, --m)); for (int i = 0; i < loaded.XValues.Count; i++) { sum = Complex.Zero; for (int k = 0; k < loaded.XValues.Count; k++) { sum += loaded.YValues[k] * Complex.Exp(new Complex(0, -2 * Math.PI * i * k / loaded.XValues.Count)); } results.Add(sum / loaded.XValues.Count); } return(new ComplexCapsule(loaded.XValues, results, loaded.SamplingFrequency)); }
internal DataCapsule Correlation(DataCapsule dataCapsule) { ChartValues <ObservablePoint> correlationValues = new ChartValues <ObservablePoint>(); double frequency = (this.XValues.Max() + dataCapsule.XValues.Max()) / (this.XValues.Count + dataCapsule.XValues.Count - 1); int counter = 0; double[] time = SignalLogics.GetTimeValues(frequency, this.XValues.Max() + dataCapsule.XValues.Max()); for (int i = 0; i < this.XValues.Count + dataCapsule.XValues.Count - 1; i++) { Complex sum = Complex.Zero; int k1min = i >= dataCapsule.XValues.Count - 1 ? i - (dataCapsule.XValues.Count - 1) : 0, k1max = i < this.XValues.Count - 1 ? i : this.XValues.Count - 1, k2min = i <= dataCapsule.XValues.Count - 1 ? dataCapsule.XValues.Count - 1 - i : 0; for (int k1 = k1min, k2 = k2min; k1 <= k1max; k1++, k2++) { sum += this.YValues[k1] * dataCapsule.YValues[k2]; } correlationValues.Add(new ObservablePoint { X = time[counter], Y = sum.Real }); counter++; } return(new DataCapsule(correlationValues, dataCapsule.SamplingFrequency)); }
internal DataCapsule Weave(DataCapsule dataCapsule) { List <Complex> a = this.YValues, b = dataCapsule.YValues; var result = new List <Complex>(); for (int i = 0; i < a.Count + b.Count - 1; i++) { Complex sum = Complex.Zero; for (int j = 0; j < a.Count; j++) { if (i - j < 0 || i - j >= b.Count) { continue; } else { sum += a[j] * b[i - j]; } } result.Add(sum); } return(new DataCapsule(result, this.SamplingFrequency)); }
public ComplexCapsule GetFastFourier() { DataCapsule loaded = SerializationLogics.Deserialize(); TransformationsLogics logics = new TransformationsLogics(); List <Complex> transformed = new List <Complex>(); int N = loaded.XValues.Count; transformed = logics.SwitchSamples(loaded.YValues); return(new ComplexCapsule(loaded.XValues.Take(transformed.Count).ToList(), transformed.Select(c => c / N).ToList(), loaded.SamplingFrequency)); }
public DataCapsule(DataCapsule dataCapsule, int samplesToMove) { List <Complex> pointsLeft = dataCapsule.YValues.Take(dataCapsule.YValues.Count - samplesToMove).ToList(); List <Complex> receivedSignal = dataCapsule.YValues.Skip(dataCapsule.YValues.Count - samplesToMove).ToList(); receivedSignal.AddRange(pointsLeft); XValues = new List <double>(dataCapsule.XValues); YValues = receivedSignal; SamplingFrequency = dataCapsule.SamplingFrequency; }
internal DataCapsule WeaveCorrelation(DataCapsule dataCapsule) { this.XValues.Reverse(); this.YValues.Reverse(); DataCapsule result = this.Weave(dataCapsule); this.XValues.Reverse(); this.YValues.Reverse(); return(result); }
internal IChartValues Filter(int m, int cutOffFrequency, int windowChoice, int filterChoice) { DataCapsule loaded = SerializationLogics.Deserialize(); List <double> factors, filtered; switch (filterChoice) { case 0: factors = FilterLogics.LowFilter(m, loaded.SamplingFrequency / cutOffFrequency); break; case 1: factors = FilterLogics.MediumFilter(FilterLogics.LowFilter(m, (loaded.SamplingFrequency / (loaded.SamplingFrequency / 4.0 - cutOffFrequency)))); break; case 2: factors = FilterLogics.HighFilter(FilterLogics.LowFilter(m, (loaded.SamplingFrequency / (loaded.SamplingFrequency / 2.0 - cutOffFrequency)))); break; default: throw new Exception("The filter combobox is out of its boundries."); } switch (windowChoice) { case 0: filtered = factors; break; case 1: filtered = FilterLogics.HammingWindow(factors); break; case 2: filtered = FilterLogics.HanningWindow(factors); break; case 3: filtered = FilterLogics.BlackmanWindow(factors); break; default: throw new Exception("The window combobox is out of its boundries."); } return(loaded.Weave(filtered).GetValues()); }
internal DataCapsule Multiply(DataCapsule dataCapsule) { ChartValues <ObservablePoint> values = new ChartValues <ObservablePoint>(); if (XValues.Count == dataCapsule.XValues.Count && XValues.Count != 0) { for (int i = 0; i < XValues.Count; i++) { YValues[i] *= dataCapsule.YValues[i]; } } else { throw new Exception("The amounts of the points are not equal."); } return(this); }
public ComplexCapsule GetFastWalsh() { DataCapsule loaded = SerializationLogics.Deserialize(); List <Complex> result = new List <Complex>(); Complex a, b; int m = 0; while (Math.Pow(2, m) <= loaded.XValues.Count) { m++; } loaded.Take((int)Math.Pow(2, --m)); for (int h = 1; h < loaded.XValues.Count; h *= 2) { for (int i = 0; i < loaded.XValues.Count; i += h * 2) { for (int j = i; j < i + h; j++) { a = loaded.YValues[j]; b = loaded.YValues[j + h]; loaded.YValues[j] = a + b; loaded.YValues[j + h] = a - b; } } } for (int i = 0; i < loaded.XValues.Count; i++) { loaded.YValues[i] /= loaded.YValues.Count; } return(new ComplexCapsule(loaded.XValues, loaded.YValues, loaded.SamplingFrequency)); }
internal void Serialize(DataCapsule capsule) { SerializationLogics.Serialize(capsule); }