/* tdrsp.cpp -- time domain (step) response by inverse laplace transform. * (C) 2000, C. Bond * * Based on "Computer methods for circuit analysis and design," * by J. Vlach and K.Singhai. The authors do not make it clear * that the 'stepping method' (implemented here) produces the * step response of the circuit, not the impulse response. * * Find: h(t) given H(s) * * b(0) + b(1)*s + b(2)*s^2 + ... + b(m-1)*s^(m-1) * H(s) = ----------------------------------------------------- * a(0) + a(1)*s + a(2)*s^2 + ... + a(n-1)*s^(n-1) + s^n * * n >= m, n <= 15, n >= 2 * * To find the impulse response of a filter, multiply the above * Laplace transform by 's'. This is the same as shifting the * numerator polynomial up one order and inserting a zero in the * constant position. * * * Third order Butterworth filter impulse response: * s * H(s) = ------------------------ * 1 + 2*s + 2*s^2 + s^3 */ #include static complex qi[15][5]; int TDResp(double *a,double *b,int n,int m,double tend, double tdel,int kk,double *rsp) { static const complex z[5] = { complex(11.83009373916819,1.593753005885813), complex(11.22085377939519,4.792964167565670), complex(9.933383722175002,8.033106334266296), complex(7.781146264464616,11.36889164904993), complex(4.234522494797000,14.95704378128156)}; static const complex Kp[5] = { complex(16286.62368050479,-139074.7115516051), complex(-28178.11171305163,74357.58237274176), complex(14629.74025233142,-19181.80818501836), complex(-2870.418161032078,1674.109484084304), complex(132.1659412474876,17.47674798877164)}; double x[16],xt[16],t,respon; complex res[5], pk[5], sk, p, pp, resk, xn; int i,j,k,l,idx; // Check input parameters if ((n < 2) || (m > n)) return 1; a[n] = 1.0; // Initialize state vector. for (i=0;i(-1.0,0.0); for (j=0;j