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. }
//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); }
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()); }
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 ); } } }
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(); }