Exemple #1
0
        public void chartBuildFilter()
        {
            Parser.Do();
            pointsClear();
            mainTitle.Text = "Filter LPF";
            foreach (var area in chart.ChartAreas)
            {
                area.AxisX.Maximum = Parser.parser.Count;
                area.AxisX.Minimum = 0;
            }
            //fill top left series
            titleTopLeft.Text             = "Parse";
            seriesTopLeft.ChartType       = SeriesChartType.Spline;
            seriesTopLeft.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = Parser.parser.Count;
            Plots.AddFilter(seriesTopLeft.Points, seriesTopLeft.ChartArea, fcut, m, dt);
            messageTopLeft = "";

            ////fill top right series
            //titleTopRight.Text = "LPF";
            //seriesTopRight.ChartType = SeriesChartType.Spline;
            //seriesTopRight.BorderDashStyle = ChartDashStyle.Solid;
            //Plots.minX = 0;
            //Plots.maxX = Parser.parser.Count;
            //fcut = 200;
            //Plots.AddFilter(seriesTopRight.Points, seriesTopRight.ChartArea, fcut, m, dt);
            //messageTopRight = "";

            //fill bottom left series
            titleBottomLeft.Text             = "BPF";
            seriesBottomLeft.ChartType       = SeriesChartType.FastLine;
            seriesBottomLeft.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = Parser.parser.Count;
            fcut       = 190;
            Plots.AddFilter(seriesBottomLeft.Points, seriesBottomRight.ChartArea, fcut, m, dt);
            messageBottomLeft = "";

            ////fill bottom right series
            //titleBottomRight.Text = "BPF";
            //seriesBottomRight.ChartType = SeriesChartType.Spline;
            //seriesBottomRight.BorderDashStyle = ChartDashStyle.Solid;
            //Plots.minX = 0;
            //Plots.maxX = Parser.parser.Count;
            //fcut = 200;
            //Plots.AddFilter(seriesBottomRight.Points, seriesBottomRight.ChartArea, fcut, m, dt);
            //messageBottomRight = "";

            //fill top right series
            titleTopRight.Text             = "DPF Input";
            seriesTopRight.ChartType       = SeriesChartType.Spline;
            seriesTopRight.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = Parser.parser.Count;
            Plots.PrepareDPF_Filter(seriesTopLeft.Points);
            //Plots.DPF(seriesTopRight.Points, seriesTopRight.ChartArea);
            chartAreaTopRight.AxisX.Maximum = Plots.CalculateBorder(dt);
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                seriesTopRight.Points.AddXY(2 * i * Plots.CalculateBorder(dt) / Plots.FourierArr.Length, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageTopRight = "";

            //fill bottom right series
            titleBottomRight.Text          = "DPF Output";
            seriesTopRight.ChartType       = SeriesChartType.FastLine;
            seriesTopRight.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = Parser.parser.Count;
            Plots.PrepareDPF_Filter(seriesBottomLeft.Points);
            //Plots.DPF(seriesBottomRight.Points, seriesTopRight.ChartArea);
            chartAreaBottomRight.AxisX.Maximum = Plots.CalculateBorder(dt);
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                seriesBottomRight.Points.AddXY(2 * i * Plots.CalculateBorder(dt) / Plots.FourierArr.Length, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageBottomRight = "";
        }
Exemple #2
0
        public void chartBuildVoiceFilter()
        {
            int rate = 0;

            NAudio.Wave.WaveFormat format = null;
            var data = AudioFilter.readWav("input_prep.wav", out rate, out format);

            dt   = 1.0 / rate;
            fcut = 1800;
            m    = 128;
            pointsClear();
            mainTitle.Text = "Filter Voice";
            foreach (var area in chart.ChartAreas)
            {
                area.AxisX.Maximum = data.Length / cutter;
                area.AxisX.Minimum = 0;
            }
            foreach (var series in chart.Series)
            {
                series.Points.SuspendUpdates();
            }
            //fill top left series
            titleTopLeft.Text             = "Input";
            seriesTopLeft.ChartType       = SeriesChartType.FastLine;
            seriesTopLeft.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = data.Length;
            for (int i = 0; i < data.Length; i++)
            {
                seriesTopLeft.Points.AddXY(i, data[i]);
            }
            messageTopLeft = "";

            //fill top right series
            titleTopRight.Text             = "BPF";
            seriesTopRight.ChartType       = SeriesChartType.FastLine;
            seriesTopRight.BorderDashStyle = ChartDashStyle.Solid;
            List <double> filter = Plots.BPF_Filter(400, 900, m, dt);

            float[] data_out = new float[data.Length + 2 * m + 1];
            for (int k = Plots.minX; k < Plots.maxX; k++)
            {
                double y = 0;
                for (int l = Plots.minX; l < data.Length + 2 * m + 1; l++)
                {
                    if (k >= l && (k - l) < filter.Count)
                    {
                        y += filter[k - l] * data[l];
                    }
                }
                seriesTopRight.Points.AddXY(k, y);
                data_out[k] = (float)y;
            }
            messageTopRight = "";

            //cut first m and last m+1
            float[] result = new float[data.Length];
            for (int i = m; i < data.Length + m; i++)
            {
                result[i - m] = data_out[i];
            }


            //fill bottom left series
            titleBottomLeft.Text             = "DPF Input";
            seriesBottomLeft.ChartType       = SeriesChartType.FastLine;
            seriesBottomLeft.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = (int)Plots.CalculateBorder(dt);
            Plots.PrepareDPF_Filter(seriesTopLeft.Points);
            chartAreaBottomLeft.AxisX.Maximum = Plots.CalculateBorder(dt);
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                seriesBottomLeft.Points.AddXY(2 * i * Plots.CalculateBorder(dt) / Plots.FourierArr.Length, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageBottomLeft = "";

            //fill bottom right series
            titleBottomRight.Text             = "DPF Output";
            seriesBottomRight.ChartType       = SeriesChartType.FastLine;
            seriesBottomRight.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = (int)Plots.CalculateBorder(dt);
            Plots.PrepareDPF_Filter(seriesTopRight.Points);
            chartAreaBottomRight.AxisX.Maximum = Plots.CalculateBorder(dt);
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                seriesBottomRight.Points.AddXY(2 * i * Plots.CalculateBorder(dt) / Plots.FourierArr.Length, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageBottomRight = "";

            foreach (var series in chart.Series)
            {
                series.Points.ResumeUpdates();
            }

            AudioFilter.writeWav("outputBPF_.wav", format, result);
        }
Exemple #3
0
        public void chartBuildFilterLDF_Test()
        {
            pointsClear();
            mainTitle.Text = "Filter";
            List <double> lpw = new List <double>();

            //прямоугольник
            double[] d   = { 0.35577019, 0.2436983, 0.07211497, 0.00630165 };
            double   arg = 2 * fcut * dt;

            lpw.Add(arg);
            arg *= Math.PI;

            for (int i = 1; i <= m; i++)
            {
                lpw.Add(Math.Sin(arg * i) / (Math.PI * i));
            }
            //трапеция
            lpw[m] /= 2;

            //окно P310 (Поттера)
            double sumg = lpw[0];
            double sum  = 0;

            for (int i = 1; i <= m; i++)
            {
                sum = d[0];
                arg = Math.PI * i / m;
                for (int k = 1; k <= 3; k++)
                {
                    sum += 2 * d[k] * Math.Cos(arg * k);
                }
                lpw[i] *= sum;
                sumg   += 2 * lpw[i];
            }
            //нормировка
            for (int i = 0; i <= m; i++)
            {
                lpw[i] /= sumg;
            }
            //зеркально отразить график, сдвинуть, чтобы был от 0 до 2m+1 (сейчас он от 0 до m+1)

            //fill top left series
            titleTopLeft.Text             = "m(" + m + ")+1";
            seriesTopLeft.ChartType       = SeriesChartType.Spline;
            seriesTopLeft.BorderDashStyle = ChartDashStyle.Solid;
            foreach (var area in chart.ChartAreas)
            {
                area.AxisX.Maximum = lpw.Count;
                area.AxisX.Minimum = 0;
            }
            for (int i = 0; i < lpw.Count; i++)
            {
                seriesTopLeft.Points.AddXY(i, lpw[i]);
            }
            messageTopLeft = "";
            //fill bottom left series
            titleBottomLeft.Text             = "2m(" + 2 * m + ")+1";
            seriesBottomLeft.ChartType       = SeriesChartType.Spline;
            seriesBottomLeft.BorderDashStyle = ChartDashStyle.Solid;
            foreach (var area in chart.ChartAreas)
            {
                area.AxisX.Maximum = lpw.Count * 2 + 1;
                area.AxisX.Minimum = 0;
            }
            List <double> total_lpw = new List <double>();

            lpw.Reverse();
            total_lpw.AddRange(lpw);

            total_lpw.RemoveAt(total_lpw.Count - 1);
            lpw.Reverse();
            total_lpw.AddRange(lpw);
            for (int i = 0; i < total_lpw.Count; i++)
            {
                seriesBottomLeft.Points.AddXY(i, total_lpw[i]);
            }
            messageBottomLeft = "";
            //fill top right series
            titleTopRight.Text             = "DPF";
            seriesTopRight.ChartType       = SeriesChartType.Spline;
            seriesTopRight.BorderDashStyle = ChartDashStyle.Solid;
            Plots.minX = 0;
            Plots.maxX = total_lpw.Count;
            Plots.PrepareDPF_Filter(seriesBottomLeft.Points);
            chartAreaTopRight.AxisX.Maximum = Plots.CalculateBorder(dt);
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                seriesTopRight.Points.AddXY(2 * i * Plots.CalculateBorder(dt) / Plots.FourierArr.Length, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageTopRight = "";
            //fill bottom right series
            titleBottomRight.Text             = "DPF";
            seriesBottomRight.ChartType       = SeriesChartType.Spline;
            seriesBottomRight.BorderDashStyle = ChartDashStyle.Solid;
            for (int i = 0; i < Plots.FourierArr.Length; i++)
            {
                //seriesTopRight.Points.AddXY(i, Plots.FourierArr[i].C * (2 * m + 1));
            }
            messageTopRight = "";
        }