1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| public class MainViewModel : INotifyPropertyChanged { private LineSeries _lineSeries = new LineSeries { MarkerType = MarkerType.Circle, Color = OxyColor.Parse("#00FF00") };
public MainViewModel() { _mainModel = new PlotModel { Title = "Spectrum Analyzer", TitleColor = OxyColor.Parse("#E8E8E8"), Background = OxyColor.Parse("#000000") }; _mainModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, AxislineStyle = LineStyle.Solid, AxislineColor = OxyColor.Parse("#E8E8E8"), MajorGridlineStyle = LineStyle.Solid, MajorGridlineColor = OxyColor.Parse("#E8E8E8"), MinorGridlineStyle = LineStyle.Dot, MinorGridlineColor = OxyColor.Parse("#E8E8E8"), TextColor = OxyColor.Parse("#E8E8E8"), TickStyle = TickStyle.None, Minimum = 0, Maximum = 22050, IsZoomEnabled = false, Title = "Frequencies(Hz)", TitleColor = OxyColor.Parse("#00CDCD"), }); _mainModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, AxislineStyle = LineStyle.Solid, AxislineColor = OxyColor.Parse("#E8E8E8"), MajorGridlineStyle = LineStyle.Solid, MajorGridlineColor = OxyColor.Parse("#E8E8E8"), MinorGridlineStyle = LineStyle.Dot, MinorGridlineColor = OxyColor.Parse("#E8E8E8"), TextColor = OxyColor.Parse("#E8E8E8"), TickStyle = TickStyle.None, Minimum = -200, Maximum = 20, AbsoluteMinimum = -214, AbsoluteMaximum = 44, IsZoomEnabled = true, Title = "Amplitude(dB FS)", TitleColor = OxyColor.Parse("#00CDCD") }); _mainModel.Series.Add(new LineSeries { MarkerSize = 1, Color = OxyColor.Parse("#00FF00") }); _mainModel.Series.Add(_lineSeries); }
private PlotModel _mainModel; public PlotModel MainModel { get { return _mainModel; } set { _mainModel = value; NotifyPropertyChanged("MainModel"); } }
public void Update(double[] frequencies, double[] dbFS) { var minFrequencie = frequencies.Min(); var maxFrequencie = frequencies.Max(); _mainModel.Axes[0].Minimum = minFrequencie; _mainModel.Axes[0].Maximum = maxFrequencie;
var mindBFS = dbFS.Min(); _mainModel.Axes[1].Minimum = mindBFS;
_lineSeries.Points.Clear(); for(var i = 0; i <dbFS.Length; i++) { var x = frequencies[i]; var y = dbFS[i]; _lineSeries.Points.Add(new DataPoint(x, y)); }
NotifyPropertyChanged("MainModel"); }
#region NotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info)); }
#endregion
|