public void SendMessage(string sendToUsername, Sample sample) { // Serialize to JSON var serializedSample = jsonSerializer.Serialize(sample); receiveClient.SendMessage(serializedSample, UserName, sendToUsername); }
public override double[] Calculate(Sample currentSample, int noOfHarmonics, int sampleRate, out string harmonicsTable, out int fundamentalFrequency) { base.Calculate(currentSample, noOfHarmonics, sampleRate, out harmonicsTable, out fundamentalFrequency); InvDFT(); return xw; }
public AnalysisController(Sample currentSample, int sampleRate) { this.currentSample = currentSample; this.sampleRate = sampleRate; fftAlgoritm = new FFTAlgorithm(); idftAlgorithm = new IDFTAlgorithm(); }
public AnalysisForm(Sample currentSample, int sampleRate) { InitializeComponent(); this.currentSample = currentSample; this.sampleRate = sampleRate; acontroller = new AnalysisController(currentSample, sampleRate); }
private void Initialize(Sample currentSample) { N = currentSample.Limit; x = new TKomplex[N + 1]; y = new TKomplex[N + 1]; we = new TKomplex[N / 2]; for (int i = 0; i < (N / 2); i++) // Init look up table for sine and cosine values { we[i].real = Math.Cos(2 * Math.PI * (double)(i) / (double)(N)); we[i].imag = Math.Sin(2 * Math.PI * (double)(i) / (double)(N)); } var windowedSignal = BuildHanWindow(currentSample); for (int i = 0; i < currentSample.Limit; i++) { y[i].real = windowedSignal[i]; y[i].imag = 0; } }
public virtual double[] Calculate(Sample currentSample, int noOfHarmonics, int sampleRate, out string harmonicsTable, out int fundamentalFrequency) { Initialize(currentSample); CalcFFT(); harmonicsTable = String.Format("{0,5} {1,20} {2,20} {3,20}\n\n", "#", "Real part", "Imaginary part", "Magnitude"); double[] harmonics = new double[noOfHarmonics]; for (int i = 0; i < currentSample.Limit; i++) { if (i < noOfHarmonics) { harmonicsTable += String.Format("{0,5} {1,20} {2,20} {3,20}\n", i, Math.Round(y[i].real, 6), Math.Round(y[i].imag, 6), Math.Round(Math.Sqrt(Math.Pow(y[i].real, 2) + Math.Pow(y[i].imag, 2)), 6)); harmonics[i] = 10 * Math.Log10(Math.Pow(CalcMagnitude(y[i].real, y[i].imag), 2)); } } fundamentalFrequency = CalculateFundamentalFrequency(currentSample, sampleRate); return harmonics; }
public BaseDataHandler() { CurrentSample = new Sample(); }
private int CalculateFundamentalFrequency(Sample currentSample, int sampleRate) { double[] magnitudes = new double[currentSample.Limit]; for (int i = 0; i < magnitudes.Length / 2; i++) { magnitudes[i] = Math.Sqrt(Math.Pow(y[i].real, 2) + Math.Pow(y[i].imag, 2)); } int max = FindMaxIndex(magnitudes); int max_freq = (int)((float)sampleRate * (float)max / (float)currentSample.Limit); return max_freq; }
private double[] BuildHanWindow(Sample currentSample) { var hanWindow = new double[currentSample.Limit]; for (int i = 0; i < currentSample.Limit; i++) { hanWindow[i] = .5 * (1 - Math.Cos(2 * Math.PI * i / (currentSample.Limit - 1.0))); } double[] hindowedSignal = new double[currentSample.Limit]; for (int i = 0; i < currentSample.Limit; i++) { hindowedSignal[i] = currentSample.Get(i); hindowedSignal[i] *= hanWindow[i]; } return hindowedSignal; }
public ReceivedSample(string username, Sample sample) { dateCreated = DateTime.Now; this.username = username; Sample = sample; }