private void ChannelsView_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (((DetectedChannel)channelsView.SelectedValue != null) && (((DetectedChannel)channelsView.SelectedValue).ResponseData != null)) { if (((DetectedChannel)channelsView.SelectedValue).ResponseData.Count > 0) { selectedChannel = (DetectedChannel)channelsView.SelectedValue; DrawChart(); } } }
private void rbtnXRangeOther_Checked(object sender, RoutedEventArgs e) { XMax = 20000; XMin = 15; selectedChannel = (DetectedChannel)channelsView.SelectedValue; if (selectedChannel != null && selectedChannel.ResponseData.Count > 0) { DrawChart(selectedChannel); //responseCombo.SelectedIndex = 0; } }
private void Chbx_Checked(object sender, RoutedEventArgs e) { CheckBox ch = sender as CheckBox; int val = int.Parse(ch.Content.ToString()) - 1; if (!keys.Contains(val)) { keys.Add(val); colors.Add(val, ch.Foreground); } selectedChannel = (DetectedChannel)channelsView.SelectedValue; if (selectedChannel != null && selectedChannel.ResponseData.Count > 0) { DrawChart(selectedChannel); //responseCombo.SelectedIndex = 0; } }
private void ChannelsView_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (((DetectedChannel)channelsView.SelectedValue != null) && (((DetectedChannel)channelsView.SelectedValue).ResponseData.Count > 0)) { selectedChannel = (DetectedChannel)channelsView.SelectedValue; } foreach (var currentChannel in channelsView.Items) { if (((DetectedChannel)currentChannel).EnChannelType == 54) { if (((DetectedChannel)currentChannel).ResponseData.Count > 0) { subwooferChannel = (DetectedChannel)currentChannel; } } } DrawChart(); }
private void ChannelsView_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedChannel = (DetectedChannel)channelsView.SelectedValue; if (selectedChannel != null) { if (selectedChannel.EnChannelType == 54 || selectedChannel.EnChannelType == 42) { rbtnXRangeSubwoower.IsChecked = true; } else { rbtnXRangeOther.IsChecked = true; } if (selectedChannel.ResponseData.Count > 0) { DrawChart(selectedChannel); //responseCombo.SelectedIndex = 0; } } }
private void ChannelsView_SelectionChanged(object sender, SelectionChangedEventArgs e) { List <CheckBox> checkBoxes = new List <CheckBox> { chbx1, chbx2, chbx3, chbx4, chbx5, chbx6, chbx7, chbx8 }; // Disable all the check boxes foreach (var checkBox in checkBoxes) { checkBox.IsEnabled = false; } var selectedValue = channelsView.SelectedValue as DetectedChannel; if (selectedValue != null && selectedValue.ResponseData != null) { // Enable the check boxes corresponding to those positions for which the measurement is available foreach (var measurementPosition in selectedValue.ResponseData) { int positionIndex = int.Parse(measurementPosition.Key); Debug.Assert(positionIndex >= 0 && positionIndex < checkBoxes.Count); checkBoxes[positionIndex].IsEnabled = true; } if (selectedValue.ResponseData.Count > 0) { selectedChannel = (DetectedChannel)channelsView.SelectedValue; DrawChart(); } } // Un-check all the disabled check boxes foreach (var checkBox in checkBoxes) { if (!checkBox.IsEnabled && checkBox.IsChecked == true) { checkBox.IsChecked = false; } } }
private void PlotLine(DetectedChannel selectedChannel, bool secondaryChannel = false) { if (selectedChannel == null) { Collection <DataPoint> points = null; //time domain data if (selectedAxisLimits == "rbtnXRangeChirp") { } //frequency domain data else { if (secondaryChannel) { points = audysseyMultEQReferenceCurveFilter.High_Frequency_Roll_Off_2(); } else { points = audysseyMultEQReferenceCurveFilter.High_Frequency_Roll_Off_1(); } if (points != null) { OxyColor color = OxyColor.FromRgb(255, 0, 0); LineSeries lineserie = new LineSeries { ItemsSource = points, DataFieldX = "X", DataFieldY = "Y", StrokeThickness = 2, MarkerSize = 0, LineStyle = LineStyle.Solid, Color = color, MarkerType = MarkerType.None, }; plotModel.Series.Add(lineserie); } } } else { for (int i = 0; i < keys.Count; i++) { Collection <DataPoint> points = new Collection <DataPoint>(); string s = keys[i].ToString(); if (!selectedChannel.ResponseData.ContainsKey(s)) { continue; } string[] values = selectedChannel.ResponseData[s]; int count = values.Length; Complex[] cValues = new Complex[count]; double[] Xs = new double[count]; float sample_rate = 48000; float total_time = count / sample_rate; AxisLimit Limits = AxisLimits[selectedAxisLimits]; if (selectedAxisLimits == "rbtnXRangeChirp") { Limits.XMax = 1000 * total_time; // horizotal scale: s to ms for (int j = 0; j < count; j++) { double d = Double.Parse(values[j], NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture); points.Add(new DataPoint(1000 * j * total_time / count, d)); } } else { for (int j = 0; j < count; j++) { decimal d = Decimal.Parse(values[j], NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture); Complex cValue = (Complex)d; cValues[j] = 100 * cValue; Xs[j] = (double)j / count * sample_rate; } MathNet.Numerics.IntegralTransforms.Fourier.Forward(cValues); int x = 0; if (radioButtonSmoothingFactorNone.IsChecked.Value) { foreach (Complex cValue in cValues) { points.Add(new DataPoint(Xs[x++], Limits.YShift + 20 * Math.Log10(cValue.Magnitude))); if (x == count / 2) { break; } } } else { double[] smoothed = new double[count]; for (int j = 0; j < count; j++) { smoothed[j] = cValues[j].Magnitude; } LinSpacedFracOctaveSmooth(smoothingFactor, ref smoothed, 1, 1d / 48); foreach (double smoothetResult in smoothed) { points.Add(new DataPoint(Xs[x++], Limits.YShift + 20 * Math.Log10(smoothetResult))); if (x == count / 2) { break; } } } } OxyColor color = OxyColor.Parse(colors[keys[i]].ToString()); LineSeries lineserie = new LineSeries { ItemsSource = points, DataFieldX = "X", DataFieldY = "Y", StrokeThickness = 1, MarkerSize = 0, LineStyle = secondaryChannel ? LineStyle.Dot : LineStyle.Solid, Color = color, MarkerType = MarkerType.None, }; plotModel.Series.Add(lineserie); } } }
private void DrawChart(DetectedChannel selectedChannel) { if (plot.Model != null && plot.Model.Series != null) { plot.Model.Series.Clear(); plot.Model = null; } for (int i = 0; i < keys.Count; i++) { ObservableCollection <DataPoint> points = new ObservableCollection <DataPoint>(); string s = keys[i].ToString(); string[] values = selectedChannel.ResponseData[s]; int count = values.Length; Complex[] cValues = new Complex[count]; double[] Xs = new double[count]; float sample_rate = 48000; float total_time = count / sample_rate; for (int j = 0; j < count; j++) { decimal d = Decimal.Parse(values[j], NumberStyles.AllowExponent | NumberStyles.Float, CultureInfo.InvariantCulture); Complex cValue = (Complex)d; cValues[j] = cValue; Xs[j] = (double)j / count * sample_rate; // units are in kHz } Complex[] result = FFT.fft(cValues); int x = 0; points.Clear(); double[] smoothed = new double[count]; for (int j = 0; j < count; j++) { smoothed[j] = result[j].Magnitude; } if (rbtnNo.IsChecked.Value) { foreach (Complex cValue in result) { //Add data point here points.Add(new DataPoint(Xs[x], VerticalShift + 20 * Math.Log10(cValue.Magnitude))); x++; if (x == count / 2) { break; } } } else { LinSpacedFracOctaveSmooth(smoothingFactor, ref smoothed, 1, 1d / 48); foreach (double smoothetResult in smoothed) { points.Add(new DataPoint(Xs[x], VerticalShift + 20 * Math.Log10(smoothetResult))); x++; if (x == count / 2) { break; } } } OxyColor color = OxyColor.Parse(colors[keys[i]].ToString()); LineSeries lineserie = new LineSeries { ItemsSource = points, DataFieldX = "x", DataFieldY = "Y", StrokeThickness = 1, MarkerSize = 0, LineStyle = LineStyle.Solid, Color = color, MarkerType = MarkerType.None, }; plotModel.Series.Add(lineserie); plotModel.Axes.Clear(); } if (chbxLogX.IsChecked.Value) { plotModel.Axes.Add(new LogarithmicAxis { Position = AxisPosition.Bottom, Title = "Hz", Minimum = XMin, Maximum = XMax, MajorGridlineStyle = LineStyle.Dot }); } else { plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Hz", Minimum = XMin, Maximum = XMax, MajorGridlineStyle = LineStyle.Dot }); } // plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "dB", MajorGridlineStyle = "Dot", MajorGridlineColor = "LightGray", Maximum = VerticalShift+15, Minimum = VerticalShift-25 }); plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "dB", Maximum = VerticalShift + 15, Minimum = VerticalShift - 25, MajorStep = 5, MinorStep = 1, MajorGridlineStyle = LineStyle.Solid }); plot.Model = plotModel; }