public override void Update() { double[] sb = new double[4]; double[] sa = new double[4]; // Capacitors double c1 = component[0]; double c2 = component[1]; double c3 = component[2]; // Resistors double Ri = component[3]; // R-in double Ro = component[4]; // R-out double R2 = component[5]; // resistor in stack // Pot values, each side double T1 = component[6] * Parameters[P_TREBLE]; double T2 = component[6] * (1 - Parameters[P_TREBLE]); double B0 = component[8] * Parameters[P_BASS]; double M1 = component[7] * Parameters[P_MID]; // If fendermode = true then = 0 double M2 = (FenderMode) ? 0 : component[7] * (1 - Parameters[P_MID]); // numerator // s^0 sb[0] = Ro * 0; // s^1 sb[1] = Ro * (B0 * c1 + B0 * c2 + c1 * M1 + c2 * M1 + c3 * M1 + c1 * M2 + c2 * M2 + c1 * T1); // s^2 sb[2] = Ro * (B0 * c1 * c3 * M1 + B0 * c2 * c3 * M1 + c1 * c3 * M1 * M2 + c2 * c3 * M1 * M2 + B0 * c1 * c3 * R2 + c1 * c3 * M1 * R2 + c1 * c2 * M2 * R2 + c1 * c3 * M2 * R2 + c1 * c3 * M1 * T1 + c1 * c2 * M2 * T1 + c1 * (c2 + c3) * R2 * T1 + c1 * c3 * M1 * T2 + c1 * c2 * M2 * T2 + B0 * c1 * c2 * (R2 + T1 + T2) + c1 * c2 * M1 * (R2 + T1 + T2)); // s^3 sb[3] = Ro * (B0 * c1 * c2 * c3 * R2 * T1 + c1 * c2 * c3 * M2 * R2 * T1 + B0 * c1 * c2 * c3 * M1 * (R2 + T1 + T2) + c1 * c2 * c3 * M1 * M2 * (R2 + T1 + T2)); // denominator // s^0 sa[0] = B0 + M1 + M2 + Ro + T1; // s^1 sa[1] = (B0 * c3 * M1 + c3 * M1 * M2 + B0 * c3 * Ri + c3 * M1 * Ri + c1 * M2 * Ri + c2 * M2 * Ri + B0 * c3 * R2 + c3 * M1 * R2 + c2 * M2 * R2 + c3 * M1 * Ro + c1 * M2 * Ro + c2 * M2 * Ro + c1 * Ri * Ro + B0 * c1 * (Ri + Ro) + c1 * M1 * (Ri + Ro) + c3 * M1 * T1 + c2 * M2 * T1 + c1 * Ri * T1 + c2 * (Ri + R2) * (Ro + T1) + c3 * (Ri + R2) * (M2 + Ro + T1) + B0 * c2 * (Ri + R2 + Ro + T1) + c2 * M1 * (Ri + R2 + Ro + T1) + B0 * c1 * T2 + c1 * M1 * T2 + c1 * M2 * T2 + c1 * T1 * T2 + c1 * Ro * (T1 + T2)); // s^2 sa[2] = (B0 * c1 * c3 * M1 * Ri + c1 * c3 * M1 * M2 * Ri + B0 * c1 * c3 * Ri * R2 + c1 * c2 * M2 * Ri * R2 + B0 * c1 * c3 * M1 * Ro + c1 * c3 * M1 * M2 * Ro + B0 * c1 * c3 * Ri * Ro + B0 * c1 * c3 * R2 * Ro + c1 * c2 * M2 * R2 * Ro + c1 * c2 * M2 * Ri * T1 + B0 * c1 * c2 * (Ri + Ro) * (R2 + T1) + c1 * c2 * M1 * (Ri + Ro) * (R2 + T1) + c2 * c3 * M2 * Ri * (Ro + T1) + c2 * c3 * M2 * R2 * (Ro + T1) + B0 * c2 * c3 * (Ri + R2) * (Ro + T1) + B0 * c2 * c3 * M1 * (Ri + R2 + Ro + T1) + c2 * c3 * M1 * M2 * (Ri + R2 + Ro + T1) + B0 * c1 * c3 * M1 * T2 + c1 * c3 * M1 * M2 * T2 + B0 * c1 * c3 * Ri * T2 + c1 * c2 * M2 * Ri * T2 + B0 * c1 * c3 * R2 * T2 + c1 * c2 * M2 * R2 * T2 + c1 * c2 * M2 * T1 * T2 + B0 * c1 * c2 * (Ri + R2 + Ro + T1) * T2 + c1 * c2 * M1 * (Ri + R2 + Ro + T1) * T2 + c1 * (c2 + c3) * Ri * T1 * (R2 + T2) + c1 * c3 * M2 * R2 * (Ro + T2) + c1 * c3 * M2 * Ri * (R2 + Ro + T2) + c1 * c2 * M2 * Ro * (T1 + T2) + c1 * (c2 + c3) * Ri * Ro * (R2 + T1 + T2) + c1 * c3 * M1 * ((Ri + Ro) * (R2 + T1) + (Ri + R2 + Ro + T1) * T2) + c1 * (c2 + c3) * R2 * (T1 * T2 + Ro * (T1 + T2))); // s^3 sa[3] = (B0 * c1 * c2 * c3 * Ri * Ro * T1 + c1 * c2 * c3 * M2 * Ri * Ro * T1 + B0 * c1 * c2 * c3 * R2 * Ro * T1 + c1 * c2 * c3 * M2 * R2 * Ro * T1 + B0 * c1 * c2 * c3 * M1 * (Ri + Ro) * (R2 + T1) + c1 * c2 * c3 * M1 * M2 * (Ri + Ro) * (R2 + T1) + B0 * c1 * c2 * c3 * Ri * R2 * (Ro + T1) + c1 * c2 * c3 * M2 * Ri * R2 * (Ro + T1) + B0 * c1 * c2 * c3 * Ri * (Ro + T1) * T2 + c1 * c2 * c3 * M2 * Ri * (Ro + T1) * T2 + B0 * c1 * c2 * c3 * R2 * (Ro + T1) * T2 + c1 * c2 * c3 * M2 * R2 * (Ro + T1) * T2 + B0 * c1 * c2 * c3 * M1 * (Ri + R2 + Ro + T1) * T2 + c1 * c2 * c3 * M1 * M2 * (Ri + R2 + Ro + T1) * T2); //System.out.println("b: "+sb[0]+" + "+sb[1]+"s + "+sb[2]+"s^2 + "+sb[3]+"s^3"); //System.out.println("a: "+sa[0]+" + "+sa[1]+"s + "+sa[2]+"s^2 + "+sa[3]+"s^3"); double[] zb = new double[4]; double[] za = new double[4]; Bilinear.Transform(sb, sa, out zb, out za, Fs); this.B = zb; this.A = za; }
public override void Update() { double[] sb = { 361.1423f, 0.4076f }; // 860hz ca double[] sa = { 5403.5f, 1f }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double[] sb = { 4.545e5, 1.002e6 }; double[] sa = { 4.545e5, 2200 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, Fs); this.B = zb; this.A = za; }
public static VertexStore TransformToVxs(this Bilinear bilinearTx, VertexStore src, VertexStore vxs) { int count = src.Count; VertexCmd cmd; double x, y; for (int i = 0; i < count; ++i) { cmd = src.GetVertex(i, out x, out y); bilinearTx.Transform(ref x, ref y); vxs.AddVertex(x, y, cmd); } return(vxs); }
public override void Update() { double R1 = 100e3 * (1 - parameters[P_GAIN]); double R2 = 8.2e3; double c1 = 0.068e-6; double[] sb = { 0, c1 *R2 }; double[] sa = { 1, c1 *(R1 + R2) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 220e3; double R2 = 40e3; double c1 = 0.0022e-6; double c2 = 0.22e-6; double[] sb = { 1, (c1 * R1 + c2 * (R1 + R2)), c1 *c2 *R1 *R2 }; double[] sa = { 1, (c1 * R1 + c2 * R2), c1 *c2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 100e3 * parameters[P_GAIN]; double R2 = 3.3e3; double c1 = 100e-12; double c2 = 0.047e-6; double[] sb = { 1, (c1 * R1 + c2 * (R1 + R2)), c1 *c2 *R1 *R2 }; double[] sa = { 1, (c1 * R1 + c2 * R2), c1 *c2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { double x = this.Parameters[P_PRES]; double C1 = 0.1e-6f; double R14 = 1e3f; double P = 2e3f * x; double[] b = { 1, C1 *P }; double[] a = { 1, C1 *(P + R14) }; double[] zb, za; Bilinear.Transform(b, a, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double c1 = 0.01e-6f; double r1 = 68e3f; double c2 = 250e-12f; double r2 = 1e6f; double[] sb = { 0, c1 *r2, 0 }; double[] sa = { 1, r2 *c2 + c1 * r1 + c1 * r2, r1 *r2 *c1 *c2 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double c4 = 0.02e-6f; double c5 = 0.005e-6f; double r3 = 22e3f * P_USE_R3 + 100; double Rvol = 50e3f; double x = this.Parameters[P_GAIN]; double[] sb = { 0, -c4 * Rvol * x, c4 *Rvol *x *(-c5 * (Rvol + r3) + c5 * Rvol * x) }; double[] sa = { -1, (-c4 * Rvol - c5 * (Rvol + r3) + c5 * Rvol * x), -c4 * c5 * Rvol * (r3 - Rvol * (-1 + x) * x) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double x = this.Parameters[P_VOL]; double C1 = 200e-9f; double C2 = 0.0002e-6f; double R2 = 100e3f * (1 - x); double R1 = 100e3f * x; //double R3 = 140e3f; double[] b = { 0, C1 *R1, C1 *C2 *R1 *R2 }; double[] a = { 1, (C1 * R1 + C1 * R2 + C2 * R2), C1 *C2 *R1 *R2 }; double[] zb, za; Bilinear.Transform(b, a, out zb, out za, this.Fs); this.B = zb; this.A = za; }
public override void Update() { double R1 = 560; double R2 = 47 + 10000 * parameters[P_RUETZ]; // ~ infinite resistance if ruetz = 1 // note, R2 can't go too big since it causes a massive DC offset spike. double C1 = 4.7e-6; double C2 = 2.2e-6; double Gain = 150e3 * parameters[P_GAIN]; double C3 = 100e-12; double[] sb = { 1.0f, (C1 * Gain + C2 * Gain + C3 * Gain + C1 * R1 + C2 * R2), (C1 * C2 * Gain * R1 + C1 * C3 * Gain * R1 + C1 * C2 * Gain * R2 + C2 * C3 * Gain * R2 + C1 * C2 * R1 * R2), (C1 * C2 * C3 * Gain * R1 * R2) }; double[] sa = { 1.0f, (C3 * Gain + C1 * R1 + C2 * R2), (C1 * C3 * Gain * R1 + C2 * C3 * Gain * R2 + C1 * C2 * R1 * R2), (C1 * C2 * C3 * Gain * R1 * R2) }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public override void Update() { var contour = parameters[P_CONTOUR]; if (contour < 0.02) { contour = 0.02; } double R1 = 100; double R2 = 33e3; double R3 = 33e3; double c1 = 0.1e-6; double c2 = 0.047e-6; double c3 = 0.22e-6; double c4 = 0.001e-6; double RO = 100e3; double P1 = 100e3 * contour; double P2 = 100e3 * (1 - contour); double b4 = (c1 * c2 * c3 * c4 * P1 * R2 * R3 * RO + c1 * c2 * c3 * c4 * P1 * P2 * (R2 + R3) * RO); double b3 = (c1 * c2 * c4 * P1 * R2 * R3 + c1 * c2 * c4 * P1 * P2 * (R2 + R3) + c1 * c2 * c3 * P1 * P2 * RO + c2 * c3 * c4 * R2 * R3 * RO + c1 * c3 * c4 * P1 * (R2 + R3) * RO + c2 * c3 * c4 * P2 * (R2 + R3) * RO); double b2 = (c1 * c2 * P1 * P2 + c2 * c4 * R2 * R3 + c1 * c4 * P1 * (R2 + R3) + c2 * c4 * P2 * (R2 + R3) + c1 * c3 * P1 * RO + c2 * c3 * P2 * RO + c3 * c4 * (R2 + R3) * RO); double b1 = (c1 * P1 + c2 * P2 + c4 * (R2 + R3) + c3 * RO); double b0 = 1; double a4 = c1 * c2 * c3 * c4 * (P1 * R1 * (R2 * R3 + P2 * (R2 + R3)) + (P1 * (P2 + R1) * R2 + R1 * R2 * R3 + P1 * (P2 + R1 + R2) * R3 + P2 * R1 * (R2 + R3)) * RO); double a3 = (c2 * c3 * c4 * (R1 * R2 * R3 + R2 * R3 * RO + R1 * (R2 + R3) * RO + P2 * (R2 + R3) * (R1 + RO)) + c1 * (c3 * c4 * (R2 + R3) * (R1 * RO + P1 * (R1 + RO)) + c2 * (c4 * (P2 * R1 + P1 * (P2 + R1)) * R2 + c4 * (R1 * (P2 + R2) + P1 * (P2 + R1 + R2)) * R3 + c3 * (R1 * (R2 * (R3 + RO) + P2 * (R2 + R3 + RO)) + P1 * ((R1 + R2) * (R3 + RO) + P2 * (R1 + R2 + R3 + RO)))))); double a2 = (c3 * c4 * (R2 + R3) * (R1 + RO) + c1 * (c2 * (R1 * (P2 + R2) + P1 * (P2 + R1 + R2)) + c4 * (P1 + R1) * (R2 + R3) + c3 * (R1 * (R2 + R3 + RO) + P1 * (R1 + R2 + R3 + RO))) + c2 * (c4 * (P2 + R1) * R2 + c4 * (P2 + R1 + R2) * R3 + c3 * ((R1 + R2) * (R3 + RO) + P2 * (R1 + R2 + R3 + RO)))); double a1 = (c3 * R1 + c1 * (P1 + R1) + c3 * R2 + c4 * R2 + c2 * (P2 + R1 + R2) + c3 * R3 + c4 * R3 + c3 * RO); double a0 = 1; double[] sb = { b0, b1, b2, b3, b4 }; double[] sa = { a0, a1, a2, a3, a4 }; double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); this.B = zb; this.A = za; }
public static Tuple <double[], double[]> ComputeCoefficients(double fs, bool isHighpass, double cutoffHz, int order) { var T = 1.0 / fs; var warpedWc = 2 / T * Math.Tan(cutoffHz * 2 * Math.PI * T / 2); // don't go over nyquist, with 10 hz safety buffer if (warpedWc >= fs / 2 * 2 * Math.PI) { warpedWc = (fs - 10) / 2 * 2 * Math.PI; } double[] sa = null; double[] sb = new double[order + 1]; sb[0] = 1; Func <double, double> ScaleFreq = (power) => Math.Pow(1.0 / warpedWc, power); if (order == 1) { sa = new[] { 1.0, ScaleFreq(1) }; } else if (order == 2) { sa = new[] { 1.0, 1.4142 * ScaleFreq(1), 1 * ScaleFreq(2) }; } else if (order == 3) { sa = new[] { 1, 2 * ScaleFreq(1), 2 * ScaleFreq(2), 1 * ScaleFreq(3) }; } else if (order == 4) { sa = new[] { 1, 2.613 * ScaleFreq(1), 3.414 * ScaleFreq(2), 2.613 * ScaleFreq(3), 1 * ScaleFreq(4) }; } else if (order == 5) { sa = new[] { 1, 3.236 * ScaleFreq(1), 5.236 * ScaleFreq(2), 5.236 * ScaleFreq(3), 3.236 * ScaleFreq(4), 1 * ScaleFreq(5) }; } else if (order == 6) { sa = new[] { 1, 3.864 * ScaleFreq(1), 7.464 * ScaleFreq(2), 9.142 * ScaleFreq(3), 7.464 * ScaleFreq(4), 3.864 * ScaleFreq(5), 1 * ScaleFreq(6) }; } else { throw new Exception("Orders higher than 6 are not supported"); } if (isHighpass) { // When transforming to high pass, we replace all s with 1/s. // then we multiply both numerator and denominator with s^order. // Since the denom. of a butterworth filter is mirrored, we don't actually need to flip it // but when we flip the numerator, we end up with an s^Order, which also needs to be frequency scaled //Utils.ReverseInPlace(sa); Utils.ReverseInPlace(sb); sb[order] = sb[order] * ScaleFreq(order); } double[] zb, za; Bilinear.Transform(sb, sa, out zb, out za, fs); return(Tuple.Create(zb, za)); }