Saturday, September 05, 2009

MATLAB - plot microwave filter S11 S21





Matlab
-----------
here is a matlab script to plot the simple microwave filter parameter S11 & S21

clc % clear cache memory
format long % format long
clear % clear display
ii=1; % ii counter (note cannot use "i" as a counter since "i" is a complex format)
count=1 ;
ff= 3.8e9 ; %start freq
ff_end=4.2e9 ; %end freq

ff_increment=1e6 ;
for index =ff:ff_increment:ff_end
f0=4e9 ; % center freq
BW=80e6 ; %given bandwidth range

M=[ 0.000000 1.040903 0.000000 0.000005 ;
1.040903 0.000000 0.771515 0.000000 ;
0.000000 0.771515 0.000000 1.040903 ;
0.000005 0.000000 1.040903 0.000000 ] ;
%M is a coupling matrix

lambda=(f0/BW)*(ff/f0-f0/ff) ;
R1=1.32748 ;
R2=1.32748 ;
R=[ i*1.32748 0 0 0 ;
0 0 0 0 ;
0 0 0 0 ;
0 0 0 i*1.32748 ] ;

II=[ 1 0 0 0 ;
0 1 0 0 ;
0 0 1 0 ;
0 0 0 1 ] ;
%identity matrix

AAA=lambda*II-R+M;
ZZ=AAA;

ZZinv=inv(ZZ) ;
YY11=ZZinv(1,1) ;
YY41=ZZinv(4,1) ;
YY44=ZZinv(4,4) ;

S11=1+2*i*R1*YY11;
S21=-2*i*sqrt(R1*R2)*YY41;
S22=S11;
S12=S21 ;

SS=[ S11 S12 ; S21 S22] ;
str=[count ff S11 S12];
disp(sprintf('%d) %d --> %d %d',str) )
ST(ii,1)=ff;
ST(ii,2)=20*log10(S11);
ST(ii,3)=20*log10(S12);
ff=ff+ff_increment;
ii=ii+1;
count=count+1 ;
end


subplot(2,1,1);

plot(ST(:,1),ST(:,2));
%loglog(ST(:,1),ST(:,2));

grid on ;
ylabel('S11 dB') ;
xlabel('frequency')
title(' S11 ')

%hold on ;

subplot(2,1,2);

plot(ST(:,1),ST(:,3),'r'); % plot on linear scale
%loglog(ST(:,1),ST(:,3),'r'); %if want to plot on loglog scale
grid on ;
ylabel('S21 dB') ;
xlabel('frequency')
title(' S21 ')

No comments: