blob: 335a18626461c1d9d16fc04bb7ccf37eb46322da (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
// Filters a data sequence using a digital filter
// a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
// - a(2)*y(n-1) - ... - a(na+1)*y(n-na)
// x: input signal
// x has maximum length
function y = filt(b,a,x)
l = length(a);
m = length(b);
n = length(x);
b = [b zeros(1,n-m)];
a = [a zeros(1,n-l)];
y1(1) = b(1)*x(1);
y2(1) = 0;
y = y1 + y2;
y = y/a(1);
for i=2:n
y1 = b(1:i) .* x(i:-1:1);
z1 = sum(y1);
y2 = a(2:i).*y(i-1:-1:1);
z2 = sum(y2);
y3 = z1 - z2;
y3 = y3/a(1);
y = [y y3];
end;
endfunction;
|