private void PadOpenShortMethod(ref Curve fileDUTPattern)
        {
            int countOfPoints = _fileOpenPattern.CountOfPoints;
            for (int i = 1; i <= countOfPoints; i++)
            {
                double[] openPatternPoints = _fileOpenPattern.GetPoints(i);

                Matrix
                       pad = new Matrix(_filePadPattern.GetPoints(i)),
                       open = new Matrix(openPatternPoints),
                       shortM = new Matrix(_fileShortPattern.GetPoints(i)),
                       DUT = new Matrix(fileDUTPattern.GetPoints(i));

                Matrix
                    yPad = pad.FromSToY,
                    yOpen = open.FromSToY,
                    yShort = shortM.FromSToY,
                    yDUT = DUT.FromSToY;

                Matrix
                    yRes = ((yDUT - yPad).Reverse - (yShort - yPad).Reverse).Reverse - ((yOpen - yPad).Reverse - (yShort - yPad).Reverse).Reverse,
                    res = yRes.FromYToS;

                fileDUTPattern.ChangePoints(i, res.A.Re, res.A.Im, res.C.Re, res.C.Im, res.B.Re, res.B.Im, res.D.Re, res.D.Im);
            }
        }
 public void AddCurve(Curve calibrCurve)
 {
     // калибруем только |S21|, alpha(S21), |S12|, alpha(S12)
     for (int i = 1; i <= _countOfPoints; i++)
     {
         for (int k = 3; k <= 6; k++)
             this._massOfPoints[k][i] += calibrCurve._massOfPoints[k][i];
     }
 }
        private void OpenMethod(ref Curve fileDUTPattern)
        {
            int countOfPoints = _fileOpenPattern.CountOfPoints;
            for (int i = 1; i <= countOfPoints; i++)
            {
                double[] openPatternPoints = _fileOpenPattern.GetPoints(i);

                Matrix
                       open = new Matrix(openPatternPoints),
                       DUT = new Matrix(fileDUTPattern.GetPoints(i));

                Matrix res = (DUT.FromSToY - open.FromSToY).FromYToS;

                fileDUTPattern.ChangePoints(i, res.A.Re, res.A.Im, res.C.Re, res.C.Im, res.B.Re, res.B.Im, res.D.Re, res.D.Im);
            }
        }
        private void L2LMethod(ref Curve fileDUTPattern)
        {
            int countOfPoints = _fileLinePattern.CountOfPoints;
            for (int i = 1; i <= countOfPoints; i++)
            {
                double[] linePatternPoints = _fileLinePattern.GetPoints(i);

                Matrix
                       line = new Matrix(linePatternPoints),
                       twoLine = new Matrix(_fileTwoLinePattern.GetPoints(i)),
                       DUT = new Matrix(fileDUTPattern.GetPoints(i));

                Matrix
                    aLine = line.FromSToA,
                    aTwoLine = twoLine.FromSToA;

                Matrix
                       PP = aLine * aTwoLine.Reverse * aLine,
                       PR = PP.FromPPToPR,
                       PL = PP.FromPPToPL,
                       L = PL.Reverse * aLine * PR.Reverse;

                Matrix
                    res = ((PL * L).Reverse * DUT.FromSToA * (L * PR).Reverse).FromAtoS;

                fileDUTPattern.ChangePoints(i, res.A.Re, res.A.Im, res.C.Re, res.C.Im, res.B.Re, res.B.Im, res.D.Re, res.D.Im);
            }
        }
        private void CalcAndSaveResult(string pathToSaveFolder)
        {
            for (int n = 0; n < _pathesToFileDUTPattern.Length; n++)
            {
                Curve fileDUTPattern = new Curve(_pathesToFileDUTPattern[n]);
                fileDUTPattern.SetFormatOfPoints("RI");
                fileDUTPattern.AddNewComment("This is de-embedded s2p file");

                string newName = Path.GetFileNameWithoutExtension(_pathesToFileDUTPattern[n]) + "_deembedded" + Path.GetExtension(_pathesToFileDUTPattern[n]);

                switch (_currMethod)
                {
                    case "open":
                        OpenMethod(ref fileDUTPattern); break;
                    case "l-2l":
                        L2LMethod(ref fileDUTPattern); break;
                    case "open-short":
                        OpenShortMethod(ref fileDUTPattern); break;
                    case "pad-open-short":
                        PadOpenShortMethod(ref fileDUTPattern); break;
                }

                fileDUTPattern.SaveFile(pathToSaveFolder + "\\" + newName);
            }
        }
        public void PadOpenShortMethodDeEmbedding(string pathToFilePadPattern, string pathToFileOpenPattern, string pathToFileShortPattern, string[] pathesToFileDUTPattern, string pathToSaveFolder)
        {
            _pathesToFileDUTPattern = (string[])pathesToFileDUTPattern.Clone();

            _pathToFilePadPattern = pathToFilePadPattern;
            _pathToFileOpenPattern = pathToFileOpenPattern;
            _pathToFileShortPattern = pathToFileShortPattern;

            _filePadPattern = new Curve(pathToFilePadPattern);
            _fileOpenPattern = new Curve(pathToFileOpenPattern);
            _fileShortPattern = new Curve(pathToFileShortPattern);
            _filePadPattern.SetFormatOfPoints("RI");
            _fileOpenPattern.SetFormatOfPoints("RI");
            _fileShortPattern.SetFormatOfPoints("RI");

            _currMethod = "pad-open-short";

            CalcAndSaveResult(pathToSaveFolder);
        }
        public void L2LMethodDeEmbedding(string pathToFileLinePattern, string pathToFileTwoLinePattern, string[] pathesToFileDUTPattern, string pathToSaveFolder)
        {
            _pathesToFileDUTPattern = (string[])pathesToFileDUTPattern.Clone();

            _pathToFileLinePattern = pathToFileLinePattern;
            _pathToFileTwoLinePattern = pathToFileTwoLinePattern;

            _fileLinePattern = new Curve(pathToFileLinePattern);
            _fileTwoLinePattern = new Curve(pathToFileTwoLinePattern);
            _fileLinePattern.SetFormatOfPoints("RI");
            _fileTwoLinePattern.SetFormatOfPoints("RI");

            _currMethod = "l-2l";

            CalcAndSaveResult(pathToSaveFolder);
        }