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