??? Attempted to access nn(26,1); index out of bounds because size(nn)=[25,25].

1 view (last 30 days)
The Matlab program is given below :-
u1=sign(randn(1,5000));
u2=[0,u1];
u2=[0,u1];
u3=[0,u2];
N=length(u1);
n=25;
nn=(randn(n,n)+j*randn(n,n))*0.1;
mu=0.008;
fc=4*10^8;
T1=100*10^(-6);
T2=T1+1/fc;
T3=T2+1/fc;
c=3*10^8;
lambda=c/fc;
d=lambda/2;
DOA1=60;
DOA2=30;
DOA3=-20;
DOA_rad1=DOA1*pi/180;
DOA_rad2=DOA2*pi/180;
DOA_rad3=DOA3*pi/180;
sin1=sin(DOA_rad1);
sin2=sin(DOA_rad2);
sin3=sin(DOA_rad3);
r=zeros(3,n);
y=zeros(3,n);
x=zeros(3,N);
e=zeros(3,N);
B=zeros(3,N);
F=zeros(3,n);
exp1A=0;
exp2A=0;
exp3A=0;
exp1B=zeros(1,n);
exp2B=zeros(1,n);
exp3B=zeros(1,n);
Gain1=0.5*(exp(j*pi/3));
Gain2=0.66*(exp(j*pi/6));
Gain3=1*(exp(j*pi/4));
for k=1:N
U1=Gain1*[u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k)];
U2=Gain2*[u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k),u2(k)];
U3=Gain3*[u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k),u3(k)];
for m=1:n
exp1A=exp(-j*2*pi*fc*T1);
exp2A=exp(-j*2*pi*fc*T2);
exp3A=exp(-j*2*pi*fc*T3);
exp1B(m)=exp(-j*2*pi*(m-1)*d*sin1/lambda);
exp2B(m)=exp(-j*2*pi*(m-1)*d*sin2/lambda);
exp3B(m)=exp(-j*2*pi*(m-1)*d*sin3/lambda);
r(1,m)=U1(m)*exp1A*exp1B(m)+U2(m)*exp2A*exp2B(m)+U3(m)*exp3A*exp3B(m);
y(1,m)=r(1,m)+nn(k,m);
r(2,m)=U2(m)*exp2A*exp2B(m)+U3(m)*exp3A*exp3B(m)+U1(m)*exp1A*exp1B(m);
y(2,m)=r(2,m)+nn(k,m);
r(3,m)=U3(m)*exp3A*exp3B(m)+U1(m)*exp1A*exp1B(m)+U2(m)*exp2A*exp2B(m);
y(3,m)=r(3,m)+nn(k,m);
end;
x(1,k)=y(1,:)*F(1,:)';
e(1,k)=u1(k)-x(1,k);
F(1,:)=F(1,:)+mu*y(1,:)*conj(e(1,k));
B(1,k)=e(1,k)*e(1,k)';
x(2,k)=y(2,:)*F(2,:)';
e(2,k)=u2(k)-x(2,k);
F(2,:)=F(2,:)+mu*y(2,:)*conj(e(2,k));
B(2,k)=e(2,k)*e(2,k)';
x(3,k)=y(3,:)*F(1,:)';
e(3,k)=u3(k)-x(3,k);
F(3,:)=F(3,:)+mu*y(3,:)*conj(e(3,k));
B(3,k)=e(3,k)*e(3,k)';
end;
fiigure(1);clf;
subplot(2,1,1);
semilogy(abs(B(1,:)),'b');
xlim([0,150]);
ylim([10^-7,10^1]);
hold on;
semilogy(abs(B(2,:)),'r');
xlim([0,150]);
ylim([10^-7,10^1]);
hold on;
semilogy(abs(B(3,:)),'g');
hold off;
xlim([0,150]);
ylim([10^-7,10^1]);
grid on; zoom on;
title('Received signal error: 1 white signal,3 DOAs');
xlabel('Sample interval');
ylabel('[U-X]^2 Error');
legend('DOA1','DOA2','DOA3',4);
angle_min=-90*pi/180;
angle=90*pi/180;
angle_incr=1*pi/180;
q=0;
F(1,:)=conj(F(1,:));
F(2,:)=conj(F(2,:));
F(3,:)=conj(F(3,:));
for angle1=angle_min:angle_incr:angle_max
q=q+1;
angle2(q)=2*pi*d*sin(angle1)/lambda;
for t=1:n
G(t)=exp(j*angle2(q)*(t-1));
end;
beam1(q)=abs(F(1,:)*G');
beam2(q)=abs(F(2,:)*G');
beam3(q)=abs(F(3,:)*G');
end;
angle_range=angle_min:angle_incr:angle_max;
figure(2);clf;
polar(angle_range,beam1,'b');
hold on;
polar(angle_range,beam2,'r');
hold on;
polar(angle_range,beam3,'g');
hold off;
view(90,-90);
legend('DOA1','DOA2','DOA3',4);
zoom on;
How can i modify this code to get an output overcoming above mentioned problem ? Please give me modified form/solution...

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 13 Dec 2014
Edited: Azzi Abdelmalek on 13 Dec 2014
y(1,m)=r(1,m)+nn(k,m);
In this line the value of k will reach the value 26, because the size of nn is 25x25, Matlab will not recognize nn(26,m). You can notice that your loop is
for k=1:N %with N=5000
Maybe you need to define nn as
nn=(randn(N,n)+j*randn(N,n))*0.1;
In your code you wrote
U1=Gain1*[u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k),u1(k)];
This can simply done by
U1=Gain1*repmat(u1(k),1,25)
  5 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 13 Dec 2014
u1=sign(randn(1,5000));
u2=[0,u1];
u2=[0,u1];
u3=[0,u2];
N=length(u1);
n=25;
nn=(randn(N,n)+j*randn(N,n))*0.1;
mu=0.008;
fc=4*10^8;
T1=100*10^(-6);
T2=T1+1/fc;
T3=T2+1/fc;
c=3*10^8;
lambda=c/fc;
d=lambda/2;
DOA1=60;
DOA2=30;
DOA3=-20;
DOA_rad1=DOA1*pi/180;
DOA_rad2=DOA2*pi/180;
DOA_rad3=DOA3*pi/180;
sin1=sin(DOA_rad1);
sin2=sin(DOA_rad2);
sin3=sin(DOA_rad3);
r=zeros(3,n);
y=zeros(3,n);
x=zeros(3,N);
e=zeros(3,N);
B=zeros(3,N);
F=zeros(3,n);
exp1A=0;
exp2A=0;
exp3A=0;
exp1B=zeros(1,n);
exp2B=zeros(1,n);
exp3B=zeros(1,n);
Gain1=0.5*(exp(j*pi/3));
Gain2=0.66*(exp(j*pi/6));
Gain3=1*(exp(j*pi/4));
for k=1:N
U1=Gain1*repmat(u1(k),1,n);
U2=Gain2*repmat(u2(k),1,n);
U3=Gain3*repmat(u3(k),1,n);
for m=1:n
exp1A=exp(-j*2*pi*fc*T1);
exp2A=exp(-j*2*pi*fc*T2);
exp3A=exp(-j*2*pi*fc*T3);
exp1B(m)=exp(-j*2*pi*(m-1)*d*sin1/lambda);
exp2B(m)=exp(-j*2*pi*(m-1)*d*sin2/lambda);
exp3B(m)=exp(-j*2*pi*(m-1)*d*sin3/lambda);
r(1,m)=U1(m)*exp1A*exp1B(m)+U2(m)*exp2A*exp2B(m)+U3(m)*exp3A*exp3B(m);
y(1,m)=r(1,m)+nn(k,m);
r(2,m)=U2(m)*exp2A*exp2B(m)+U3(m)*exp3A*exp3B(m)+U1(m)*exp1A*exp1B(m);
y(2,m)=r(2,m)+nn(k,m);
r(3,m)=U3(m)*exp3A*exp3B(m)+U1(m)*exp1A*exp1B(m)+U2(m)*exp2A*exp2B(m);
y(3,m)=r(3,m)+nn(k,m);
end;
x(1,k)=y(1,:)*F(1,:)';
e(1,k)=u1(k)-x(1,k);
F(1,:)=F(1,:)+mu*y(1,:)*conj(e(1,k));
B(1,k)=e(1,k)*e(1,k)';
x(2,k)=y(2,:)*F(2,:)';
e(2,k)=u2(k)-x(2,k);
F(2,:)=F(2,:)+mu*y(2,:)*conj(e(2,k));
B(2,k)=e(2,k)*e(2,k)';
x(3,k)=y(3,:)*F(1,:)';
e(3,k)=u3(k)-x(3,k);
F(3,:)=F(3,:)+mu*y(3,:)*conj(e(3,k));
B(3,k)=e(3,k)*e(3,k)';
end;
figure(1);clf;
subplot(2,1,1);
semilogy(abs(B(1,:)),'b');
xlim([0,150]);
ylim([10^-7,10^1]);
hold on;
semilogy(abs(B(2,:)),'r');
xlim([0,150]);
ylim([10^-7,10^1]);
hold on;
semilogy(abs(B(3,:)),'g');
hold off;
xlim([0,150]);
ylim([10^-7,10^1]);
grid on; zoom on;
title('Received signal error: 1 white signal,3 DOAs');
xlabel('Sample interval');
ylabel('[U-X]^2 Error');
legend('DOA1','DOA2','DOA3',4);
angle_min=-90*pi/180;
angle_max=90*pi/180;
angle_incr=1*pi/180;
q=0;
F(1,:)=conj(F(1,:));
F(2,:)=conj(F(2,:));
F(3,:)=conj(F(3,:));
for angle1=angle_min:angle_incr:angle_max
q=q+1;
angle2(q)=2*pi*d*sin(angle1)/lambda;
for t=1:n
G(t)=exp(j*angle2(q)*(t-1));
end;
beam1(q)=abs(F(1,:)*G');
beam2(q)=abs(F(2,:)*G');
beam3(q)=abs(F(3,:)*G');
end;
angle_range=angle_min:angle_incr:angle_max;
subplot(212);
polar(angle_range,beam1,'b');
hold on;
polar(angle_range,beam2,'r');
hold on;
polar(angle_range,beam3,'g');
hold off;
view(90,-90);
legend('DOA1','DOA2','DOA3',4);
zoom on;
Abdullah
Abdullah on 14 Dec 2014
Tnx u very much I have got desired output figure according to ur correction

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!