I want to determine optimal initial states for a FIR/IIR filter to get rid of oscillations and shifts at the initial interval.
I've found that these initial states depend on filter type in the following way (up to a constant):
for k=1:order % (Direct Form II Transposed)
z_hp(k) = sum(1*b(1+k:end)- 0*a(1+k:end)); % for HPF: x=const, y=0
z_lp(k) = sum(1*b(1+k:end)- 1*a(1+k:end)); % for LPF: x=const, y=const
end
Then I should choose z_hp
or z_lp
- how can I do this given only filter coefficients?
By now the solution is empirical - passing 10 points of constant value to the filter and compare the shift in output:
x = ones(1,10);
y_hp = filter(b,a,x,z_hp);
y_lp = filter(b,a,x,z_lp);
if (1-y_lp) > y_hp
z = z_hp;
else
z = z_lp;
end
I wonder if I there is a simple formula for this.