コード例 #1
0
        private void cbTransform_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cbTransform.Text)
            {
            case "Fourier":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => Transformations.FurieXTransform(y));
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.FurieFunction(y));
                addParameters(panelTransformParams, new string[] { });
                break;
            }

            case "ForwardFurie":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ForwardFurie(y).Select(x => x.Imaginary + x.Real).ToArray());
                addParameters(panelTransformParams, new string[] { });
                break;
            }

            case "ReverseFurie":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ReverseFurie(y).Select(x => x.Imaginary + x.Real).ToArray());
                addParameters(panelTransformParams, new string[] { });
                break;
            }



            case "CombFilter":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);

                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        double [] res = Transformations.CombFilter(y, args[0], (int)args[1]);
                        return(res);
                    });
                addParameters(panelTransformParams, new string[] { "g", "M" });
                break;
            }

            case "Spikes(F(x),M,Sigma)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.SpikesFunction(y, args[0], args[1]));
                addParameters(panelTransformParams, new string[] { "M", "sigma" });
                break;
            }

            case "Shift(F(x),shift)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ShiftFunction(y, args[0]));
                addParameters(panelTransformParams, new string[] { "shift" });
                break;
            }

            case "RandomSpikes(x,spikes)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.RandomSpikes(y, (int)args[0], args[1]));
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "spikes", "sigma" });
                break;
            }

            case "ConvolutionWithHeartBeat(x,f0,alpha,hLeft,hRight,hStep)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ConvolutionWithHeartBeat(y, args[0], args[1], args[2], args[3], args[4], Double.Parse(tbStep.Text)));
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "f0", "alpha", "hLeft", "hRight", "hStep" });
                break;
            }

            case "ConvolutionWithPlot":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => {
                        Series series = chart.Series.FindByName(args[0].ToString());
                        int m         = series.Points.Select(item => item.YValues[0]).ToArray().Length;


                        return(y.ToArray());
                    });
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        Series series = chart.Series.FindByName(args[0].ToString());
                        double[] h    = series.Points.Select(item => item.YValues[0]).ToArray();
                        double[] res  = Transformations.ConvolutionWithPlot(h, y);

                        return(Transformations.Normalize(res));
                    });
                addParameters(panelTransformParams, new string[] { "Plot number" });
                break;
            }

            case "Shroeder":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => { return(y.ToArray()); });
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        double g    = 0.9;
                        double[] cg = new double[4];
                        int[] cd    = new int[4];
                        double ag   = 0.9;
                        int[] ad    = new int[2];
                        double k    = 0.2;
                        Random r    = new Random();

                        for (int i = 0; i < cg.Length; i++)
                        {
                            cg[i] = 0.7;
                        }
                        for (int i = 0; i < cd.Length; i++)
                        {
                            cd[i] = (int)(0.05 * r.Next(0, y.Length) + 1);
                        }
                        for (int i = 0; i < ad.Length; i++)
                        {
                            ad[i] = (int)(0.05 * r.Next(0, y.Length) + 1);
                        }


                        return(Transformations.ShroederFilter(y, cg, cd, ag, ad, k));
                    });
                addParameters(panelTransformParams, new string[] {});

                break;
            }

            case "ConvolutionWithLpf(x,fcut,m,dt)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y.Take(y.Length).ToArray());
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        int m = (int)args[1];
                        return(Transformations.ConwolutionWithLpf(y, args[0], m, dT)
                               .Skip(m).Take(y.Length).ToArray());
                    });
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "fcut", "m" });
                break;
            }

            case "ConvolutionWithHpf(x,fcut,m,dt)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y.Take(y.Length).ToArray());
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ConwolutionWithHpf(y, args[0], args[1], dT).Skip((int)args[1]).Take(y.Length).ToArray());
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "fcut", "m" });
                break;
            }

            case "ConvolutionWithBpf(x,fcut1,fcut2,m,dt)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y.Take(y.Length).ToArray());
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ConwolutionWithBpf(y, args[0], args[1], args[2], dT)
                                                                     .Skip((int)args[2])
                                                                     .Take(y.Length)
                                                                     .ToArray());
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "fcut1", "fcut2", "m" });

                break;
            }

            case "ConvolutionWithBsf(x,fcut1,fcut2,m,dt)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y.Take(y.Length).ToArray());
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.ConwolutionWithBsf(y, args[0], args[1], args[2], dT)
                                                                     .Skip((int)args[2])
                                                                     .Take(y.Length)
                                                                     .ToArray());
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "fcut1", "fcut2", "m" });

                break;
            }

            case "AddRandom":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        for (int i = 0; i < args[1]; i++)
                        {
                            y = Transformations.AddRandom(y, args[0]);
                        }

                        return(y);
                    });
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "A", "M" });
                break;
            }

            case "AntiRandom":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                double left  = Double.Parse(tbLeft.Text);
                double right = Double.Parse(tbRight.Text);
                double step  = Double.Parse(tbStep.Text);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.AntiRandomFunction(left, right, step, y, args[0], args[1], args[2]));
                addParameters(panelTransformParams, new string[] { "A", "F", "CanalsCount" });
                break;
            }

            case "AntiShift": {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.AntiShifFunction(y));
                addParameters(panelTransformParams, new string[] { });
                break;
            }

            case "AntiSpike":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.AntiSpikeFunction(y));
                addParameters(panelTransformParams, new string[] { });
                break;
            }

            case "AntiTrend": {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        double [] newY = Transformations.AvgSlidingWindow(y, (int)args[0]);
                        return(y);
                    });
                double tmp = 0;

                addParameters(panelTransformParams, new string[] { "width" });
                break;
            }

            case "LPW":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => Transformations.LpfX((int)args[1]));
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.Lpf(args[0], (int)args[1], args[2]));
                addParameters(panelTransformParams, new string[] { "fcut", "m", "dt" });
                MessageBox.Show("Преобразование фурье умножьте на 2*m+1");
                break;
            }

            case "HPF":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => Transformations.LpfX((int)args[1]));
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.Hpf(args[0], (int)args[1], args[2]));
                addParameters(panelTransformParams, new string[] { "fcut", "m", "dt" });
                MessageBox.Show("Преобразование фурье умножьте на 2*m+1");
                break;
            }

            case "BPF":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => Transformations.LpfX((int)args[2]));
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.Bpf(args[0], args[1], (int)args[2], args[3]));
                addParameters(panelTransformParams, new string[] { "fcut1", "fcut2", "m", "dt" });
                MessageBox.Show("Преобразование фурье умножьте на 2*m+1");
                break;
            }

            case "BSF":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => Transformations.LpfX((int)args[2]));
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.Bsf(args[0], args[1], (int)args[2], args[3]));
                addParameters(panelTransformParams, new string[] { "fcut1", "fcut2", "m", "dt" });
                MessageBox.Show("Преобразование фурье умножьте на 2*m+1");
                break;
            }

            case "CombFilter(x,g,M)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.CombFilter(y, args[0], (int)args[1]));
                addParameters(panelTransformParams, new string[] { "g", "M" });
                break;
            }

            case "UniversalCombFilter(BL,FB,FF,M)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.UniversalCombFilter(y, args[0], args[1], args[2], (int)args[3]));
                addParameters(panelTransformParams, new string[] { "BL", "FB", "FF", "M" });
                break;
            }


            case "Multiply":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => y);
                transformY = new Func <Double[], Double[], Double[]>((y, args) => Transformations.Multiply(y, args[0]));
                addParameters(panelTransformParams, new string[] { "2*m+1" });

                break;
            }

            case "Cut(left_cut, right_cut)":
            {
                transformX = new Func <Double[], Double[], Double[]>((y, args) => {
                        int start          = 0;
                        int end            = y.Length;
                        double leftBorder  = args[0];
                        double rightBorder = args[1];

                        Series series = chart.Series.FindByName(cbArea.Text);
                        for (int i = 0; i < y.Length; i++)
                        {
                            if (y[i] > leftBorder)
                            {
                                start = i;
                                break;
                            }
                        }
                        for (int i = y.Length - 1; i > 0; i--)
                        {
                            if (y[i] < rightBorder)
                            {
                                end = i;
                                break;
                            }
                        }
                        startCut = start;
                        endCut   = end;
                        return(Transformations.CutX(y, start, end));
                    });
                transformY = new Func <Double[], Double[], Double[]>((y, args) => {
                        return(Transformations.CutY(y, startCut, endCut));
                    });
                addParameters(panelTransformParams, new string[] { "left_cut", "right_cut" });

                break;
            }


            default:
            {
                break;
            }
            }
        }