function y = ka_IIR(x, fs, R)
% KA_IIR keskiarvoistaa rekursiivisesti

n = 1 : length(x);
t = n/fs;
y = zeros(size(x));
for k = 2:length(x)
  y(k) = R*y(k-1) + (1-R)*x(k);
end;
figure(1); clf;
plot(t, x, 'b', t, y, 'r');


figure(2); clf;
w = [0 : pi/2048 : pi];  % omega/rad-asteikko
W = (fs/2)*w/pi;         % taajuus/Hz-asteikko
H = (1-R)./(1 - R*exp(-j*w));
plot(W, abs(H));         % amplitudivaste 

grid on;
