diff --git a/SampleGenerator/Sample.cs b/SampleGenerator/Sample.cs index 893684c..30a7d2c 100644 --- a/SampleGenerator/Sample.cs +++ b/SampleGenerator/Sample.cs @@ -4,6 +4,7 @@ * */ using SignalGenerator; using SignalProcessor; +using SignalProcessor.Filters; using System; using System.Collections.Generic; using System.Linq; @@ -35,20 +36,40 @@ public Sample(int sampleRate, double seconds, double hertz, ISignalGenerator sig _seconds = seconds; _hertz = hertz; - int sampleCount = (int)Math.Ceiling(_sampleRate * _seconds); - int cycleCount = (int)Math.Ceiling(_seconds * _hertz); - + if (sigGen != null) { - _samples = sigGen.GetSignal(sampleCount, cycleCount); + _samples = sigGen.GetSignal(SampleCount, CycleCount); } else { - _samples = new List(cycleCount); // Create empty sample list + _samples = new List(CycleCount); // Create empty sample list } _sampleIDX = 0; } + public int SampleRate + { + get + { + return _sampleRate; + } + } + public int SampleCount + { + get + { + return (int)Math.Ceiling(_sampleRate * _seconds); + } + } + + public int CycleCount + { + get + { + return (int)Math.Ceiling(_seconds * _hertz); + } + } public FrequencyDomain GetFrequencyDomainForSlice { get @@ -68,7 +89,7 @@ public List GetSignalSlice // 64 channel DFT done on 50 samples + 14 zeros padded right public List Get50Padded64ChannelSamples() { - int numSamplesToGet = 32; + int numSamplesToGet = 64; int curIDX = _sampleIDX; if (curIDX + numSamplesToGet >= _samples.Count) { diff --git a/SignalProcessor/DFT.cs b/SignalProcessor/DFT.cs index 45ab0ae..dad3bf1 100644 --- a/SignalProcessor/DFT.cs +++ b/SignalProcessor/DFT.cs @@ -61,6 +61,23 @@ public double ScaledImaginaryComponent(int K) return (ImaginaryComponent[K] * ScalingFactor[K]); } + + + // See page 162, Equation 8-6 and 8-7 in "The Scientist and Engineer's Guide to Digital Signal Processing + #region polarcoords + public double Magnitude(int k) + { + return Math.Sqrt(Math.Pow(ScaledRealComponent(k), 2) + Math.Pow(ScaledImaginaryComponent(k), 2)); + } + + public double Phase(int k) + { + if (ScaledRealComponent(k) == 0) + return Math.PI / 2.0; + + return Math.Atan(ScaledImaginaryComponent(k) / ScaledRealComponent(k)); + } + #endregion } public class DFT diff --git a/Signals And Transforms/MainWindow.xaml b/Signals And Transforms/MainWindow.xaml index 48f83a7..f2115b3 100644 --- a/Signals And Transforms/MainWindow.xaml +++ b/Signals And Transforms/MainWindow.xaml @@ -44,6 +44,10 @@ High None + +