how to remove Vectors must be the same lengths error in following code?

8 views (last 30 days)
Sir,i have implemented ESPRIT aLGORITHM FOR DIRECTION OF ARRIVAL estimation bt it is giving the above error in plot function.
doas=[-30 -5 40]*pi/180;
P=[1 1 1];
N=10;
K=1024;
d=0.5;
noise_var=1;
r=length(doas);
A=exp(-i*2*pi*d*(0:N-1)'*sin([doas(:).']));
sig=round(rand(r,K)*2-1);
noise=sqrt(noise_var/2)*(randn(N,K)+i*randn(N,K));
X=A*diag(sqrt(P))*sig+noise;
R=X*X'/K;
[Q,D]=eig(R);
[D,I]=sort(diag(D),1,'descend');
Q=Q(:,I);
Qs=Q(:,1:r);
Qn=Q(:,r+1:N);
angles=(-90:.1:90);
phi=linsolve(Qs(1:N-1,:),Qs(2:N,:));
for k=1:length(angles)
ESPRIT_doas=asin(-angle(eig(phi))/(2*pi*d))*180/pi;
end
figure(1)
plot(angles,abs(ESPRIT_doas))
title('music spectrum')
xlabel('angles in degrees')

Answers (2)

Matt J
Matt J on 28 Apr 2013
Edited: Matt J on 28 Apr 2013
When I run your code, I get the following error
Error using plot
Vectors must be the same lengths.
Error in test (line 24)
plot(angles,abs(ESPRIT_doas))
It makes perfect sense. When checking the lengths of "angles" and "ESPRIT_doas", one can easily see that they are not the same:
K>> whos angles ESPRIT_doas
Name Size Bytes Class Attributes
ESPRIT_doas 3x1 24 double
angles 1x1801 14408 double
There is nothing in your code that explains why the 2 should be the same length. You will have to explain that.

Walter Roberson
Walter Roberson on 29 Apr 2013
Your code
for k=1:length(angles)
ESPRIT_doas=asin(-angle(eig(phi))/(2*pi*d))*180/pi;
end
is going to overwrite ESPRIT_doas each time through the loop. You need something closer to
for k=1:length(angles)
ESPRIT_doas(:,k) = asin(-angle(eig(phi))/(2*pi*d))*180/pi;
end
However, notice that you do not change the right hand side of the expression according to k, so all of the values are going to be the same.

Community Treasure Hunt

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

Start Hunting!