home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------------------
- //
- // deconv
- //
- // Syntax: A=deconv(b,a)
- //
- // This routine performs "de=convolution." If it is called as A=deconv(b,a)
- // then it deconvolves vector a out of vector b such that the following is true:
- //
- // b=conv(q,a) + r
- //
- // where q is the result of the deconvolution and b is the remainder.
- //
- // If b and a are vectors of polynomial coefficients, then using deconv
- // is equivalent to polynomial division (q is the quotient and r is the
- // remainder).
- //
- // The results are returned in a list:
- // A.q = results of a being deconvolved out of b.
- // A.r = remainder
- //
- // Copyright (C), by Jeffrey B. Layton, 1994
- // Version JBL 940918
- //-------------------------------------------------------------------------------
-
- rfile conv
-
- deconv = function(b,a)
- {
- local(nargs,mb,nb,na,q,r)
-
- // Count number of input arguments
- nargs=0;
- if (exist(b)) {nargs=nargs+1;}
- if (exist(a)) {nargs=nargs+1;}
-
- if (nargs != 2) {
- error("DECONV: Wrong number of input arguments");
- }
-
- mb=b.nr;
- mb=b.nr;
- nb=b.nc;
- nb=a.nc;
- nb=max(mb,nb);
- na=length(a);
-
- if (na > nb) {
- q=0;
- r=b;
- return << q=q; r=r >>
- }
-
- if (a[1] == 0) {
- error("First coefficient of A must be non-zero.")
- }
-
- // Deconvolution and polynomial division are the same operations
- // as a digital filter's impulse response B(z)/A(z):
- q=filter(b, a, [1,zeros(1,nb-na)]);
-
- // if (mb != 1) {
- // q=q(:);
- // }
-
- r=b-conv(q,a);
-
- return << q=q; r=r>>
- };
-