private void updatePlot() { if (zedGraphControl1.InvokeRequired) { var d = new CalldrawGraph(updatePlot); Invoke(d); } else { //listA.Clear(); //listB.Clear(); teamAcurve.Clear(); teamBcurve.Clear(); //Thread.Sleep(10); double[] a = teamA(); double[] b = teamB(); for (int i = 0; i < 100; i++) { listA.Add(i, a[i]); listB.Add(i, b[i]); } //adding a single point //double v = Math.Sin(2 * time * Math.PI / 90); //listA.Add(new PointPair(time, v)); //double v2 = 2 * Math.Sin(2 * Math.PI * (time / 2) / 45); //listB.Add(new PointPair(time / 2, v2)); mypane.AxisChange(); zedGraphControl1.Refresh(); } }
private void updatePlot() //method that updates the plot after receiving new samples { if (zedGraphControl1.InvokeRequired || zedGraphControl2.InvokeRequired) { var d = new CalldrawGraph(updatePlot); //method used to have safe-cross thread call Invoke(d); } else { teamAcurve.Clear(); teamBcurve.Clear(); teamCcurve.Clear(); double[] a = teamA(); double[] b = teamB(); double[] c = teamC(); float sampling_freq = float.Parse(max_sampling_freq.Text); float freq = float.Parse(freq_box.Text); int cycles = int.Parse(textBox1.Text); int points_to_show = (int)(sampling_freq / freq * cycles); if (points_to_show <= BUFFER_SIZE) { for (int i = 0; i < points_to_show; i++) { listA.Add((double)(i / sampling_freq), a[i]); } mypane_1.XAxis.Scale.Max = (float)(points_to_show / sampling_freq) - (float)(1 / sampling_freq); } else { for (int i = 0; i < BUFFER_SIZE; i++) { listA.Add(i, a[i]); } mypane_1.XAxis.Scale.Max = BUFFER_SIZE - 1; } if (linear_plot) { //adding imaginary part from DFT into respective list mypane_2.YAxis.Title.Text = "Amplitude(V)"; for (int i = 0; i < BUFFER_SIZE / 2; i++) { listB.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), b[i]); listC.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), c[i]); } //adding DC part from DFT into respective list listB.Add(0, b[BUFFER_SIZE / 2]); listC.Add(0, c[BUFFER_SIZE / 2]); //adding real part from DFT into respective list for (int i = BUFFER_SIZE / 2 + 1; i < BUFFER_SIZE; i++) { listB.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), b[i]); listC.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), c[i]); } } else// plot in DB form { double max_db_value = b.Max(); mypane_2.YAxis.Title.Text = "Amplitude(dB)"; //adding imaginary part from DFT into respective list for (int i = 0; i < BUFFER_SIZE / 2; i++) { listB.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), 20 * Math.Log10(b[i] / max_db_value)); listC.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), c[i]); } //adding DC part from DFT into respective list listB.Add(0, 20 * Math.Log10(b[BUFFER_SIZE / 2] / max_db_value)); listC.Add(0, c[BUFFER_SIZE / 2]); //adding real part from DFT into respective list for (int i = BUFFER_SIZE / 2 + 1; i < BUFFER_SIZE; i++) { listB.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), 20 * Math.Log10(b[i] / max_db_value)); listC.Add((i - BUFFER_SIZE / 2) * (sampling_freq / BUFFER_SIZE), c[i]); } } mypane_2.XAxis.Scale.Max = sampling_freq / 2; mypane_2.XAxis.Scale.Min = -sampling_freq / 2; if (DFT_phase) { //turning on phase plot and turning off amplitude plot teamBcurve.IsVisible = false; teamCcurve.IsVisible = true; mypane_2.YAxis.IsVisible = false; mypane_2.Y2Axis.IsVisible = true; } else { //turning off phase plot and turning on amplitude plot teamBcurve.IsVisible = true; teamCcurve.IsVisible = false; mypane_2.YAxis.IsVisible = true; mypane_2.Y2Axis.IsVisible = false; } mypane_1.AxisChange(); mypane_2.AxisChange(); zedGraphControl1.Refresh(); zedGraphControl2.Refresh(); if (start_pressed && !single_pressed) { //sending PIC signal to send another set of data char[] ch = new char[1]; ch[0] = '~'; _setting._serial.Write(ch, 0, 1); //sending start_sampling_signal //sending PIC signal to send another max sampling freq data ch[0] = '%'; _setting._serial.Write(ch, 0, 1); //sending start_sampling_signal } } }