I would like to use tfestimate
and invfreqz
to determine coefficients in a second order linear system.
Ideally it would look something like this:
Nsamp = 2^16;
t = linspace(0,100,Nsamp);
x = square(t/30) + .1*randn(1,Nsamp);
Num = 1;
Den = [20 2 10];
sys = tf(Num, Den);
y = lsim(sys,x,t);
[txy, phi] = tfestimate(x,y);
[b, a] = invfreqz(txy,phi,2,0);
In this way, I am hoping that the values in b
are good estimates for the original values used in Den
.
However, my values are completely off. If I plot the bode of the system and the tfestimate
, I see that they are not close at all. I have tried fiddling with all the settings in tfestimate
-- window type & size, sampling frequency, nfft, etc but I can't seem to get an accurate answer.
I'm not sure I understand enough about tfestimate
spectral analysis to tune it properly. Or perhaps there is a better to doing it altogether that I don't realize.
Also, I do not have access to the System ID toolbox so I can't use anything from that.