MATLAB: Do I get different results when I use the BANDWIDTH and FREQRESP functions in Control System Toolbox 8.3 (R2009a)

Control System Toolboxdiscrepnacyreltolrtol

I generate a fifth order discrete time system using the following command:
sysd = c2d(tf(1, [1 1])^5, 1);
and use the BANDWIDTH function to calculate the crossover frequency, which is the first frequency where the gain of the system drops below 70.79 percent (-3dB) of its DC value given by:
A1 = 10^(-3/20); % Ideal crossover frequency
BW = bandwidth(sysd);
I then use the FREQRESP command to calculate the crossover frequency using the bandwidth returned by the BANDWIDTH function:
A = abs(freqresp(sysd,BW));
The resulting answer (A = 0.7085) is different from the value that I expect (A1 = 0.7079). Why am I getting different results?

Best Answer

This is expected behavior. For transfer function (TF) and zero pole gain (ZPK) models, a fast search algorithm is used to determine the crossover frequency, which has a 1e-3 relative accuracy target. This means that the crossover frequency is determined with only 0.1% accuracy, which in turn means that the gain at this frequency won't be exactly -3dB. For example, for the same fifth order system 'sysd' (defined in the Summary section above), the relative accuracy can be computed as follows:
rel_acc = abs(1-A/A1);
The relative accuracy is equal to 8.0727e-004, which is less than 0.1%.
As a workaround, if higher accuracy is desired, you can modify the "rtol" parameter in the BANDWIDTH function as follows.
NOTE: Making the modification mentioned in the workaround below may affect the behavior of the BANDWIDTH function itself, and any built-in functions or custom functions that make use of it. Please make sure that you retain a copy of the file being modified before you modify it so that you may be able to revert to it when necessary.
1. Execute the following command to open the BANDWIDTH function for LTI models:
edit(fullfile(matlabroot, '\toolbox\control\control\+ltipack\@ltidata\bandwidth.m'))
where 'matlabroot' is to be replaced by the path returned by executing the command 'matlabroot' at the MATLAB prompt.
2. Navigate to line 8 in the file, and set the parameter "rtol" to a value such as 1e-6, and then save it.