function [numa,dena]=tfapprox(num,den,dorder,wmin,wmax) %Transfer approximation program %[numa,dena]=tfapprox(num,den,dorder,wmin,wmax) % %Generates a transfer function approximation with numerator "numa" and %denominator "dena" of desired order "dorder" %over the frequency range of wmin rad/sec to wmax rad/sec starting with %a transfer function with numerator "num" and denominator "den". % %The approximation is achieved by curve fitting the original transfer %function frequency response over the specified frequency range. % %file name "tfapprox.m" %num=numerator polynomial of original transfer function %den=denominator polynomial of original transfer function %wmin=minimum frequency (rad/sec) for a good approximation %wmax=maximum frequency (rad/sec) for a good approximation %numa=numerator polynomial of the transfer function approximation %dena=denominator polynomial of the transfer function approximation %dorder=desired order of the transfer function approximation % norder=dorder-1; Gorig=tf(num,den); [mag,phase,w]=bode(Gorig,{wmin,wmax}); H=freqs(num,den,w); [numa,dena]=invfreqs(H,w,norder,dorder); Gapprox=tf(numa,dena) wm=2*wmax; bode(Gorig,Gapprox,{wmin,wm})