q1=.5;y0=2831.31;f=.1; N=100;
n1d=-100:q1:-70;
nd=.05.*n1d;
di1=ones(size(nd));
di2=ones(size(nd));
di3=ones(size(nd));
di4=ones(size(nd));
di5=ones(size(nd));
di6=ones(size(nd));
b=2*pi*y0;x1=zeros(size(nd));%di=zeros(size(nd));

x1=10 .^nd;x=b.*x1;
n1z=-87.18:5:-87.18;
nz=.1.*n1z;
r0=zeros(size(nz));
r0=(b/2)^2.*(10 .^nz);
t1=0:f:.5;
t=2*pi.*t1;P=length(nz);T=length(t);Q=length(nd);s1=ones(T,Q);
ss=ones(T,Q);
for p=1:P
  for l=1:T;
    for q=1:Q;
s=0;
for n=1:100;xn=x(q)*n; bn=besselj(1,xn);
s=s+(1/xn)*bn*cos(t(l)*n)*exp(-n^2*r0(p));
end
s1(l,q)=(1+4*s)^2;ss(l,q)=10*log10(s1(l,q));
%di(q)=n1d(q)+ss(q);
    end

%plot(n1d,di)
%axis([-100 -70 -100 -60])
%hold on
  end
end
%c=ones(T+1,Q);
%c=[n1d;ss];
%disp(c)
u=1
for q=1:Q
di1(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di1-a1);
[m,l]=min(dif);
ss(u,l)
u=2
for q=1:Q
di2(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di2-a1);
[m,l]=min(dif);
ss(u,l)
u=3
for q=1:Q
di3(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di3-a1);
[m,l]=min(dif);
ss(u,l)
u=4
for q=1:Q
di4(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di4-a1);
[m,l]=min(dif);
ss(u,l)
u=5
for q=1:Q
di5(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di5-a1);
[m,l]=min(dif);
ss(u,l)
u=6
for q=1:Q
di6(q)=ss(u,q)+n1d(q);
end
a1=-85*ones(1,Q);
dif=abs(di6-a1);
[m,l]=min(dif);
ss(u,l)
plot(n1d,di1,'+',n1d,di2,'*',n1d,di3,'x',n1d,di4,'.',n1d,di5,'-.',n1d,di6,'-')
axis([-100 -70 -100 -70])
grid
xlabel('Diafonia la intare in dBm0')
ylabel('Diafonia la iesire in dBm0')
title('Accentuarea diafoniei')