summaryrefslogtreecommitdiff
path: root/macros/filtic.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/filtic.sci')
-rw-r--r--macros/filtic.sci44
1 files changed, 30 insertions, 14 deletions
diff --git a/macros/filtic.sci b/macros/filtic.sci
index efd48ba..56367b7 100644
--- a/macros/filtic.sci
+++ b/macros/filtic.sci
@@ -1,5 +1,4 @@
-function zf = filtic (b, a, y, x)
-
+function zf = filtic(b,a,y,x)
//This function finds the initial conditions for the delays in the transposed direct-form II filter implementation
//Calling Sequence
//zf = filtic (b, a, y)
@@ -18,19 +17,36 @@ function zf = filtic (b, a, y, x)
// 0.00000 - 22.60000i
// 2.40000 + 0.00000i
// 0.00000 + 0.00000i
-//This function is being called from Octave
-funcprot(0);
-rhs = argn(2)
+ if (argn(2)>4 | argn(2)<3) | (argn(1)>1)
+ error("Wrong number of input agruments.")
+ end
+ if argn(2) < 4, x = []; end
+
+ nz = max(length(a)-1,length(b)-1);
+ zf=zeros(nz,1);
-if(rhs>4 | rhs<3)
- error("Wrong number of input agruments.")
-end
+
+ if length(a)<(nz+1)
+ a(length(a)+1:nz+1)=0;
+ end
+ if length(b)<(nz+1)
+ b(length(b)+1:nz+1)=0;
+ end
+
+ if length(x) < nz
+ x(length(x)+1:nz)=0;
+ end
+ if length(y) < nz
+ y(length(y)+1:nz)=0;
+ end
+
+ for i=nz:-1:1
+ for j=i:nz-1
+ zf(j) = b(j+1)*x(i) - a(j+1)*y(i)+zf(j+1);
+ end
+ zf(nz)=b(nz+1)*x(i)-a(nz+1)*y(i);
+ end
-select(rhs)
-case 3 then
-zf = callOctave("filtic",b,a,y)
-case 4 then
-zf = callOctave("filtic",b,a,y,x)
-end
endfunction
+