示例#1
0
 /// <summary>
 /// Displays raw time series data.
 /// </summary>
 /// <param name="samples">Audio input samples.</param>
 private void ProcessTimeSeriesAudioSample(float[] samples)
 {
     using (sciChart.SuspendUpdates())
     {
         _audioSeriesSource.Clear();
         _audioSeriesSource.Append(_xSeries, samples);
     }
 }
示例#2
0
        // Add 100 new data to DataSeries's
        private void OnNewData(object sender, EventArgs e)
        {
            _tick++;
            if (_tick == 2)
            {
                _tick = 0;
                _step = _random.Next(0, 11);
            }

            var massVal = new double[100];

            for (int i = 0; i < 100; i++)
            {
                double y = _step * Math.Sin(((2 * Math.PI) * 0.4) * t) + _random.NextDouble() * 2;
                _yValues[i] = y;
                _tValues[i] = t;
                massVal[i]  = y + 10;

                t += dt;
            }

            var sortData = massVal.OrderByDescending(x => x);

            using (_series0.SuspendUpdates())
                using (_series1.SuspendUpdates())
                    using (_series2.SuspendUpdates())
                    {
                        _series0.Append(_tValues, _yValues);
                        _series1.PushRow(sortData.ToArray());
                        _series2.PushRow(sortData.ToArray());
                    }
        }
示例#3
0
        private void UpdateData()
        {
            lock (this)
            {
                for (int i = 0; i < Count; i++)
                {
                    _re[i] = 2.0 * Math.Sin(2 * Math.PI * i / 20) +
                             5.0 * Math.Sin(2 * Math.PI * i / 10) +
                             2.0 * _random.NextDouble();
                    _im[i] = IsFrequencyDomain ? 0.0 : i;
                }

                if (IsFrequencyDomain)
                {
                    _transform.run(_re, _im);
                    for (int i = 0; i < Count; i++)
                    {
                        double mag = Math.Sqrt(_re[i] * _re[i] + _im[i] * _im[i]);
                        _re[i] = 20 * Math.Log10(mag / Count);
                        _im[i] = i;
                    }
                }

                _dataSeries.SeriesName = YAxisTitle;
                _dataSeries.Clear();
                _dataSeries.Append(_im, _re);
            }
        }
示例#4
0
        private void GenerateData()
        {
            _scatterData = new XyDataSeries <double, double>();
            _fittedData  = new XyDataSeries <double, double>();

            _scatterData.Append(_xData, _scatterY);
            _fittedData.Append(_xData, _lineY);
        }
示例#5
0
        private void AppendPoint(double sampleRate)
        {
            if (_currentIndex >= _sourceData.Length)
            {
                _currentIndex = 0;
            }

            // Get the next voltage and time, and append to the chart
            double voltage = _sourceData[_currentIndex];
            double time    = _totalIndex / sampleRate;

            _series0.Append(time, voltage);

            // Calculate the next visible range
            XVisibleRange = ComputeXAxisRange(time);

            _lastBeat = IsBeat;
            _currentIndex++;
            _totalIndex++;
        }
        private void FillData(IXyDataSeries <double, double> dataSeries)
        {
            var data = DataManager.Instance.GetRandomDoubleSeries(50);

            dataSeries.Append(data.XData, data.YData);

            sciChart.RenderableSeries.Add(new FastLineRenderableSeries()
            {
                Stroke     = DataManager.Instance.GetRandomColor(),
                DataSeries = dataSeries,
            });
        }
 private void OnData(StateMonitorLineChartData info)
 {
     if (temp_index <= info.Time)
     {
         PosSeries.Append(info.Time, info.Pos);
         SpeedSeries.Append(info.Time, info.Speed);
         temp_index = info.Time;
     }
     else
     {
         PosSeries.Clear();
         SpeedSeries.Clear();
         temp_index = info.Time;
     }
 }
示例#8
0
        private void OnNewData(object sender, EventArgs e)
        {
            // Compute our three series values
            double y1 = 3.0 * Math.Sin(((2 * Math.PI) * 1.4) * t) + _random.NextDouble() * 0.5;
            double y2 = 2.0 * Math.Cos(((2 * Math.PI) * 0.8) * t) + _random.NextDouble() * 0.5;
            double y3 = 1.0 * Math.Sin(((2 * Math.PI) * 2.2) * t) + _random.NextDouble() * 0.5;

            // Suspending updates is optional, and ensures we only get one redraw
            // once all three dataseries have been appended to
            using (sciChart.SuspendUpdates())
            {
                // Append x,y data to previously created series
                series0.Append(t, y1);
                series1.Append(t, y2);
                series2.Append(t, y3);
            }

            // Increment current time
            t += dt;
        }
示例#9
0
        private void OnTick(object sender, EventArgs e)
        {
            lock (this)
            {
                // Generate data at this phase depending on data source type
                var dataSource = SelectedDataSource == "Lissajous"
                                     ? DataManager.Instance.GetLissajousCurve(0.12, _phase1, _phase0, 2500)
                                     : DataManager.Instance.GetFourierSeries(2.0, _phase0, 1000);

                _phase0 += _phaseIncrement;
                _phase1 += _phaseIncrement * 0.005;

                // Lock the data-series and clear / re-add new data
                using (this.ChartData.SuspendUpdates())
                {
                    _series0.Clear();
                    _series0.Append(dataSource.XData, dataSource.YData);
                }
            }
        }
示例#10
0
        //public void prepareDataReceiver(){
        //    _ploted = new TripleSeries(50000);
        //    _receivedPackets = new List<List<byte[]>>(40);
        //    for (int i = 0; i < 40; i++){
        //        _receivedPackets.Add(new List<byte[]>(50000));
        //    }
        //    _receivingPackets = _receivedPackets[0];
        //}

        public void finishedReadingData()
        {
            IsScrollingVisible = true;
            IsShowingHistory   = true;

            Task.Factory.StartNew(
                () =>
            {
                /*do a last refreshing of graph cuz scichart seems to not work properly sometimes*/
                try
                {
                    //give time for
                    Thread.Sleep((int)(RefreshTime * 3));
                    double[] y_1;
                    double[] y_2;
                    double[] xs;
                    lock (MonitorupdateSeries)
                    {
                        lock (MonitordataReceived)
                        {
                            y_1 = _ploted.Select(y1 => y1.Y1).ToArray();
                            y_2 = _ploted.Select(y2 => y2.Y2).ToArray();
                            xs  = _ploted.Select(x => x.X).ToArray();
                            using (_series0.SuspendUpdates())
                            {
                                using (_series1.SuspendUpdates())
                                {
                                    _series0.Clear();
                                    _series1.Clear();
                                    _series0.Append(xs, y_1);
                                    _series1.Append(xs, y_2);
                                }
                            }
                        }
                    }
                }
                catch { Debugger.Break(); }
                Thread.Sleep(250);
                ResetZoom();
            });
        }
        private IDataSeries FillData(IXyDataSeries <double, double> dataSeries, string name)
        {
            var randomWalk = 10.0;

            // Generate the X,Y data with sequential dates on the X-Axis and slightly positively biased random walk on the Y-Axis
            var xBuffer = new double[Count];
            var yBuffer = new double[Count];

            for (int i = 0; i < Count; i++)
            {
                randomWalk += (_random.NextDouble() - 0.498);
                yBuffer[i]  = randomWalk;
                xBuffer[i]  = i;
            }

            // Buffer above and append all in one go to avoid multiple recalculations of series range
            dataSeries.Append(xBuffer, yBuffer);
            dataSeries.SeriesName = name;

            return(dataSeries);
        }
示例#12
0
        private void Init()
        {
            Sthetho.IsStreaming    = true;  //Block Streaming Button
            checkboxFile.IsEnabled = false; //Disable CheckBox
            SerialDataIn.OpenSerialPort();  //Open Serial Data Por

            //Setup Sound plot
            SoundSeries.DataSeries = SoundData;
            YAxis.VisibleRange     = new DoubleRange(-32000, 32000);
            this.sciChartSurface.XAxis.AutoRange = SciChart.Charting.Visuals.Axes.AutoRange.Always;
            SoundData.Clear();

            //Check if File will be written
            if (Sthetho.WriteToFile)
            {
                if (File.Exists(outputfile))
                {
                    File.Delete(outputfile);
                }
                tmpFile = File.OpenWrite(outputfile);
            }

            timer = new MultimediaTimer()
            {
                Interval = 1
            };

            Console.WriteLine("Running graphing system");
            //Observable to output to observer

            System.Reactive.Subjects.IConnectableObservable <byte> dataStream = null;
            if (Sthetho.Demo)
            {
                dataStream = Observable.Create <byte[]>(ob =>
                {
                    timer.Elapsed += (source, e) =>
                    {
                        if (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            ob.OnNext(reader.ReadBytes(32));  //Call connected, subscribed observables.
                        }
                        else
                        {
                            Console.WriteLine("timer: ready to stop");
                            timer.Stop();
                            Console.WriteLine("timer: stopped");
                        }
                    };
                    timer.Start();
                    return(Disposable.Empty);
                })
                             .SelectMany(data => data.ToObservable())
                             .Publish();
            }
            else
            {
                //Observable to output to observer - SerialPort
                dataStream = Observable.FromEventPattern <SerialDataReceivedEventHandler, SerialDataReceivedEventArgs>(
                    h => SerialDataIn.SerialPortFTDI.DataReceived += h,
                    h => SerialDataIn.SerialPortFTDI.DataReceived -= h)
                             .Select(arg =>
                {
                    byte[] buf = new byte[SerialDataIn.SerialPortFTDI.BytesToRead];
                    SerialDataIn.SerialPortFTDI.Read(buf, 0, buf.Length);
                    return(buf);
                })
                             .SelectMany(data => data.ToObservable())
                             .Publish();
            }

            // Save to file
            dataStream
            .Buffer(2)
            .Buffer(1000)
            .SubscribeOn(NewThreadScheduler.Default)
            .Subscribe(data =>
            {
                var res = data.ToArray();
                foreach (var t in res)
                {
                    StethoPlayer.AddData(new byte[] { t[1], t[0] });
                }
                //StethoPlayer.AddData(res);
                StethoPlayer.Play();

                //tmpFile.WriteByte(data[0]);
                //tmpFile.Write(res, 0, res.Length);
                //tmpFile.WriteByte(data[1]);
                //tmpFile.Flush();
            });


            /*
             * if (Sthetho.WriteToFile)
             * {
             *  dataStream.Buffer(2).Subscribe(data =>
             *  {
             *      tmpFile.WriteByte(data[0]);
             *      tmpFile.WriteByte(data[1]);
             *      //tmpFile.Flush();
             *  });
             * }
             */
            //Graphing
            dataStream
            .Buffer(2)
            .Buffer(153)
            .Subscribe(values =>
            {
                // draw
                using (sciChartSurface.SuspendUpdates())
                {
                    //Console.WriteLine("Data Received");
                    foreach (var v in values)
                    {
                        short s = BitConverter.ToInt16(new byte[2] {
                            (byte)v[1], (byte)v[0]
                        }, 0);
                        tmpFile.WriteByte(v[0]);
                        tmpFile.WriteByte(v[1]);
                        //WriteFileASync(v);
                        if (StethoPlayer.PlayBackState == PlaybackState.Playing)
                        {
                            Sthetho.AnnotationX = plotCount - (16000);
                        }
                        if (Sthetho.FilterHeart)
                        {
                            SoundData.Append(plotCount++, (short)BandPassfilter.ProcessSample((double)s));
                            //SoundData.Append(plotCount++, (short) s);
                        }
                        else
                        {
                            SoundData.Append(plotCount++, s);
                        }
                    }
                }
            });

            dataStream.Connect();  //For the .Publish on the observable
        }
        private void DataAppendLoop()
        {
            // if timer was released in another thread - skip all further processing
            if (_timer == null)
            {
                return;
            }

            // By nesting multiple updates inside a SuspendUpdates using block, you get one redraw at the end
            using (_mainSeries.SuspendUpdates())
            {
                // Preload previous value with k-1 sample, or 0.0 if the count is zero
                int    xValue = _mainSeries.Count > 0 ? _mainSeries.XValues[_mainSeries.Count - 1] : 0;
                double yValue = _mainSeries.Count > 0 ? _mainSeries.YValues[_mainSeries.Count - 1] : 10.0f;

                // Add N points at a time. We want to get to the higher point counts
                // quickly to demonstrate performance.
                // Also, it is more efficient to buffer and block update the chart
                // even if you use SuspendUpdates due to the overhead of calculating min, max
                // for a series
                for (int i = 0; i < BufferSize; i++)
                {
                    // Generate a new X,Y value in the random walk and buffer
                    xValue = xValue + 1;
                    yValue = (double)(yValue + (_random.NextDouble() - 0.5));

                    _xBuffer[i] = xValue;
                    _yBuffer[i] = yValue;

                    // Update moving averages
                    _maLowBuffer[i]  = (double)_maLow.Push(yValue).Current;
                    _maHighBuffer[i] = (double)_maHigh.Push(yValue).Current;
                }

                // Append block of values to all three series
                _mainSeries.Append(_xBuffer, _yBuffer);
                _maLowSeries.Append(_xBuffer, _maLowBuffer);
                _maHighSeries.Append(_xBuffer, _maHighBuffer);
            }

            // Render the total point count (all series) to the screen
            int numPoints = 3 * _mainSeries.Count;

            if (numPoints > 10000 && _reached < 10000)
            {
                _reached = 10000;
            }

            if (numPoints > 100000 && _reached < 100000)
            {
                _reached = 100000;
            }

            if (numPoints > 300000 && _reached < 300000)
            {
                _reached = 300000;
            }

            if (numPoints > 500000 && _reached < 500000)
            {
                _reached = 500000;
            }

            if (numPoints > 1000000 && _reached < 1000000)
            {
                _reached = 1000000;
            }

            if (numPoints > 3000000 && _reached < 3000000)
            {
                Messages.Add("Reached 3,000,000 Points!");
                _reached = 3000000;
            }

            if (numPoints > 5000000 && _reached < 5000000)
            {
                Messages.Add("Reached 5,000,000 Points!");
                _reached = 5000000;
            }

            if (numPoints > MaxCount)
            {
                Messages.Add("Reached 10M points!");
                Messages.Add(".. and I'm still going!");
                _timer.Stop();
                _timer     = null;
                BoundRange = AutoRange.Never;

                this.ShowInstructionsToUser();
            }
        }