private float[] PreprocessSignal(SignalCalibration calibration, float[] rawData, bool amplify) { if (amplify && false) { for (int i = 0; i < rawData.Length; i++) { if (i >= Sensor.StartCutOff && i <= rawData.Length - Sensor.EndCutOff) { // amplify the data // double factor = 2.0 * Math.Pow(Sensor.GetDistance(i), 3.0) + 1.0; // double factor = 4.0 * Math.Pow(Sensor.GetDistance(i), 2.0) + 1.0; double factor = 1.0 * Math.Pow(Sensor.GetDistance(i), 2.0) + 1.0; factor = 1.0; // rawData[i] *= 4.0f; // factor *= 2.0; // SMALL // double factor = 8.0 * Math.Pow(Sensor.GetDistance(i), 4.0) + 1.0; rawData[i] *= (float)factor; } } } // let the calibration do its job float[] calibratedEnvelope = calibration.GetCalibratedSignal(rawData); if (amplify) { for (int i = 0; i < calibratedEnvelope.Length; i++) { if (i >= Sensor.StartCutOff && i <= rawData.Length - Sensor.EndCutOff) { // amplify the data // double factor = 2.0 * Math.Pow(Sensor.GetDistance(i), 3.0) + 1.0; // SMALL double factor = 8.0 * Math.Pow(Sensor.GetDistance(i), 2.0) + 1.0; factor *= 2.0; // LARGE /* factor = 2.0 * Math.Pow(Sensor.GetDistance(i), 3.0) + 1.0; * factor *= 2.0; */ calibratedEnvelope[i] *= (float)factor; } } } return(calibratedEnvelope); }
public SensorDataEventArgs ProcessData(SignalCalibration calibration, float[] rawData, bool amplify) { // data setup double threshold = 0.0; // preprocess the data float[] envelopedData = PreprocessSignal(calibration, rawData, amplify); if (envelopedData == null) { // this is a faulty signal, return 'null' return(null); } SensorDataEventArgs eventArgs = new SensorDataEventArgs(Sensor, rawData, envelopedData) { CutOffs = new Tuple <int, int>(Sensor.StartCutOff, Sensor.EndCutOff) }; // get the first/highest peak (if any exists) Tuple <int, float> firstPeak = GetFirstPeak(envelopedData); // check whether we found a peak if (firstPeak.Item1 != -1) { // we in fact did! // now, let's get the areas (all of them) threshold = 1.0 * firstPeak.Item2 / 1.5; threshold = Sensor.UpperTouchThreshold; Sensor.LowerTouchThreshold = (float)threshold; // Debug.WriteLine(Sensor.LowerTouchThreshold); // threshold = Sensor.UpperTouchThreshold; // Sensor.LowerTouchThreshold = (float)threshold; List <Tuple <int, int> > areas = GetRawAreas(envelopedData, threshold); // filter them (by merging) List <Tuple <int, int> > filteredAreas = FilterAreas(areas, envelopedData); // get the raw peaks from those areas List <Tuple <int, int, int, float> > peaks = GetPeaks(filteredAreas, envelopedData); // add the values to the result eventArgs.RawPeaks = peaks.ToArray(); eventArgs.Threshold = threshold; } return(eventArgs); }