function eval_limiter(name)

Tr = 1;     % ms
Tf = 100;  % ms
input_gain = 2;
output_gain = 0.5;

limit_thresh = 0.25;

[x, fs, nbits, opts] = wavread(name);
x = x.*input_gain;

N = fix(length(x));

a_r = 1000/(Tr*fs);
a_f = 1000/(Tf*fs);

y = 0;
for n=1:N
    if (y < abs(x(n)))
		y = y + a_r*(abs(x(n)) - y);
	else
		y = y + a_f*(abs(x(n)) - y);
    end
    env(n) = y;
end;

limiter_gain = limit_thresh./max(limit_thresh, env)';
x_limited = x(1:N).*limiter_gain.*output_gain;

wavwrite(x_limited,fs,'limiter_out.wav');

subplot(2, 1, 1)
plot(0:N-1, x(1:N), 0:N-1, env, 'r-'); grid;
subplot(2, 1, 2)
plot(0:N-1, x_limited, 0:N-1, limiter_gain, 'r-'); grid;


