ref: 4fa07020d3c13de61a71d7d4730e059741935799
parent: f0d8dedb45838219f1e56debb2dd24cf2341d804
author: Jeff Snyder <jeff@snyderphonics.com>
date: Thu Sep 26 09:50:39 EDT 2019
added resistance port changing
--- a/LEAF/Inc/leaf-WDF.h
+++ b/LEAF/Inc/leaf-WDF.h
@@ -24,6 +24,7 @@
void tWDFresistor_init(tWDFresistor* const r, float electrical_resistance);
float tWDFresistor_getPortResistance(tWDFresistor* const r);
+void tWDFresistor_setElectricalResistance(tWDFresistor* const r, float electrical_resistance);
void tWDFresistor_setIncidentWave(tWDFresistor* const r, float incident_wave);
float tWDFresistor_getReflectedWave(tWDFresistor* const r);
float tWDFresistor_getVoltage(tWDFresistor* const r);
@@ -95,7 +96,8 @@
void tWDFseriesAdaptor_init(tWDFseriesAdaptor* const r, tWDFresistor* const rL, tWDFcapacitor* const rR);
float tWDFseriesAdaptor_getPortResistance(tWDFseriesAdaptor* const r);
-void tWDFseriesAdaptor_setIncidentWaves(tWDFseriesAdaptor* const r, float incident_wave);
+void tWDFseriesAdaptor_setPortResistances(tWDFseriesAdaptor* const r);
+void tWDFseriesAdaptor_setIncidentWave(tWDFseriesAdaptor* const r, float incident_wave);
float tWDFseriesAdaptor_getReflectedWave(tWDFseriesAdaptor* const r);
float tWDFseriesAdaptor_getVoltage(tWDFseriesAdaptor* const r);
float tWDFseriesAdaptor_getCurrent(tWDFseriesAdaptor* const r);
--- a/LEAF/Src/leaf-WDF.c
+++ b/LEAF/Src/leaf-WDF.c
@@ -17,6 +17,12 @@
r->incident_wave = 0.0f;
r->reflected_wave = 0.0f;
}
+void tWDFresistor_setElectricalResistance(tWDFresistor* const r, float electrical_resistance)
+{
+ r->port_resistance = electrical_resistance;
+ r->port_conductance = 1.0f / electrical_resistance;
+ r->electrical_resistance = electrical_resistance;
+}
float tWDFresistor_getPortResistance(tWDFresistor* const r)
{
return r->port_resistance;
@@ -82,7 +88,7 @@
void tWDFcapacitor_init(tWDFcapacitor* const r, float electrical_capacitance, float sample_rate)
{
- r->port_resistance = 1.0f / (sample_rate * electrical_capacitance); //based on trapezoidal discretization
+ r->port_resistance = 1.0f / (sample_rate * 2.0f * electrical_capacitance); //based on trapezoidal discretization
r->port_conductance = (1.0f / r->port_resistance);
r->electrical_capacitance = electrical_capacitance;
r->incident_wave = 0.0f;
@@ -134,16 +140,30 @@
r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
}
+
+void tWDFseriesAdaptor_setPortResistances(tWDFseriesAdaptor* const r)
+{
+ r->port_resistance_left = tWDFresistor_getPortResistance(r->rL);
+ r->port_resistance_right = tWDFcapacitor_getPortResistance(r->rR);
+ r->port_resistance_up = r->port_resistance_left + r->port_resistance_right;
+ r->port_conductance_up = 1.0f / r->port_resistance_up;
+ r->port_conductance_left = 1.0f / r->port_resistance_left;
+ r->port_conductance_right = 1.0f / r->port_resistance_right;
+ r->gamma_zero = 1.0f / (r->port_resistance_right + r->port_resistance_left);
+}
+
float tWDFseriesAdaptor_getPortResistance(tWDFseriesAdaptor* const r)
{
return r->port_resistance_up;
}
-void tWDFseriesAdaptor_setIncidentWaves(tWDFseriesAdaptor* const r, float incident_wave)
+void tWDFseriesAdaptor_setIncidentWave(tWDFseriesAdaptor* const r, float incident_wave)
{
float gamma_left = r->port_resistance_left * r->gamma_zero;
float gamma_right = r->port_resistance_right * r->gamma_zero;
- tWDFresistor_setIncidentWave(r->rL, (-1.0f * gamma_left * incident_wave) + ((1.0f - gamma_left) * tWDFresistor_getReflectedWave(r->rL)) - (gamma_left * tWDFcapacitor_getReflectedWave(r->rR)));
- tWDFcapacitor_setIncidentWave(r->rR, (-1.0f * gamma_right * incident_wave) + ((-1.0f * gamma_right) * tWDFresistor_getReflectedWave(r->rL)) + (1.0f - gamma_right * tWDFcapacitor_getReflectedWave(r->rR)));
+ float left_wave = tWDFresistor_getReflectedWave(r->rL);
+ float right_wave = tWDFcapacitor_getReflectedWave(r->rR);
+ tWDFresistor_setIncidentWave(r->rL, (-1.0f * gamma_left * incident_wave) + ((1.0f - gamma_left) * left_wave) - (gamma_left * right_wave));
+ tWDFcapacitor_setIncidentWave(r->rR, (-1.0f * gamma_right * incident_wave) + ((-1.0f * gamma_right) * left_wave) + ((1.0f - gamma_right) * right_wave));
}
float tWDFseriesAdaptor_getReflectedWave(tWDFseriesAdaptor* const r)
--- a/LEAF/leaf.h
+++ b/LEAF/leaf.h
@@ -58,6 +58,7 @@
#include "./Inc/leaf-crusher.h"
#include "./Inc/leaf-wavefolder.h"
#include "./Inc/leaf-tables.h"
+#include "./Inc/leaf-WDF.h"
#endif