Skip to content

Commit

Permalink
Expirementing with 50 sample padded to 64
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Tabone committed Jul 6, 2018
1 parent 7ca87fa commit 9016f6b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
28 changes: 28 additions & 0 deletions SampleGenerator/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ public List<Double> GetSignalSlice
return _sliceSignal;
}
}

// 64 channel DFT done on 50 samples + 14 zeros padded right
public List<double> 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<double> paddedSignal = new List<double>(_sliceSignal);
// Pad
int padLen = (64 - numSamplesToGet);
for (int cnt = 0; cnt < padLen; cnt++)
paddedSignal.Add(0.0);

_frequencyDomain = DFT.Transform(paddedSignal);
return _sliceSignal;
}

public List<double>GetNextSamplesForTimeSlice(double milliseconds)
{
Expand Down
22 changes: 15 additions & 7 deletions Signals And Transforms/Models/SampleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,12 +66,20 @@ public static FrequencyDomain FreqDomain
}
}

public static List<double> GetNextSamplesForTimeSlice(int millis)
/// <summary>
/// Get the next 50 samples, the Frequency Domain is padded to 64 in its calculation
/// </summary>
/// <returns></returns>
public static List<double> Get50Padded64ChannelSamples()
{
List<double> sliceSignal = SignalSample.GetNextSamplesForTimeSlice(20);
NewSlice?.Invoke(null, null);
return SignalSample.Get50Padded64ChannelSamples();
}

public static List<double> GetNextSamplesForTimeSlice(int millis)
{
NewSlice?.Invoke(null, null);
return sliceSignal;
return SignalSample.GetNextSamplesForTimeSlice(20);
}

public static event EventHandler NewSlice;
Expand Down
6 changes: 3 additions & 3 deletions Signals And Transforms/View Models/GraphViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 9016f6b

Please sign in to comment.