
f1=[0 2500 10000 20000 40000 100000 150000 200000 400000 500000 650000 750000 850000 1000000 1100000];

f=4000:4000:1100000;
d=4000; %distanta intre purtatori

%parametrii liniei de 0,4 mm
r1=[280 280.007 280.11 280.44  281.748 290.433 302.070 316.393 383.562 417.427 465.785 496.218 525.274 566.521 592.628];
l1=10^(-6).*[587.132 587.075 586.738 586.099 584.443 577.878 571.525 564.889 539.437 528.409 514.272 506.304 499.343 490.494 485.481];
c1=10^(-9)*50.*ones(size(f)); %capacitatea liniei
r11=spline(f1,r1,f);
l11=spline(f1,l1,f);

%parametrii liniei de 0,32 mmm
r2=[409 409.009 409.140 409.557 411.216 422.302 437.337 456.086 546.395 592.843 659.743 702.072 742.601 800.272 836.837];
l2=10^(-6).*[607.639 607.639 607.639 607.639 607.639 607.631 607.570 607.327 596.934 579.376 544.657 526.991 515.919 507.415 504.623];
c2=10^(-9)*40.*ones(size(f));
r22=spline(f1,r2,f);
l22=spline(f1,l2,f);

%parametrii liniei de 0,5 mm
r3=[179 179.015 179.244 179.970 182.790 199.608 218.721 239.132 316.230 350.243 396.528 424.835 451.480 488.857 512.317];
l3=10^(-6).*[673.574 673.466 672.923 671.980 669.716 661.677 654.622 647.735 624.309 615.202 604.192 598.261 593.217 586.966 583.495];
c3=c1;
r33=spline(f1,r3,f);
l33=spline(f1,l3,f);

%parametrii liniei de 0,63 mm
r4=[113 113.028 113.442 114.737 119.523 143.115 164.938 185.689 255.575 284.753 323.844 347.542 369.758 400.816 420.264];
l4=10^(-6).*[699.258 697.943 693.361 687.008 674.593 642.718 622.050 605.496 563.845 551.323 537.868 531.212 525.813 519.402 515.956];
c4=10^(-9)*45.*ones(size(f));
r44=spline(f1,r4,f);
l44=spline(f1,l4,f);

%parametrii liniei de 0,9 mm
r5=[55 55.088 56.361 59.941 70.127 100.769 121.866 140.075 197.208 220.365 251.155 269.745 287.138 311.416 326.602];
l5=10^(-6).*[750.796 745.504 731.961 716.775 692.707 647.496 625.140 609.652 579.919 568.287 559.435 555.183 551.784 547.739 545.063];
c5=10^(-9)*40.*ones(size(f));
r55=spline(f1,r5,f);
l55=spline(f1,l5,f);

g=zeros(size(f));
z1=zeros(size(f));
y1=zeros(size(f));
d1=1.1; %lungimea sectiunii de cablu de 0,5 mm
d2=0.45; %lungimea sectiunii de cablu 0,4 mm 
d3=0.5; %lungimea sectiunii de cablu 0,63 mm
d4=0.2; %lungimea sectiunii de cablu 0,32 mm
d5=4; %lungimea sectiunii de cablu 0,32 m;
dg1=0.2; %lungimea sectiunii dervatiei
dg2=0.8;
for k=1:length(f);
z1(k)=r33(k)+2*pi*f(k)*l33(k)*i;
y1(k)=g(k)+2*pi*f(k)*c3(k)*i;
zc1(k)=sqrt(z1(k)/y1(k));
gamma1(k)=sqrt(z1(k)*y1(k));
alfa1(k)=real(gamma1(k));
beta1(k)=imag(gamma1(k));
z5(k)=r55(k)+2*pi*f(k)*l55(k)*i;
y5(k)=g(k)+2*pi*f(k)*c5(k)*i;
zc5(k)=sqrt(z5(k)/y5(k));
gamma5(k)=sqrt(z5(k)*y5(k));
alfa5(k)=real(gamma5(k));
beta5(k)=imag(gamma5(k));
z4(k)=r22(k)+2*pi*f(k)*l22(k)*i;
y4(k)=g(k)+2*pi*f(k)*c2(k)*i;
zc4(k)=sqrt(z4(k)/y4(k));
gamma4(k)=sqrt(z4(k)*y4(k));
alfa4(k)=real(gamma4(k));
beta4(k)=imag(gamma4(k));
z3(k)=r44(k)+2*pi*f(k)*l44(k)*i;
y3(k)=g(k)+2*pi*f(k)*c4(k)*i;
zc3(k)=sqrt(z3(k)/y3(k));
gamma3(k)=sqrt(z3(k)*y3(k));
alfa3(k)=real(gamma3(k));
beta3(k)=imag(gamma3(k));
z2(k)=r11(k)+2*pi*f(k)*l11(k)*i;
y2(k)=g(k)+2*pi*f(k)*c1(k)*i;
zc2(k)=sqrt(z2(k)/y2(k));
gamma2(k)=sqrt(z2(k)*y2(k));
alfa2(k)=real(gamma2(k));
beta2(k)=imag(gamma2(k));
B(k)=zc1(k)*sinh(gamma2(k)*d1);
B2(k)=zc2(k)*sinh(gamma2(k)*d2);
B3(k)=zc3(k)*sinh(gamma3(k)*d3);
B4(k)=zc4(k)*sinh(gamma4(k)*d4);
B5(k)=zc5(k)*sinh(gamma5(k)*d5);

A(k)=cosh(gamma2(k)*d1);
A2(k)=cosh(gamma2(k)*d2);
A3(k)=cosh(gamma3(k)*d3);
A4(k)=cosh(gamma4(k)*d4);
A5(k)=cosh(gamma5(k)*d5);
D2(k)=A2(k);
D(k)=A(k);
D3(k)=A3(k);
D4(k)=A4(k);
D5(k)=A5(k);
C(k)=(1/zc1(k))*sinh(gamma2(k)*d1);
C2(k)=(1/zc2(k))*sinh(gamma2(k)*d2);
C3(k)=(1/zc3(k))*sinh(gamma3(k)*d3);
C4(k)=(1/zc4(k))*sinh(gamma4(k)*d4);
C5(k)=(1/zc5(k))*sinh(gamma5(k)*d5);
end
for k=1:length(f);
zg(k)=zc2(k)*cosh(gamma2(k)*dg1)/sinh(gamma2(k)*dg1);
zg2(k)=zc2(k)*cosh(gamma4(k)*dg2)/sinh(gamma4(k)*dg2);
end
m=ones(2,2);
m1=ones(2,2);
m2=ones(2,2);
m3=ones(2,2);
m4=ones(2,2);
m5=ones(2,2);
m6=ones(2,2);
m7=ones(2,2);
m8=ones(2,2);

rs=105; %rezistenta sarcina
hc2=ones(size(f));

for k=1:length(f);
m1=[1 105;0 1]; %matricea generatorului
m2=[A(k) B(k);C(k) D(k)]; %matricea sectiunii de cablu de 0,5 mm
m3=[A2(k) B2(k);C2(k) D2(k)]; %matricea sectiunii de cablu de 0,4 mm
m4=[A3(k) B3(k);C3(k) D3(k)]; %matricea sectiunii de cablu de 0,63 mm
m5=[A4(k) B4(k);C4(k) D4(k)]; %matricea sectiunii de cablu de 0,32 mm
m6=[A5(k) B5(k);C5(k) D5(k)]; %matricea sectiunii de cablu de 0,9 mm
m7=[1 0;1/zg(k) 1];
m8=[1 0;1/zg(k) 1];
m=m1*m8*m2*m7*m3;
hc(k)= rs/(m(1,1)*rs+m(1,2)); %functia de transfer a canalului
hc2(k)=(abs(hc(k)))^2; %modulul la patrat a functiei canalului
end

%semilogy(f,hc2);grid %graficul functiei de transfer a canalului
%xlabel('Frecventa in Hz');
%ylabel('H (dB)');
%title('Functia de transfer a canalului pentru bucla 8 ETSI')

%calculul paradiafoniei
beta=10^(-13);
for n=1:k
hnxt(n)=beta*f(n)^1.5;
end

hold on
%semilogy(f,hnxt); %graficul paradiafoniei

%calculul telediafoniei
n0=10^(-12.340); %zgomotul de fond
nn=256; %numarul de subcanale
kfext=7.74*10^(-21); %constanta de telediafonie
t=7;
ff=f(1:1,t:t+nn);
hc21=hc2(1:1,t:t+nn);
fext=ones(1,length(ff));
c=1.*ones(1,length(ff));
for j=1:length(ff)
fext(j)= kfext*hc21(j)*d1*(ff(j))^2*(49^(.6))*1000*3.28;
end

hold on
%semilogy(ff,fext); %graficul paradiafoniei
%gtext('H canal');
%gtext('H paradiafonie');
%gtext('H telediafonie');

%calculul capacitatii canalului
cap=0;
for n=1:k
cap=cap+d*log2(1+hc2(n)/(hnxt(n)));
end

%calculul PSD
f0=2.208*10^6;
Kg=.1104;
fhl=f0/2;
fhh=25875;
alfal=11.96;
alfah=7.09;
fl=4000;
lpf=ones(size(f)); 
hpf=ones(size(f));
si=ones(size(f));

for i=1:length(f)
hpf(i)=(f(i)^alfah+fl^alfah)/(f(i)^alfah+fhh^alfah); %calcului functiei de transfer a FTS
si(i)=(sin(pi*f(i)/f0)/(pi*f(i)/f0))^2; 
lpf(i)=fhl^alfal/(f(i)^alfal+fhl^alfal); %calcului functiei de transfer a FTJ
psd(i)=Kg*(2/f0)*si(i)*hpf(i)*lpf(i); %calculul PSD
ps(i)=10*log10(1000*psd(i));
end
hpf1=hpf(1:1,1:10);
psd1=psd(1:1,t:t+nn);
adslfext=fext.*psd1;
adslf=10*log10(1000.*adslfext);
plot(ff,adslf);grid %graficul PSD
xlabel('Frecventa in Hz');
ylabel('DSP (dBm/Hz)');
title('Densitatea spectrala de putere a canalului');

