Beispiel #1
0
        public void AddSignal()
        {
            SignalGenerator generator = new SignalGenerator()
            {
                Amplitude   = A,
                FillFactor  = Kw,
                Period      = T,
                StartTime   = T1,
                JumpTime    = Ts,
                JumpN       = Ns,
                Probability = P
            };
            List <double> pointsX = new List <double>();
            List <double> pointsY = new List <double>();
            List <double> samples = new List <double>();

            Func <double, double> func = null;

            switch (SelectedSignalType.Substring(1, 3))
            {
            case "S00":
                func = generator.GenerateSignalForTransform;
                break;

            case "S01":
                func = generator.GenerateUniformDistributionNoise;
                break;

            case "S02":
                func = generator.GenerateGaussianNoise;
                break;

            case "S03":
                func = generator.GenerateSinusoidalSignal;
                break;

            case "S04":
                func = generator.GenerateSinusoidal1PSignal;
                break;

            case "S05":
                func = generator.GenerateSinusoidal2PSignal;
                break;

            case "S06":
                func = generator.GenerateRectangularSignal;
                break;

            case "S07":
                func = generator.GenerateRectangularSymmetricalSignal;
                break;

            case "S08":
                func = generator.GenerateTriangularSignal;
                break;

            case "S09":
                func = generator.GenerateUnitJump;
                break;

            case "S10":
                func = generator.GenerateUnitPulse;
                break;

            case "S11":
                func = generator.GenerateImpulseNoise;
                break;
            }


            if (func != null)
            {
                generator.Func = func;
                if (func.Method.Name.Contains("GenerateUnitPulse"))
                {
                    for (double i = N1 * F; i <= (D + N1) * F; i++)
                    {
                        pointsX.Add(i / F);
                        pointsY.Add(func(i / F));
                    }

                    SampledSignal signal = new SampledSignal();
                    signal.Frequency = F;
                    signal.StartTime = N1;
                    signal.PointsY   = pointsY;
                    signal.PointsX   = pointsX;
                    signal.Name      = SignalName + " - S";
                    AddSignal(signal);
                }
                else if (func.Method.Name.Contains("GenerateImpulseNoise"))
                {
                    for (double i = N1; i <= D + N1; i += 1 / F)
                    {
                        pointsX.Add(i);
                        pointsY.Add(func(0));
                    }

                    SampledSignal signal = new SampledSignal();
                    signal.Frequency = F;
                    signal.StartTime = N1;
                    signal.PointsY   = pointsY;
                    signal.PointsX   = pointsX;
                    signal.Name      = SignalName + " - S";
                    AddSignal(signal);
                }
                else
                {
                    if (IsContinuous)
                    {
                        for (double i = T1; i < T1 + D; i += D / 5000)
                        {
                            pointsX.Add(i);
                            pointsY.Add(func(i));
                        }
                        ContinuousSignal signal = new ContinuousSignal();
                        signal.PointsY = pointsY;
                        signal.PointsX = pointsX;
                        signal.Name    = SignalName + " - C";
                        AddSignal(signal);
                    }
                    if (IsSampled)
                    {
                        for (double i = T1; i < T1 + D; i += 1 / Fp)
                        {
                            samples.Add(func(i));
                        }
                        SampledSignal signal = new SampledSignal();
                        signal.Frequency = Fp;
                        signal.StartTime = T1;
                        signal.PointsY   = samples;
                        signal.Name      = SignalName + " - S";
                        signal.CalculateSamplesX();
                        AddSignal(signal);
                    }
                }
            }
        }
        public void Draw()
        {
            MWViewModel.SelectedTab = SelectedTab;
            SignalGenerator generator = new SignalGenerator()
            {
                Amplitude   = A,
                FillFactor  = Kw,
                Period      = T,
                StartTime   = T1,
                JumpTime    = Ts,
                JumpN       = Ns,
                Probability = P
            };
            List <double> pointsX = new List <double>();
            List <double> pointsY = new List <double>();
            List <double> samples = new List <double>();

            Func <double, double> func = null;

            switch (SelectedSignalType.Substring(1, 3))
            {
            case "S01":
                func = generator.GenerateUniformDistributionNoise;
                break;

            case "S02":
                func = generator.GenerateGaussianNoise;
                break;

            case "S03":
                func = generator.GenerateSinusoidalSignal;
                break;

            case "S04":
                func = generator.GenerateSinusoidal1PSignal;
                break;

            case "S05":
                func = generator.GenerateSinusoidal2PSignal;
                break;

            case "S06":
                func = generator.GenerateRectangularSignal;
                break;

            case "S07":
                func = generator.GenerateRectangularSymmetricalSignal;
                break;

            case "S08":
                func = generator.GenerateTriangularSignal;
                break;

            case "S09":
                func = generator.GenerateUnitJump;
                break;

            case "S10":
                func = generator.GenerateUnitPulse;
                break;

            case "S11":
                func = generator.GenerateImpulseNoise;
                break;

            case "S12":
                func = generator.GenerateSignalForTransformS1;
                break;

            case "S13":
                func = generator.GenerateSignalForTransformS2;
                break;

            case "S14":
                func = generator.GenerateSignalForTransformS3;
                break;
            }


            if (func != null)
            {
                generator.Func = func;
                bool isScattered = false;
                if (func.Method.Name.Contains("GenerateUnitPulse"))
                {
                    isScattered = true;
                    for (double i = N1 * F; i < (D + N1) * F; i++)
                    {
                        pointsX.Add(i / F);
                        pointsY.Add(func(i / F));
                    }
                    MWViewModel.SelectedTab.TabContent.Data.Samples   = pointsY;
                    MWViewModel.SelectedTab.TabContent.Data.Frequency = F;
                    MWViewModel.SelectedTab.TabContent.Data.StartTime = N1;
                    MWViewModel.SelectedTab.TabContent.LoadData(pointsX, pointsY, false);
                    MWViewModel.SelectedTab.TabContent.CalculateSignalInfo(N1, N1 + D, true);
                }
                else if (func.Method.Name.Contains("GenerateImpulseNoise"))
                {
                    isScattered = true;
                    for (double i = N1; i < D + N1; i += 1 / F)
                    {
                        pointsX.Add(i);
                        pointsY.Add(func(0));
                    }
                    MWViewModel.SelectedTab.TabContent.Data.Samples   = pointsY;
                    MWViewModel.SelectedTab.TabContent.Data.Frequency = F;
                    MWViewModel.SelectedTab.TabContent.Data.StartTime = N1;
                    MWViewModel.SelectedTab.TabContent.LoadData(pointsX, pointsY, false);
                    MWViewModel.SelectedTab.TabContent.CalculateSignalInfo(N1, N1 + D, true);
                }
                else
                {
                    for (double i = T1; i < T1 + D; i += 1 / Fp)
                    {
                        samples.Add(func(i));
                    }
                    for (double i = T1; i < T1 + D; i += D / 5000)
                    {
                        pointsX.Add(i);
                        pointsY.Add(func(i));
                    }

                    MWViewModel.SelectedTab.TabContent.Data.Samples   = samples;
                    MWViewModel.SelectedTab.TabContent.Data.Frequency = Fp;
                    MWViewModel.SelectedTab.TabContent.Data.StartTime = T1;
                    MWViewModel.SelectedTab.TabContent.LoadData(pointsX, pointsY, false);
                    MWViewModel.SelectedTab.TabContent.CalculateSignalInfo(T1, T1 + D);
                }

                MWViewModel.SelectedTab.TabContent.IsScattered = isScattered;
                SelectedTab.TabContent.AddOriginal             = false;
                SelectedTab.TabContent.AddSamples = false;
                MWViewModel.SelectedTab.TabContent.DrawCharts();
            }
            //TODO
        }