using 'npoles' parameter with rationalfit -凯发k8网页登录
this example shows how to use the 'npoles' parameter to improve the quality of the output of . by default, the rationalfit
function uses 48 or fewer poles to find the rational function that best matches the data. if 48 poles is not enough, it may be advantageous to change the range of the number of poles used by rationalfit
.
first, read in the bandpass filter data contained in the file npoles_bandpass_example.s2p
, and plot the s21
data. next, use the rationalfit
function to fit a rational function to the s21
data, with the 'npoles' parameter set to its default value, and visually compare the results to the original data. lastly, use rationalfit
again, this time specifying a larger number of poles, and see if the result improves.
read and visualize data
s = sparameters('npoles_bandpass_example.s2p'); figure subplot(2,1,1) rfplot(s,2,1,'db') subplot(2,1,2) rfplot(s,2,1,'angle')
analyze output of rationalfit when using default value for 'npoles'
use the function to extract the s21
values, and then call .
s21 = rfparam(s,2,1); datafreq = s.frequencies; defaultfit = rationalfit(datafreq,s21);
warning: achieved only -13.0 db accuracy with 48 poles, not -40.0 db. consider specifying a larger number of poles using the 'npoles' parameter.
use the function to calculate the response of the output of rationalfit
.
respfreq = 2.25e9:2e5:2.75e9; defaultresp = freqresp(defaultfit,respfreq);
compare the original data against the frequency response of the default rational function calculated by rationalfit
.
subplot(2,1,1) plot(datafreq,20*log10(abs(s21)),'.-') hold on plot(respfreq,20*log10(abs(defaultresp))) hold off xlabel('frequency (hz)') ylabel('magnitude (db)') defaultnpoles = numel(defaultfit.a); defaultstr = ['default npoles (uses ',num2str(defaultnpoles),' poles)']; title(defaultstr) legend('original data','default rationalfit','location','best') subplot(2,1,2) plot(datafreq,unwrap(angle(s21))*180/pi,'.-') hold on plot(respfreq,unwrap(angle(defaultresp))*180/pi) hold off xlabel('frequency (hz)') ylabel('angle (degrees)') legend('original data','default rationalfit','location','best')
analyzing how well the output of rationalfit
matches the original data, it appears that while the default values of rationalfit
do a reasonably good job in the center of the bandpass region, the fit is poor on the edges of the bandpass region. it is possible that using a more complex rational function will achieve a better fit.
analyze output of rationalfit when using custom value for 'npoles'
fit the original s21
data, but this time, instruct rationalfit
to use between 49 and 60 poles using the 'npoles' parameter.
customfit = rationalfit(datafreq,s21,'npoles',[49 60]);
customresp = freqresp(customfit,respfreq);
compare the original data against the frequency response of the custom rational function calculated by rationalfit
.
figure subplot(2,1,1) plot(datafreq,20*log10(abs(s21)),'.-') hold on plot(respfreq,20*log10(abs(customresp))) hold off xlabel('frequency (hz)') ylabel('magnitude (db)') customnpoles = numel(customfit.a); customstr = ['npoles = [49 60] (uses ',num2str(customnpoles),' poles)']; title(customstr) legend('original data','custom rationalfit','location','best') subplot(2,1,2) plot(datafreq,unwrap(angle(s21))*180/pi,'.-') hold on plot(respfreq,unwrap(angle(customresp))*180/pi) hold off xlabel('frequency (hz)') ylabel('angle (degrees)') legend('original data','custom rationalfit','location','best')
the fit using a larger number of poles is clearly more precise.