diff --git a/Libs/rt-wdf/rt-wdf.cpp b/Libs/rt-wdf/rt-wdf.cpp index 66b10c0..412135a 100644 --- a/Libs/rt-wdf/rt-wdf.cpp +++ b/Libs/rt-wdf/rt-wdf.cpp @@ -228,7 +228,6 @@ std::string wdfRootSimple::getType( ) const { // P O R T //============================================================================== wdfPort::wdfPort( wdfTreeNode *connectedNode ) : Rp( 0 ), - Gp( 0 ), a( 0 ), b( 0 ), connectedNode( connectedNode ) { @@ -549,11 +548,12 @@ void wdfTerminatedLeaf::calculateScatterCoeffs( ) { #pragma mark Terminated Capacitor //============================================================================== wdfTerminatedCap::wdfTerminatedCap( double C, - double sampleRate ) : wdfTerminatedLeaf( ), + double sampleRate, + double alpha) : wdfTerminatedLeaf( ), C( C ), sampleRate( sampleRate ), + alpha( alpha ), prevA( 0 ) { - } //---------------------------------------------------------------------- @@ -562,7 +562,8 @@ double wdfTerminatedCap::calculateUpRes( double sampleRate ) { assert(C > 0 && "capacitance must be a nonzero positive number."); this->sampleRate = sampleRate; - const double R = 1 / ( 2.0 * sampleRate * C ); + const double R = 1 / ( (1.0 + alpha) * sampleRate * C ); + return R; } @@ -584,9 +585,11 @@ std::string wdfTerminatedCap::getType( ) const { #pragma mark Terminated Inductor //============================================================================== wdfTerminatedInd::wdfTerminatedInd( double L, - double sampleRate ) : wdfTerminatedLeaf( ), + double sampleRate, + double alpha ) : wdfTerminatedLeaf( ), L( L ), sampleRate( sampleRate ), + alpha( alpha ), prevA( 0 ) { } @@ -597,7 +600,8 @@ double wdfTerminatedInd::calculateUpRes( double sampleRate ) { assert(L > 0 && "inductance must be a nonzero positive number."); this->sampleRate = sampleRate; - const double R = 2.0 * sampleRate * L ; + const double R = (1.0 + alpha) * sampleRate * L ; + return R; } @@ -761,8 +765,10 @@ std::string wdfUnterminatedSwitch::getType( ) const { #pragma mark Unterminated Capacitor //============================================================================== wdfUnterminatedCap::wdfUnterminatedCap(double C, - double sampleRate ) : wdfRootNode(1), + double sampleRate, + double alpha ) : wdfRootNode(1), sampleRate(sampleRate), + alpha(alpha), prevA(0), prevB(0), C(C) { @@ -787,14 +793,16 @@ std::string wdfUnterminatedCap::getType( ) const { void wdfUnterminatedCap::setPortResistance( double Rp ) { this->Rp = Rp; - reflectionCoeff = (Rp - 1 / (2 * sampleRate * C)) / (Rp + (1 / (2 * sampleRate * C))); + reflectionCoeff = (Rp - 1 / ((1.0 + alpha) * sampleRate * C)) / (Rp + (1 / ((1.0 + alpha) * sampleRate * C))); } #pragma mark Unterminated Inductor //============================================================================== wdfUnterminatedInd::wdfUnterminatedInd( double L, - double sampleRate ) : wdfRootNode(1), + double sampleRate, + double alpha ) : wdfRootNode(1), sampleRate(sampleRate), + alpha(alpha), prevA(0), prevB(0), L(L) { @@ -819,7 +827,7 @@ std::string wdfUnterminatedInd::getType( ) const { void wdfUnterminatedInd::setPortResistance( double Rp ) { this->Rp = Rp; - reflectionCoeff = (Rp - 2 * sampleRate * L) / (Rp + 2 * sampleRate * L); + reflectionCoeff = (Rp - (1.0 + alpha) * sampleRate * L) / (Rp + (1.0 + alpha) * sampleRate * L); } @@ -858,8 +866,8 @@ wdfIdealVSource::wdfIdealVSource( double Vs ) : wdfRootNode(1), //---------------------------------------------------------------------- void wdfIdealVSource::calculateDownB( vec* ascendingWaves, - vec* descendingWaves, - size_t* portIndex) { + vec* descendingWaves, + size_t* portIndex) { descendingWaves->at(*portIndex) = 2 * Vs - ascendingWaves->at(*portIndex); (*portIndex) += numPorts; } @@ -897,5 +905,4 @@ std::string wdfIdealCSource::getType( ) const { //---------------------------------------------------------------------- void wdfIdealCSource::setPortResistance( double Rp ) { this->Rp = Rp; -} - +} \ No newline at end of file diff --git a/Libs/rt-wdf/rt-wdf.h b/Libs/rt-wdf/rt-wdf.h index 43dc280..4eb6048 100644 --- a/Libs/rt-wdf/rt-wdf.h +++ b/Libs/rt-wdf/rt-wdf.h @@ -619,12 +619,6 @@ class wdfPort { */ double Rp; - //---------------------------------------------------------------------- - /** - The inverse WDF port resistance in Siemens - */ - double Gp; - //---------------------------------------------------------------------- /** Incident wave (incoming wave) @@ -1266,6 +1260,26 @@ class wdfTerminatedLeaf: public wdfTreeNode { //============================================================================== class wdfTerminatedCap : public wdfTerminatedLeaf { +protected: + //---------------------------------------------------------------------- + /** + Capacitance in Farad + */ + double C; + /** + Sample rate in Hertz + */ + double sampleRate; + /** + Paramter for alpha transform + */ + double alpha; + + /** + One sample delay element + */ + double prevA; + public: //---------------------------------------------------------------------- /** @@ -1275,9 +1289,12 @@ class wdfTerminatedCap : public wdfTerminatedLeaf { @param C physical capacitance of the component in Farads @param sampleRate sample rate in Hertz + @param alpha parameter in alpha transform, default = 1.0 + (Bilinear transform) */ wdfTerminatedCap( double C, - double sampleRate ); + double sampleRate, + double alpha = 1.0 ); //---------------------------------------------------------------------- /** @@ -1327,20 +1344,6 @@ class wdfTerminatedCap : public wdfTerminatedLeaf { */ virtual std::string getType( ) const; - //---------------------------------------------------------------------- - /** - Capacitance in Farad - */ - double C; - /** - Sample rate in Hertz - */ - double sampleRate; - /** - One sample delay element - */ - double prevA; - }; //============================================================================== @@ -1355,9 +1358,12 @@ class wdfTerminatedInd : public wdfTerminatedLeaf { @param L physical inductance of the component in Henry @param sampleRate sample rate in Hertz + @param alpha parameter in alpha transform, default = 1.0 + (Bilinear transform) */ wdfTerminatedInd( double L, - double sampleRate ); + double sampleRate, + double alpha = 1.0 ); //---------------------------------------------------------------------- /** @@ -1417,6 +1423,10 @@ class wdfTerminatedInd : public wdfTerminatedLeaf { Sample rate in Hertz */ double sampleRate; + /** + Parameter in alpha-transform + */ + double alpha; /** One sample delay element */ @@ -1828,9 +1838,12 @@ class wdfUnterminatedCap : public wdfRootNode { @param C physical capacitance of the component in Farads @param sampleRate sample rate in Hertz + @param alpha parameter in alpha transform, default = 1.0 + (Bilinear transform) */ wdfUnterminatedCap( double C, - double sampleRate ); + double sampleRate, + double alpha = 1.0 ); //---------------------------------------------------------------------- /** @@ -1880,6 +1893,11 @@ class wdfUnterminatedCap : public wdfRootNode { */ double C; + //---------------------------------------------------------------------- + /** + Parameter in alpha-transform + */ + double alpha; }; //============================================================================== @@ -1916,9 +1934,12 @@ class wdfUnterminatedInd : public wdfRootNode { @param L physical inductance of the component in Henry @param sampleRate sample rate in Hertz + @param alpha parameter in alpha transform, default = 1.0 + (Bilinear transform) */ wdfUnterminatedInd( double L, - double sampleRate ); + double sampleRate, + double alpha = 1.0 ); //---------------------------------------------------------------------- /** @@ -1965,6 +1986,11 @@ class wdfUnterminatedInd : public wdfRootNode { Inductance in Henry */ double L; + //---------------------------------------------------------------------- + /** + Parameter in alpha-transform + */ + double alpha; };