コード例 #1
0
        public void SendMessage(string sendToUsername, Sample sample)
        {
            // Serialize to JSON
            var serializedSample = jsonSerializer.Serialize(sample);

            receiveClient.SendMessage(serializedSample, UserName, sendToUsername);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        public AnalysisController(Sample currentSample, int sampleRate)
        {
            this.currentSample = currentSample;
            this.sampleRate = sampleRate;

            fftAlgoritm = new FFTAlgorithm();
            idftAlgorithm = new IDFTAlgorithm();
        }
コード例 #4
0
        public AnalysisForm(Sample currentSample, int sampleRate)
        {
            InitializeComponent();

            this.currentSample = currentSample;
            this.sampleRate = sampleRate;

            acontroller = new AnalysisController(currentSample, sampleRate);
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
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;
        }
コード例 #7
0
 public BaseDataHandler()
 {
     CurrentSample = new Sample();
 }
コード例 #8
0
        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;
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 public ReceivedSample(string username, Sample sample)
 {
     dateCreated = DateTime.Now;
     this.username = username;
     Sample = sample;
 }