Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            button2_Click(new object(), new EventArgs());
            double sampleRate = Convert.ToDouble(currentSignal.sampleRate);
            int    itr        = 0;

            foreach (double[] frame in currentSignal.signal)
            {
                currentSignal.maksima.Add(new List <PointF>());
                double[] value  = new double[frame.Length / 2];
                double[] freq   = new double[frame.Length / 2];
                double[] result = new double[frame.Length];
                result = AudioHelper.PreEmFaza(frame);
                result = AudioHelper.toDouble(AudioHelper.FFT(AudioHelper.toComplex(result), true));

                List <PointF> values = new List <PointF>();
                for (int i = 0; i < result.Count() / 2; i++)
                {
                    value[i] = AudioHelper.LinearToDecibels(result[i] / sampleRate);

                    freq[i] = (int)(i * sampleRate / result.Length); // to jest do widma amplitudowego

                    values.Add(new PointF((float)freq[i], (float)value[i]));
                }

                // znajdujemy maksima powyżej progu:

                for (int i = 1; i < values.Count - 2; i++)
                {
                    if (values[i].Y > values[i - 1].Y && values[i].Y > values[i + 1].Y &&
                        values[i].Y > (float)numProg.Value)
                    {
                        currentSignal.maksima[itr].Add(new PointF(values[i].X, values[i].Y));
                    }
                }

                if (currentSignal.maksima[itr].Count == 0)
                {
                    currentSignal.maksima.RemoveAt(itr);
                    itr--;
                }

                itr++;
            }

            if (currentSignal.maksima.Count == 0)
            {
                MessageBox.Show("Nie znaleziono żadnego maksimum lokalnego - zmień próg");
                return;
            }

            double[] fhz = new double[currentSignal.maksima.Count];
            for (int f = 0; f < currentSignal.maksima.Count; f++)
            {
                double[] tmp_fhz = new double[currentSignal.maksima[f].Count];
                tmp_fhz[0] = currentSignal.maksima[f][0].X;
                for (int i = 1; i < currentSignal.maksima[f].Count; i++)
                {
                    tmp_fhz[i] = currentSignal.maksima[f][i].X - currentSignal.maksima[f][i - 1].X;
                }

                Sort(tmp_fhz);

                fhz[f] = Mediana(tmp_fhz);
            }


            _freqPerFrame = fhz.ToList();
            foreach (double freq in fhz)
            {
                textBox1.Text += freq + " Hz" + Environment.NewLine;
            }


            Sort(fhz);
            double F = Mediana(fhz);


            currentSignal.isCalculated = true;
            RefreshSignal((int)numFrame.Value);
        }
Exemple #2
0
        public void RefreshSignal(int frame)
        {
            double[] result = currentSignal.signal[frame];
            Signal.Series.Clear();
            Signal.Series.Add("Value");
            Signal.Series["Value"].ChartType  = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            Signal.Series["Value"].MarkerSize = 10;

            double sampleRate = Convert.ToDouble(currentSignal.sampleRate);
            int    seconds    = currentSignal.seconds.Seconds;

            double[] time  = new double[result.Length];
            double[] value = new double[result.Length];
            double[] freq  = new double[result.Length];


            for (int i = 0; i < result.Count(); i++)
            {
                value[i] = result[i] / sampleRate;
                time[i]  = i / sampleRate;
                //   freq[i] = (int)(i * sampleRate / result.Length);           // to jest do widma amplitudowego
                Signal.Series["Value"].Points.AddXY(time[i], value[i]);
            }

            SignalAmplitude.Series.Clear();
            SignalAmplitude.Series.Add("Value");
            SignalAmplitude.Series["Value"].ChartType =
                System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            SignalAmplitude.Series["Value"].MarkerSize = 10;
            SignalAmplitude.Series.Add("Prog");
            SignalAmplitude.Series["Prog"].Color     = Color.Red;
            SignalAmplitude.Series["Prog"].ChartType =
                System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            SignalAmplitude.Series["Prog"].MarkerSize = 10;
            SignalAmplitude.Series.Add("Max");
            SignalAmplitude.Series["Max"].Color     = Color.Green;
            SignalAmplitude.Series["Max"].ChartType =
                System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
            SignalAmplitude.Series["Max"].MarkerSize = 5;

            result = AudioHelper.PreEmFaza(result);
            result = AudioHelper.toDouble(AudioHelper.FFT(AudioHelper.toComplex(result), true));

            currentSignal.amplitude = result;
            value = new double[result.Length / 2];
            freq  = new double[result.Length / 2];

            for (int i = 0; i < result.Count() / 2; i++)
            {
                value[i] = AudioHelper.LinearToDecibels(result[i] / sampleRate);

                freq[i] = (int)(i * sampleRate / result.Length); // to jest do widma amplitudowego
                SignalAmplitude.Series["Value"].Points.AddXY(freq[i], value[i]);
            }

            btnProg_Click(new object(), new EventArgs());
            SignalAmplitude.Series["Max"].Points.Clear();
            if (currentSignal.isCalculated)
            {
                foreach (PointF point in currentSignal.maksima[frame])
                {
                    SignalAmplitude.Series["Max"].Points.AddXY(point.X, point.Y);
                }
            }
            else
            {
            }
        }