示例#1
0
 public static double G_total(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");
     }
     return(G_S(tpn) * G_0(tpn) * G_L(tpn));
 }
示例#2
0
 public static double G_0(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");
     }
     return(tpn.p[1, 0].Magnitude * tpn.p[1, 0].Magnitude);
 }
示例#3
0
        public static double G_L(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_l = gamma_L(tpn);
            double  numer   = 1 - Math.Pow(Complex.Abs(gamma_l), 2);
            double  denom   = Math.Pow(Complex.Abs(1 - tpn.p[1, 1] * gamma_l), 2);

            return(numer / denom);
        }
        //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);
        }
示例#5
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);
        }
        protected virtual void UpdateForNewParams()
        {
            //Change DesignFrequency.
            bool UserInputFrequency = double.TryParse(setDesignFrequency_tb.Text, out DesignFrequency);

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

            //Fill out table.
            TwoPortNetworks.TwoPortNetwork temp_tpn = this.Device.ExtractTwoPortNetwork(DesignFrequency);
            ThreadSafe.SetControlTextThreadSafe_uc(this, sParamsChosen_tlp.GetControlFromPosition(0, 0), temp_tpn.m(1, 1).ToString());
            ThreadSafe.SetControlTextThreadSafe_uc(this, sParamsChosen_tlp.GetControlFromPosition(0, 1), temp_tpn.m(1, 2).ToString());
            ThreadSafe.SetControlTextThreadSafe_uc(this, sParamsChosen_tlp.GetControlFromPosition(1, 0), temp_tpn.m(2, 1).ToString());
            ThreadSafe.SetControlTextThreadSafe_uc(this, sParamsChosen_tlp.GetControlFromPosition(1, 1), temp_tpn.m(2, 2).ToString());
        }
示例#7
0
        public static Complex gamma_L(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 dd = tpn.det();

            Complex B2 = 1 + Math.Pow(Complex.Abs(tpn.p[1, 1]), 2) - Math.Pow(Complex.Abs(tpn.p[0, 0]), 2) - Math.Pow(Complex.Abs(dd), 2);
            Complex C2 = tpn.p[1, 1] - dd * Complex.Conjugate(tpn.p[0, 0]);

            Complex numer1 = B2 + Complex.Sqrt(Complex.Pow(B2, 2) - 4 * Complex.Pow(Complex.Abs(C2), 2));
            Complex denom1 = 2 * C2;
            Complex g1     = numer1 / denom1;

            Complex numer2 = B2 - Complex.Sqrt(Complex.Pow(B2, 2) - 4 * Complex.Pow(Complex.Abs(C2), 2));
            Complex denom2 = 2 * C2;
            Complex g2     = numer2 / denom2;

            return(g1.Magnitude < 1 ? g1 : g2);
        }
示例#8
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();
        }
        private void Bgw_Update_DoWork(object sender, DoWorkEventArgs e)
        {
            //Update S-parameter table.
            base.UpdateForNewParams();

            //Replace everything under here with a BGW.

            //Update mu.
            //Report progress, starting calculating mu.
            //string appendTo_stabilityVsFrequency_tb = ""; //For full mu function.
            //List<string> appendTo_conditionalStability_lb = new List<string>(); //For listing of conditional stabilities.
            double prg = 0;

            for (int freq_ind = 0; freq_ind < this.Device.freq.Count; freq_ind++)
            {
                //Assign.
                double f = this.Device.freq[freq_ind];

                //New temp tpn for this freq.
                TwoPortNetworks.TwoPortNetwork tpn = this.Device.ExtractTwoPortNetwork(f);

                //Calculate mu at this freq.
                double mu = tpn.mu();

                //Full fn. versus frequency.
                //appendTo_stabilityVsFrequency_tb += Convert.ToString(f) + ", " + Convert.ToString(mu) + Environment.NewLine; //ok.

                prg = (double)freq_ind / (double)(this.Device.freq.Count) * 50;
                Bgw_Update.ReportProgress((int)prg, new object[] { 1, stabilityVsFrequency_tb, Convert.ToString(f) + ", " + Convert.ToString(mu) + Environment.NewLine });

                if (mu < 1)
                {
                    //ReportProgress in here.
                    Bgw_Update.ReportProgress(0, new object[] { 0, ConditionalStabilityListing_lb, Convert.ToString(freq_ind) + ", " + Convert.ToString(f) + ", " + Convert.ToString(mu) });
                    //appendTo_conditionalStability_lb.Add(Convert.ToString(freq_ind) + ", " + Convert.ToString(f) + ", " + Convert.ToString(mu));
                }
            }
            //ThreadSafe.ListAddRemoveListboxThreadSafe_uc(this, ConditionalStabilityListing_lb, appendTo_conditionalStability_lb);
            //ThreadSafe.SetControlTextThreadSafe_uc(this, stabilityVsFrequency_tb, appendTo_stabilityVsFrequency_tb);

            //Pre-calculate all gammaIN(gammaL) and gammaOUT(gammaS) for all frequencies, store.
            ComplexLinearSpace gammaLS_Sweep = new ComplexLinearSpace(
                new LinearSpace(0.0, 1.0, (int)100),
                new LinearSpace(0.0, 360, (int)100)
                );

            stabilityPlots_FREQ   = new double[this.Device.freq.Count];
            stabilityPlots_IN_XY  = new ComplexXY[this.Device.freq.Count];
            stabilityPlots_OUT_XY = new ComplexXY[this.Device.freq.Count];

            for (int freq_ind = 0; freq_ind < this.Device.freq.Count; freq_ind++)
            {
                //Get the current tpn.
                TwoPortNetworks.TwoPortNetwork tpn = this.Device.ExtractTwoPortNetwork((int)freq_ind);

                //Calculate.
                stabilityPlots_FREQ[freq_ind]   = this.Device.freq[freq_ind];
                stabilityPlots_IN_XY[freq_ind]  = new Microwave.ComplexXY(gammaLS_Sweep, tpn.CalculateGammaIN);
                stabilityPlots_OUT_XY[freq_ind] = new Microwave.ComplexXY(gammaLS_Sweep, tpn.CalculateGammaOUT);

                //Show GUI.
                prg = 50 + 50 * ((double)freq_ind / (double)this.Device.freq.Count);
                Bgw_Update.ReportProgress((int)prg, new object[] { 2, calculationsProgress_lbl, freq_ind + " / " + this.Device.freq.Count });
            }
        }