Example #1
0
        private void calculateLmatch_btn_Click(object sender, EventArgs e)
        {
            //.
            Complex ZA   = MenialOperations.ComplexFromString(CalculateLMatch_ZA_tb.Text);
            Complex ZB   = MenialOperations.ComplexFromString(CalculateLMatch_ZB_tb.Text);
            bool    isLP = lowpass_rb.Checked;
            double  freq = Convert.ToDouble(CalculateLmatch_frequency_tb.Text);
            double  Zo   = Convert.ToDouble(CalculateLMatch_Zo_tb.Text);

            //Calculate.
            double L;
            double C;
            bool   seriesNextToLoad = OnePortNetwork.Lmatch(ZA, ZB, isLP, freq, Zo, out L, out C);

            //Show.
            ThreadSafe.SetControlTextThreadSafe_f(this, CalculateLmatch_Output_tb,
                                                  L.ToString() + " H, " + Environment.NewLine +
                                                  ((seriesNextToLoad == isLP) ? "Next to ZA, " : "Next to ZB, ") + Environment.NewLine + //Series next to load XOR isLP.
                                                  (isLP ? "Series, " : "Shunt, ") + Environment.NewLine
                                                  );
            ThreadSafe.SetControlTextThreadSafe_f(this, CalculateLmatch_Output_tb,
                                                  C.ToString() + " F," + Environment.NewLine +
                                                  ((seriesNextToLoad != isLP) ? "Next to ZA, " : "Next to ZB, ") + Environment.NewLine + //Series next to load XNOR isLP.
                                                  (!isLP ? "Series, " : "Shunt, ")
                                                  );

            //Draw ind and cap connected on screen.
        }
Example #2
0
        /// <summary>
        /// Calculates response of Hartley oscillator with respect to change in varactor reverse bias voltage.
        /// </summary>
        /// <param name="C_3A">Capacitance that sits ON EITHER SIDE of varactor Cj.</param>
        /// <param name="C_3B">Capacitance that sits in parallel with C_3A - Cj - C_3A series combination.</param>
        /// <returns></returns>
        static XY CalcHartleyVoltageResponse(double C_3A, double C_3B)
        {
            XY Cj = ImportData.ReadCSVtoXY(ImportData.OutputDataPath);

            XY freq = new XY(Cj.x);
            XY C3   = new XY(Cj.x);

            //This block of variables is necessary for initializing inductance.
            //Inductance is initialized to resonate with first-calculated C3 value at 49.5 MHz.
            double L1;
            double L2;
            double omega0 = 2 * Math.PI * 49.5 * Math.Pow(10, 6); //Frequency I want for voltage == 0.0.
            double beta   = 80.0;

            for (int n = 0; n < freq.N; n++)
            {
                C3.y[n] = C_3B + MenialOperations.Parallel(0.5 * C_3A, Cj.y[n]);
                Hartley_CwBtoL(C3.y[0], omega0, beta, out L1, out L2);
                freq.y[n] = Math.Pow(C3.y[n] * (L1 + L2), -0.50) / (2.0 * Math.PI);

                //Debug.WriteLine("Run " + n + ": " + C3.y[n] + " " + L1 + " " + L2 + " " + freq.y[n]);
            }

            ExportData.WriteXYtoCSV("C:\\Users\\Mehdy Faik\\Desktop\\Work\\Work\\Side Hustles\\Microwave\\Microwave\\Microwave\\Data\\hartley.csv", freq);
            return(freq);
        }
Example #3
0
        private void calculateZs_btn_Click(object sender, EventArgs e)
        {
            //Parse inputs.
            Complex V_A1 = MenialOperations.ComplexFromString(Va1_tb.Text);
            Complex Z_L1 = MenialOperations.ComplexFromString(Rl1_tb.Text);
            Complex V_A2 = MenialOperations.ComplexFromString(Va2_tb.Text);
            Complex Z_L2 = MenialOperations.ComplexFromString(Rl2_tb.Text);

            MessageBox.Show(V_A1.ToString());
            MessageBox.Show(Z_L1.ToString());
            MessageBox.Show(V_A2.ToString());
            MessageBox.Show(Z_L2.ToString());

            Double freq;

            Double.TryParse(frequency_tb.Text, out freq);

            //Pass to calculation.
            Complex Z_S = (V_A2 - V_A1) / ((V_A1 / Z_L1) - (V_A2 / Z_L2));

            MessageBox.Show(Z_S.ToString());
            Complex Z_S_Conj = new Complex(Z_S.Real, -Z_S.Imaginary);
            Complex V_S_Ampl = (V_A2 / Z_L2) * Z_S + V_A2;

            //Populate textboxes.
            SetControlTextThreadSafe(Zs_tb, Z_S.ToString());
            SetControlTextThreadSafe(ZsComponent_tb, Z_S.Real + ", " + Conversions.XtoComponent(Z_S.Imaginary, freq));
            SetControlTextThreadSafe(ZsConj_tb, Z_S_Conj.ToString());
            SetControlTextThreadSafe(ZsConjComponent_tb, Z_S_Conj.Real + ", " + Conversions.XtoComponent(Z_S_Conj.Imaginary, freq));
            SetControlTextThreadSafe(VsAmpl_tb, V_S_Ampl.Magnitude + "<" + V_S_Ampl.Phase);
        }
Example #4
0
        public Complex Access(int row_mag, int col_phase)
        {
            double mag   = this.Mag.v[row_mag];
            double phase = this.Phase.v[col_phase];

            return(MenialOperations.complex_magphase(mag, phase, true));
        }
Example #5
0
 public static double[] AddConstantToVector(double[] x, double constant)
 {
     double[] x_copy = MenialOperations.CopyVector(x);
     for (int n = 0; n < x.Length; n++)
     {
         x_copy[n] += constant;
     }
     return(x_copy);
 }
Example #6
0
        public static int AppendXYtoCSV(string csvPath, XY xy)
        {
            string s         = "";
            bool   overwrite = false;

            double[,] arrayOut = new double[1, 1];

            //If the file doesn't exist, create it.
            if (!File.Exists(csvPath))
            {
                using (StreamWriter sw = new StreamWriter(csvPath, false))
                {
                    sw.Write("");
                }
            }

            using (StreamReader sr = new StreamReader(csvPath))
            {
                s = sr.ReadLine();
                if (String.IsNullOrEmpty(s)) //Empty file -> plot full XY.
                {
                    overwrite = false;
                }
                else //Non-empty file -> read what's there, tack on XY, and overwrite.
                {
                    double[,] curTable = ImportData.ReadCSVtoDoubleArray(csvPath);
                    arrayOut           = new double[curTable.GetLength(0), curTable.GetLength(1) + 1];
                    MenialOperations.copy_matrix(curTable, arrayOut);
                    for (int curRow = 0; curRow < xy.N; curRow++)
                    {
                        arrayOut[curRow, arrayOut.GetLength(1) - 1] = xy.y[curRow];
                    }

                    overwrite = true;
                }
            }
            if (!overwrite)
            {
                WriteXYtoCSV(csvPath, xy);
                return(0);
            }

            else
            {
                WriteDoubleArrayToCSV(csvPath, arrayOut);
                return(0);
            }

            //If there is something here:
            //read in everything
            //add XY.y as a column
            //put everything back out
        }
        //NOT RELATED TO UPDATING.
        private void ConjugateMatch_btn_Click(object sender, EventArgs e)
        {
            //Dummy validation script.
            //Take s-parameters.
            //TwoPortNetworks.TwoPortNetwork tpn = new TwoPortNetworks.TwoPortNetwork(
            //    MenialOperations.complex_magphase(0.869, -159, true),
            //    MenialOperations.complex_magphase(0.031, -9, true),
            //    MenialOperations.complex_magphase(4.250, 61, true),
            //    MenialOperations.complex_magphase(0.507, -117, true),
            //    TwoPortNetworks.STATE.S,
            //    50.0
            //    );
            //
            //ComplexXY gammaIN_TEST_XY = new ComplexXY(new ComplexLinearSpace(100, 100), tpn.CalculateGammaIN);
            //ComplexXY gammaOUT_TEST_XY = new ComplexXY(new ComplexLinearSpace(100, 100), tpn.CalculateGammaOUT);
            //
            //this.PlotGammaXY(gammaIN_TEST_XY, Color.Red);
            //this.PlotGammaXY(gammaOUT_TEST_XY, Color.Blue, false);

            TwoPortNetworks.TwoPortNetwork tpn = this.Device.ExtractTwoPortNetwork(DesignFrequency);

            //Calculate gamma_s and gamma_L.
            Complex gamma_s = PAdesign.gamma_S(tpn);
            Complex gamma_l = PAdesign.gamma_L(tpn);
            Complex Z_s     = Conversions.GammaToZ(gamma_s, this.Device.Zo);
            Complex Z_l     = Conversions.GammaToZ(gamma_l, this.Device.Zo);

            //Compute gain.
            double GS     = PAdesign.G_S(tpn);
            double GL     = PAdesign.G_L(tpn);
            double GTotal = PAdesign.G_total(tpn);

            //Report.
            string CompleteCircuitDesign = "";

            CompleteCircuitDesign += "Gamma S: " + Environment.NewLine +
                                     gamma_s.Magnitude + " " + MenialOperations.radtodeg(gamma_s.Phase) + Environment.NewLine +
                                     Z_s + Environment.NewLine +
                                     Z_s.Real + ", " + Conversions.XtoComponent(Z_s.Imaginary, DesignFrequency) + Environment.NewLine + Environment.NewLine;

            CompleteCircuitDesign += "Gamma L: " + Environment.NewLine +
                                     gamma_l.Magnitude + " " + MenialOperations.radtodeg(gamma_l.Phase) + Environment.NewLine +
                                     Z_l + Environment.NewLine +
                                     Z_l.Real + ", " + Conversions.XtoComponent(Z_l.Imaginary, DesignFrequency) + Environment.NewLine + Environment.NewLine;

            ////These.... might not be correct.....
            //CompleteCircuitDesign += "GS is: " + GS + " (" + 10 * Math.Log10(GS) + "dB)" + Environment.NewLine;
            //CompleteCircuitDesign += "GL is: " + GL + " (" + 10 * Math.Log10(GL) + "dB)" + Environment.NewLine;
            //CompleteCircuitDesign += "GTotal is: " + GTotal + " (" + 10 * Math.Log10(GTotal) + "dB)" + Environment.NewLine;
            //CompleteCircuitDesign += "Mu is: " + tpn.mu();
            //
            ThreadSafe.SetControlTextThreadSafe_uc(this, CompleteCircuitDesign_tb, CompleteCircuitDesign);
        }
Example #8
0
        public static double G_S(TwoPortNetworks.TwoPortNetwork tpn)
        {
            if (tpn.state != TwoPortNetworks.STATE.S)
            {
                throw new Exception("Error: Attempt to call s-param function without two-port network in s-params mode");
            }
            Complex gamma_s  = gamma_S(tpn);
            Complex gamma_in = MenialOperations.gamma_IN(tpn.p, gamma_s);
            double  numer    = 1 - Math.Pow(Complex.Abs(gamma_s), 2);
            double  denom    = Math.Pow(Complex.Abs(1 - gamma_in * gamma_s), 2);

            return(numer / denom);
        }
Example #9
0
        public static double Covariance(double[] x, double[] y)
        {
            if (x.Length != y.Length)
            {
                return(0.0);
            }

            double[] x_shifted = MenialOperations.copy_vector(x);
            double[] y_shifted = MenialOperations.copy_vector(y);

            x_shifted = MenialOperations.shift_vector(x_shifted, -ExpectedValue(x_shifted));
            y_shifted = MenialOperations.shift_vector(y_shifted, -ExpectedValue(y_shifted));

            return(ExpectedValue(MenialOperations.mul_vector(x_shifted, y_shifted)));
        }
Example #10
0
        private void CalculateOscillatorInForm(Complex gammaL)
        {
            //int gx = smithChart.gammacoord_to_imagecoord(g.Real, true);
            //int gy = smithChart.gammacoord_to_imagecoord(g.Imaginary, false);
            //MessageBox.Show("You clicked at " + e.X + ", " + e.Y + ", which is " + g.Real + ", " + g.Imaginary + ", which converts back to " + gx + ", " + gy);

            //So clicking should give you the whole rundown on the rest of the circuit.
            Complex Z_L     = Conversions.GammaToZ(gammaL, BiasedBJT.Zo);
            Complex gammaIN = MenialOperations.gamma_IN(BiasedBJTAtDesignFrequency.p, gammaL);
            Complex Zin     = Conversions.GammaToZ(gammaIN, BiasedBJT.Zo);
            Complex Z_s     = new Complex(Zin.Real / -3, -Zin.Imaginary);
            Complex gammaS  = Conversions.ZtoGamma(Z_s, BiasedBJT.Zo);

            ThreadSafe.SetControlTextThreadSafe_f(this,
                                                  completeCircuitDesign_tb,
                                                  "Desired Gamma In /// Zin: " + MenialOperations.ComplexToStringMagPhase(gammaIN) + " /// " + Zin + Environment.NewLine + Environment.NewLine +
                                                  "Source Z: " + Z_s + " (" + Conversions.XtoComponent(Z_s.Imaginary, DesignFrequency) + ")" + Environment.NewLine + Environment.NewLine +
                                                  "Load Z: " + Z_L + " (" + Conversions.XtoComponent(Z_L.Imaginary, DesignFrequency) + ")"
                                                  );

            //For every other frequency, calculate the gammaIN and gammaOUT with this network.
            //For every other frequency.
            ThreadSafe.SetControlTextThreadSafe_f(this,
                                                  otherOscillationModes_tb, "");
            for (int n = 0; n < BiasedBJT.freq.Count; n++)
            {
                //Calculate gammaIN and gammaOUT.
                Complex gammaIN_otherFrequency  = MenialOperations.gamma_IN(BiasedBJT.p[n], gammaL);
                Complex gammaOUT_otherFrequency = MenialOperations.gamma_OUT(BiasedBJT.p[n], gammaS);

                //If any magnitudes are greater than one.
                if (gammaIN_otherFrequency.Magnitude > 1 || gammaOUT_otherFrequency.Magnitude > 1)
                {
                    //Print them.
                    ThreadSafe.AppendControlTextThreadSafe_f(this,
                                                             otherOscillationModes_tb,
                                                             BiasedBJT.freq[n] + ", " +
                                                             gammaIN_otherFrequency.Magnitude + ", " +
                                                             gammaOUT_otherFrequency.Magnitude + Environment.NewLine
                                                             );
                }
            }
        }
Example #11
0
        public static void Lmatch_Z(Complex ZA, Complex ZB, bool isLP, double freq, out double L, out double C)
        {
            //Calculate Xs s/t GA,new = GB.
            //Add shunt susceptance s/t ZA = ZB.

            Complex YA = 1 / ZA;
            Complex YB = 1 / ZB;

            double a = YB.Real;
            double b = YB.Real * 2 * ZA.Imaginary;
            double c = YB.Real * ZA.Imaginary * ZA.Imaginary + YB.Real * ZA.Real * ZA.Real - ZA.Real;

            double Xs_Add;
            double Xs_Sub;

            MenialOperations.Quadratic(a, b, c, out Xs_Add, out Xs_Sub);

            double Xs = 0;

            //If this is a lowpass match, Xs needs > 0.
            if (isLP)
            {
                Xs = Xs_Add > 0 ? Xs_Add : Xs_Sub;
                Conversions.XtoComponent(Xs, freq, out L);

                Complex YA_Prime = 1 / (ZA + new Complex(0, Xs));
                double  Bp       = YB.Imaginary - YA_Prime.Imaginary;

                Conversions.BtoComponent(Bp, freq, out C);
            }
            //If this is a highpass match, Xs needs < 0.
            else
            {
                Xs = Xs_Add < 0 ? Xs_Add : Xs_Sub;
                Conversions.XtoComponent(Xs, freq, out C);

                Complex YA_Prime = 1 / (ZA + new Complex(0, Xs));
                double  Bp       = YB.Imaginary - YA_Prime.Imaginary;

                Conversions.BtoComponent(Bp, freq, out L);
            }
        }
Example #12
0
        public static void Lmatch_Y(Complex YA, Complex YB, bool isLP, double freq, out double L, out double C)
        {
            Complex ZA = 1 / YA;
            Complex ZB = 1 / YB;

            double a = ZB.Real;
            double b = ZB.Real * 2 * YA.Imaginary;
            double c = ZB.Real * YA.Imaginary * YA.Imaginary + ZB.Real * YA.Real * YA.Real - YA.Real;

            double Bp_Add;
            double Bp_Sub;

            MenialOperations.Quadratic(a, b, c, out Bp_Add, out Bp_Sub);

            double Bp = 0;

            //If this is a lowpass match, Bp needs > 0.
            if (isLP)
            {
                Bp = Bp_Add > 0 ? Bp_Add : Bp_Sub;
                Conversions.BtoComponent(Bp, freq, out C);

                Complex ZA_Prime = 1 / (YA + new Complex(0, Bp));
                double  Xs       = ZB.Imaginary - ZA_Prime.Imaginary;

                Conversions.XtoComponent(Xs, freq, out L);
            }
            //If this is a highpass match, Bp needs < 0.
            else
            {
                Bp = Bp_Add < 0 ? Bp_Add : Bp_Sub;
                Conversions.BtoComponent(Bp, freq, out L);

                Complex ZA_Prime = 1 / (YA + new Complex(0, Bp));
                double  Xs       = ZB.Imaginary - ZA_Prime.Imaginary;

                Conversions.XtoComponent(Xs, freq, out C);
            }
        }
Example #13
0
        public static Complex ComplexFromString(string s, bool degNOTRAD = true)
        {
            //a + jb
            if (s.Contains("j") || (s.Contains("i")))
            {
                s = Regex.Replace(s, @"\s", "");
                Regex RealRegex = new Regex(@"^(-)?(\d+)?(\.)?\d+");
                Regex ImagRegex = new Regex(@"(\+|-)(j|i)(\d+\.)?\d+");

                double real = double.MinValue;
                double.TryParse(RealRegex.Match(s).Value, out real);

                double imag = double.MinValue;
                double.TryParse(ImagRegex.Match(s).Value.Replace("i", "").Replace("j", ""), out imag);

                Complex toReturn = new Complex(real, imag);
                return(toReturn);
            }

            //m<phase. Defaults to this branch if no imaginary is entered. Returns solely re + j0 if no "<" with corresponding phase is entered.
            else
            {
                s = Regex.Replace(s, @"\s", "");
                Regex MagRegex   = new Regex(@"^(\d+)?(\.)?\d+");
                Regex PhaseRegex = new Regex(@"<(-)?(\d+\d.)?\d+");

                double mag = double.MinValue;
                double.TryParse(MagRegex.Match(s).Value, out mag);

                double phase = double.MinValue;
                double.TryParse(PhaseRegex.Match(s).Value.Substring(PhaseRegex.Match(s).Value.IndexOf('<') + 1), out phase);

                Complex toReturn = MenialOperations.complex_magphase(mag, phase, degNOTRAD);
                return(toReturn);
            }
        }
Example #14
0
        private void UpdateForDesignFrequencyChange()
        {
            //Change DesignFrequency variable.
            bool UserInputFrequency = double.TryParse(setDesignFrequency_tb.Text, out DesignFrequency);

            if (!UserInputFrequency)
            {
                MessageBox.Show("Please enter valid frequency");
                return;
            }
            DesignFrequency *= MenialOperations.M;

            //Fill out table.
            BiasedBJTAtDesignFrequency = BiasedBJT.ExtractTwoPortNetwork(DesignFrequency);
            ThreadSafe.SetControlTextThreadSafe_f(this, sParamsChosen_tlp.GetControlFromPosition(0, 0), BiasedBJTAtDesignFrequency.m(1, 1).ToString());
            ThreadSafe.SetControlTextThreadSafe_f(this, sParamsChosen_tlp.GetControlFromPosition(0, 1), BiasedBJTAtDesignFrequency.m(1, 2).ToString());
            ThreadSafe.SetControlTextThreadSafe_f(this, sParamsChosen_tlp.GetControlFromPosition(1, 0), BiasedBJTAtDesignFrequency.m(2, 1).ToString());
            ThreadSafe.SetControlTextThreadSafe_f(this, sParamsChosen_tlp.GetControlFromPosition(1, 1), BiasedBJTAtDesignFrequency.m(2, 2).ToString());

            //So now we have the right two-port network. It's the one at our design-freq of course.
            //But we're interested in mag gammaIN wrt gammaL.

            //You can make this be a scalarField2D that takes in gammaL.real and gammaL.imag, then outputs gammaIN.magnitude.
            //Then you can do the Func<> and Fill() that way and get the whole .csv.
            //Alternatively you can go with the contour plot, which this is not.
            //But luckily it's not much of a change to go.

            //Sweep and calculate.
            double             maxMagnitude = 0;
            double             minMagnitude = double.MaxValue;
            ComplexLinearSpace gammaL_Sweep = new ComplexLinearSpace(
                new LinearSpace(0.0, 1.0, (int)200),
                new LinearSpace(0.0, 2 * Math.PI, (int)200)
                );

            Complex[,] gammaIN_Sweep = new Complex[gammaL_Sweep.Mag.N, gammaL_Sweep.Phase.N];
            for (int mag_ind = 0; mag_ind < gammaL_Sweep.Mag.N; mag_ind++)
            {
                for (int phase_ind = 0; phase_ind < gammaL_Sweep.Phase.N; phase_ind++)
                {
                    Complex gammaL_Current = MenialOperations.complex_magphase(gammaL_Sweep.Mag.v[mag_ind], gammaL_Sweep.Phase.v[phase_ind], false);

                    gammaIN_Sweep[mag_ind, phase_ind] = MenialOperations.gamma_IN(BiasedBJTAtDesignFrequency.p, gammaL_Current);
                    if (gammaIN_Sweep[mag_ind, phase_ind].Magnitude > maxMagnitude)
                    {
                        maxMagnitude      = gammaIN_Sweep[mag_ind, phase_ind].Magnitude;
                        maximizing_gammaL = gammaL_Current;
                        Debug.WriteLine("Max magnitude of " + maxMagnitude + " at " + gammaL_Current);
                    }
                    if (gammaIN_Sweep[mag_ind, phase_ind].Magnitude < minMagnitude)
                    {
                        minMagnitude = gammaIN_Sweep[mag_ind, phase_ind].Magnitude;
                        Debug.WriteLine("Min magnitude of " + minMagnitude + " at " + gammaL_Current);
                    }
                }
            }

            maxMagnitude = Math.Log10(maxMagnitude);
            minMagnitude = Math.Log10(minMagnitude);

            //Plot.
            for (int mag_ind = 0; mag_ind < gammaL_Sweep.Mag.N; mag_ind++)
            {
                for (int phase_ind = 0; phase_ind < gammaL_Sweep.Phase.N; phase_ind++)
                {
                    Complex gammaL_Current = MenialOperations.complex_magphase(gammaL_Sweep.Mag.v[mag_ind], gammaL_Sweep.Phase.v[phase_ind], false);

                    if (gammaIN_Sweep[mag_ind, phase_ind].Magnitude > 1)
                    {
                        int colorFactor = (int)((Math.Log10(gammaIN_Sweep[mag_ind, phase_ind].Magnitude) - minMagnitude) / (maxMagnitude - minMagnitude) * 255);
                        smithChart.plotGamma(gammaL_Current, Color.FromArgb(255, colorFactor, 255 - colorFactor, 0));
                    }
                }
            }

            smithChart_pb.Invalidate();
        }
Example #15
0
        public static XY LTSpiceVaractorImport(string path, string pathOut)
        {
            //String.
            string DataHeader = "Step Information:";
            string curLine;

            //Numerical.
            int    numRuns           = -1;
            int    curRun            = 0;
            double MaxGainForRun     = Double.MinValue;
            double MaxGainFreqForRun = Double.MinValue;
            double CurFreq           = Double.MinValue;
            string CurFreqString     = "";
            double CurGain           = Double.MinValue;
            string CurGainString     = "";

            double[] TestVoltages         = new double[1];
            double[] ResonantFrequencies  = new double[1];
            double[] VaractorCapacitances = new double[1];

            //Circuit constants.
            double L  = 2000 * MenialOperations.n;
            double C1 = 10 * MenialOperations.p;
            double C2 = 10 * MenialOperations.p;

            //Open stream to target file.
            System.IO.StreamReader fr = new System.IO.StreamReader(path);

            while (!fr.EndOfStream)
            {
                curLine = fr.ReadLine();

                //Case 1: Very first occurrence of DataHeader.
                if (curLine.Contains(DataHeader) && numRuns == -1)
                {
                    int.TryParse(curLine.Substring(curLine.IndexOf('/') + 1, curLine.IndexOf(')') - curLine.IndexOf('/') - 1), out numRuns);

                    TestVoltages    = new double[numRuns];
                    TestVoltages[0] = ParseTestParameter(MenialOperations.SubstringProperly(curLine, curLine.IndexOf('=') + 1, curLine.IndexOf('(')).Trim());

                    ResonantFrequencies  = new double[numRuns];
                    VaractorCapacitances = new double[numRuns];
                }
                //Case 2: Non-first occurrence of DataHeader.
                else if (curLine.Contains(DataHeader))
                {
                    //Store necessary data.
                    ResonantFrequencies[curRun] = MaxGainFreqForRun;
                    TestVoltages[curRun + 1]    = ParseTestParameter(MenialOperations.SubstringProperly(curLine, curLine.IndexOf('=') + 1, curLine.IndexOf('(')).Trim());

                    //Reset maxes.
                    MaxGainForRun     = Double.MinValue; //New run -> Recorded max gain from previous run is now obsolete
                    MaxGainFreqForRun = Double.MinValue;
                    curRun++;                            //New run -> new test voltage -> new resonant frequency -> new varactor capacitance.
                }
                //Case 3: Dealing with number.
                else if (curLine.Contains("dB"))
                {
                    //Getting freq.
                    //Take substring from [0] to ind(e) + 5.
                    CurFreqString = MenialOperations.SubstringProperly(curLine, 0, curLine.IndexOf('e') + 5);
                    CurFreq       = ParseScientificNotation(CurFreqString);

                    curLine = curLine.Replace(CurFreqString, ""); //Chop it off.

                    //Getting gain.
                    //Take substring from [ind('(') + 1] to ind(e) + 5.
                    CurGainString = MenialOperations.SubstringProperly(curLine, curLine.IndexOf('(') + 1, curLine.IndexOf('e') + 5);
                    CurGain       = ParseScientificNotation(CurGainString);

                    if (CurGain > MaxGainForRun)
                    {
                        MaxGainFreqForRun = CurFreq;
                        MaxGainForRun     = CurGain;
                    }
                }
            }
            //Case 4: End of file.
            ResonantFrequencies[curRun] = MaxGainFreqForRun;

            //Calculate varactor capacitances from resonant frequencies in test circuit.
            for (int n = 0; n < ResonantFrequencies.Length; n++)
            {
                double combinedCaps             = MenialOperations.Parallel(C1, C2);
                double inductiveResonanceFactor = 1.0 / ((2.0 * Math.PI * ResonantFrequencies[n]) * (2.0 * Math.PI * ResonantFrequencies[n]) * L);

                VaractorCapacitances[n] = (combinedCaps * inductiveResonanceFactor) / (combinedCaps - inductiveResonanceFactor);
            }

            //Now print.
            //Debug.WriteLine("Voltage, Resonant Frequency, Capacitance");
            //Console.WriteLine("Voltage, Resonant Frequency, Capacitance");
            //for (int n = 0; n < ResonantFrequencies.Length; n++)
            //{
            //    Debug.WriteLine(TestVoltages[n] + ", " + ResonantFrequencies[n] + ", " + VaractorCapacitances[n]);
            //    Console.WriteLine(TestVoltages[n] + ", " + ResonantFrequencies[n] + ", " + VaractorCapacitances[n]);
            //}
            using (StreamWriter fw = new StreamWriter(pathOut))
            {
                fw.WriteLine("Voltage, Varactor Capacitance");
                for (int n = 0; n < ResonantFrequencies.Length; n++)
                {
                    fw.WriteLine(TestVoltages[n] + ", " + VaractorCapacitances[n]);
                }
            }

            //Return.
            XY Cj = new Microwave.XY(TestVoltages, VaractorCapacitances);

            return(Cj);

            //Find number of runs.
            //Allocate this # of resFreq terms.

            //Also fill out vector for v.

            //For each line in the file:
            //If it says "Step Information", get this value for v.
            //Get the magnitude value. (dB)
            //If it's greater than the previous magnitude value:
            //Store it.
            //Also store the freq.
            //Else, move to the next line.

            //For each resFreq term:
            //Convert this resFreq to the respective capacitance.
        }