public void Reconstruct()
 {
     if (SelectedReconstructSignal != null && SelectedReconstructSignal.HasData())
     {
         var sampledSignal = (SampledSignal)SelectedReconstructSignal;
         ContinuousSignal        signal = new ContinuousSignal();
         List <(double, double)> reconstructed;
         if (SelectedReconstruction.Substring(1, 2) == "R1")
         {
             reconstructed = Reconstruction
                             .ZeroOrderHold(sampledSignal.PointsX.Zip(sampledSignal.PointsY, (d, d1) => (d, d1)).ToList(), sampledSignal.Frequency, NSamples)
                             .ToList();
         }
         else
         {
             reconstructed = Reconstruction
                             .SincReconstruction(sampledSignal.PointsX.Zip(sampledSignal.PointsY, (d, d1) => (d, d1)).ToList(), sampledSignal.Frequency, NSamples)
                             .ToList();
         }
         signal.PointsX = reconstructed.Select(c => c.Item1).ToList();
         signal.PointsY = reconstructed.Select(c => c.Item2).ToList();
         signal.Name    = ReconstructedSignalName + " - R";
         SignalCreator.AddSignal(signal);
     }
 }
示例#2
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);
                    }
                }
            }
        }