Exemple #1
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);
        }
Exemple #2
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.
        }