diff --git a/SampleGenerator/Sample.cs b/SampleGenerator/Sample.cs index 4e8af5f..893684c 100644 --- a/SampleGenerator/Sample.cs +++ b/SampleGenerator/Sample.cs @@ -64,6 +64,34 @@ public List GetSignalSlice return _sliceSignal; } } + + // 64 channel DFT done on 50 samples + 14 zeros padded right + public List Get50Padded64ChannelSamples() + { + int numSamplesToGet = 32; + int curIDX = _sampleIDX; + if (curIDX + numSamplesToGet >= _samples.Count) + { + numSamplesToGet = _samples.Count - curIDX - 1; + if (numSamplesToGet <= 0) + { + // Roll over to the beginning + _sampleIDX = 0; + return Get50Padded64ChannelSamples(); + } + } + _sampleIDX += numSamplesToGet; + _sliceSignal = _samples.GetRange(curIDX, numSamplesToGet); + + List paddedSignal = new List(_sliceSignal); + // Pad + int padLen = (64 - numSamplesToGet); + for (int cnt = 0; cnt < padLen; cnt++) + paddedSignal.Add(0.0); + + _frequencyDomain = DFT.Transform(paddedSignal); + return _sliceSignal; + } public ListGetNextSamplesForTimeSlice(double milliseconds) { diff --git a/Signals And Transforms/Models/SampleData.cs b/Signals And Transforms/Models/SampleData.cs index fe0197d..1e2f981 100644 --- a/Signals And Transforms/Models/SampleData.cs +++ b/Signals And Transforms/Models/SampleData.cs @@ -29,11 +29,11 @@ public static Sample SignalSample ISignalGenerator random = new WhiteNoise(); ISignalGenerator square = new SquareIshWave(); - Sample sinusoidSamp = new Sample(8000, 1, 100, sinusoid); - Sample sinusoidSamp2 = new Sample(8000, 1, 2000, sinusoid); - Sample whiteNoise = new Sample(16000, 1, 1000, random); + Sample sinusoidSamp = new Sample(16000, 1, 500, sinusoid); + Sample sinusoidSamp2 = new Sample(16000, 1, 7000, sinusoid); + Sample whiteNoise = new Sample(16000, 1, 2000, random); Sample squareWave = new Sample(8000, 1, 400, square); - _signalSample = squareWave; //sinusoidSamp.SumWithSample(sinusoidSamp2);//.SumWithSample(whiteNoise); + _signalSample = sinusoidSamp.SumWithSample(sinusoidSamp2); } _signalSample.GetNextSamplesForTimeSlice(20); // Prime the pump @@ -66,12 +66,20 @@ public static FrequencyDomain FreqDomain } } - public static List GetNextSamplesForTimeSlice(int millis) + /// + /// Get the next 50 samples, the Frequency Domain is padded to 64 in its calculation + /// + /// + public static List Get50Padded64ChannelSamples() { - List sliceSignal = SignalSample.GetNextSamplesForTimeSlice(20); + NewSlice?.Invoke(null, null); + return SignalSample.Get50Padded64ChannelSamples(); + } + public static List GetNextSamplesForTimeSlice(int millis) + { NewSlice?.Invoke(null, null); - return sliceSignal; + return SignalSample.GetNextSamplesForTimeSlice(20); } public static event EventHandler NewSlice; diff --git a/Signals And Transforms/View Models/GraphViewModel.cs b/Signals And Transforms/View Models/GraphViewModel.cs index 50f6971..497e4d3 100644 --- a/Signals And Transforms/View Models/GraphViewModel.cs +++ b/Signals And Transforms/View Models/GraphViewModel.cs @@ -111,15 +111,15 @@ private void GetNewModel() break; } - _signal = SampleData.GetNextSamplesForTimeSlice(20); + _signal = SampleData.Get50Padded64ChannelSamples(); _frequencyDomain = SampleData.FreqDomain; _synthesis = DFT.Synthesize(_frequencyDomain); this.MyModel = new PlotModel { Title = "Signal And Synthesis" }; - this.MyModel.Series.Add(new FunctionSeries(getSynthesis, 0, _synthesis.Count - 1, 1.0, "Synthesis")); - this.MyModel.Series.Add(new FunctionSeries(getSignal, 0, _signal.Count - 1, 1.0, "Signal")); + this.MyModel.Series.Add(new FunctionSeries(getSynthesis, 0, 1000 - 1, 1.0, "Synthesis")); // Clip synthesis to signal sample count + this.MyModel.Series.Add(new FunctionSeries(getSignal, 0, 1000 - 1, 1.0, "Signal")); NotifyPropertyChanged("MyModel"); }