% Program for modeling a CATV channel blocker using lossless lines
% K. A. Connor 
% Updated 20 September 2009
% The parallel combination of two relatively short transmission lines is
% analyzed. The first is a short line with a matched load which represents
% the connection to a TV or CATV box. The second is an open-circuit stub
% line whose properties are chosen to block selected CATV channels. Two
% types of analysis are done. For the first, the open stub length is
% specified and the frequency response of the combination of the two lines
% is determined. In the second, the frequency F is specfied for a range of
% stub lengths. To change conditions, this file must be edited. The
% conditions below are specifically selected for an open stub by setting
% Zl, the stub load, to be very large. The frequency range covers all of
% the CATV bands and a bit more. The characteristic impedance is the usual
% 75 Ohms. The length of the stub is Zl. Since the line to the TV or CATV
% box is matched, its impedance is Zo. The two lines in parallel are
% assumed to be driven by a long, lossless line that represents the main
% cable feed into a house, apartment, etc. from the cable company. 
 
% First Analysis -- Frequency Response for a Given Stub Length
% The frequency range covering all cable channels, the characteristic
% impedance, cable propagation velocity, stub length and stub load are
% given. 

f=[5:.1:100]*1e7;u=2e8;
Zo=75; d=.5; beta=2.*pi.*f./u;Zl=1e9;
lam=2.*pi./beta;% Wavelength

% Input impedance of the open stub

Zin=Zo.*(Zl+j.*Zo.*tan(beta.*d))./(Zo+j.*Zl.*tan(beta.*d));

% Parallel Combination of Zin and Zo 

Ztotal=1./(1./Zin+1./Zo);

% Reflection Coefficient Seen by the Main Transmission Line due to the
% Combination of Zin and Zo

Ref=(Ztotal-Zo)./(Ztotal+Zo);

% Transmission Coefficient for the Same Conditions

Trans=1+Ref;

%Plotting Results

% Zin for the Stub
plot(f,real(Zin),'.',f,imag(Zin),'-',f,abs(Zin));legend('Real Zin', 'Imag Zin', 'Abs Zin');
title('Input Impedance of the Open Stub of Fixed Length d');xlabel('Frequency');grid;

% Reflection Coefficient
figure;plot(f,real(Ref),'.',f,imag(Ref),'-',f,abs(Ref));legend('Real Ref', 'Imag Ref', 'Abs Ref');
title('Reflection Coefficient for Fixed Stub Length d');xlabel('Frequency');grid;

%Transmission Coefficient
figure;plot(f,real(Trans),'.',f,imag(Trans),'-',f,abs(Trans));legend('Real Trans','Imag Trans','Abs Trans');
title('Transmission Coefficient for Fixed Stub Length d');xlabel('Frequency');grid;

% Second Analysis -- Determine the Stub Lengths for a Particular Frequency.
% The Frequncy F should be input by the user along with the range of
% lengths L by editing this file. F is a scalar while L is a vector.

% Specify the frequency to be blocked F and the range of possible stub
% lengths L. 
F=1.75e8;
B=2*pi*F/u;LAM=2*pi/B;
L=[0:LAM/400:2*LAM];

% All of the calculations done for the first type of analysis are repeated.
% The results are plotted in a new figure.
Zin=Zo.*(Zl+j.*Zo.*tan(B.*L))./(Zo+j.*Zl.*tan(B.*L));
Ztotal=1./(1./Zin+1./Zo);
R=(Ztotal-Zo)./(Ztotal+Zo);
T=1+R;

% Plotting the Transmission Coefficient for a Specified Frequency
figure;plot(L,real(T),'.',L,imag(T),'-',L,abs(T));legend('Real T', 'Imag T', 'Abs T');
title('Transmission Coefficient for Selected Frequency for a Range of Open Stub Lengths');xlabel('Length');grid;

% Find the lengths that produce the minimum transmission. Note that this
% may not work properly, since it will find the minimum transmission
% coefficient magnitude abs(T) and its index. There will usually be more
% than one minimum in the selected range of lengths and there is no
% guarantee that the shortest one will be found. The minimum is plotted on
% the last figure, so it is easy to see if the correct one is found. This
% section can be commented out if desired. 

[value,index]=min(abs(T));
Tmin=value;Lmin=L(index);
'Transmission Coefficient and Length to Block Specified Frequency'
Tmin
Lmin
hold on;
plot(Lmin,Tmin,'k^');legend('Real T', 'Imag T', 'Abs T','Lmin');
hold off;

