How to rectify the error in this code?

조회 수: 1 (최근 30일)
Sadiq Akbar
Sadiq Akbar 2021년 5월 27일
댓글: DGM 2021년 5월 28일
I found a code for ESPRIT algorithm as below but it gives me this error:
Undefined function or variable 'theatest3'.
Error in ESPRIT_1D_Thesis (line 76)
thetaest=[thetaest1 thetaest2 theatest3];
How can I rectify the error? My code is as below:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matlab Code for ESPRIT Algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d=0.5;
lamda=1;
thetaest1=[];
thetaest2=[];
thetaest3=[];
for i=1:2500; % number for independent trials
M=8;%6; % number of antenna elements
N=200; % number of snapshot
%input data
data1=sign(2*rand(1,N)-1);
data2=sign(2*rand(1,N)-1);
data3=sign(2*rand(1,N)-1);
% Signal to Noise ratio
SNR1=2;
SNR2=2;
SNR3=2;
% transmitted signals.
s1=sqrt(10^(SNR1/10))*data1;
s2=sqrt(10^(SNR2/10))*data2;
s3=sqrt(10^(SNR3/10))*data3;
% Direction of Arrival (DOA) for three uncorrelated sources
theta1=(pi/180)*82;
theta2=(pi/180)*90;
theta3=(pi/180)*98;
% array response vector
i=1:M;
A1=exp(-1j*2*pi*d*(i-1)*cos(theta1));
A2=exp(-1j*2*pi*d*(i-1)*cos(theta2));
A3=exp(-1j*2*pi*d*(i-1)*cos(theta3));
% the observation vectors from the two subarrays
Z=eye(8);
J0=Z(1:7,:);
J1=Z(2:8,:);
L=[J0 ;J1];
u1=L*A1'*s1+L*A2'*s2+L*A3'*s3;
% add noise to the observation vector
n1=sqrt(.5)*randn(size(u1))+1j*sqrt(.5)*randn(size(u1));
X1=n1+u1; % the observation data
% Estimation of the cross spectral matrix.
Rxx=zeros(2*(M-1),2*(M-1));
for k=1:200;
Rxx=Rxx+X1(:,k)*X1(:,k)';
end;
Rxx=Rxx/200;
% Total Least Square Method.
% eigen decompostion
[V D]=eig(Rxx);
%form signal space
Es=V(:,[8:10]);
E=Es;
E0=E(1:5,1:3);
E1=E(6:10,1:3);
E2=[E0';E1']*[E0 E1];
%eigen decomposition for E2
[V1 D1]=eig(E2);
E12=V1(1:3,3:5);
E22=V1(3:5,3:5);
% eigen decomposition
H=-E12*inv(E22);
[V2 D2]=eig(H);
%Estimation of the Direction of Arrival (DOA) for incident sources.
% z=angle(D3);
z=angle(D); % Changed by Me due to error
Y=sort(diag(z));
angle_estim1=acos(Y(3,1)/pi)/pi*180;
angle_estim2=acos(Y(2,1)/pi)/pi*180;
angle_estim3=acos(Y(1,1)/pi)/pi*180;
thetaest1=[thetaest1 angle_estim1]; % This Gives Error because of thetaest1
thetaes2=[thetaest2 angle_estim2];
thetaest3=[thetaest3 angle_estim3];
end ;
thetaest=[thetaest1 thetaest2 theatest3];
span=[1:.1:130];
% Figure 3.4
% histogram plot
hist(thetaest,span);
ylabel('histogram');
xlabel('DOA(angle)');

답변 (1개)

DGM
DGM 2021년 5월 27일
It's just a typo
thetaest3
instead of
theatest3
  댓글 수: 2
Sadiq Akbar
Sadiq Akbar 2021년 5월 27일
Thank you very much for your help. Now it displays only a single vertical line. The angles defined at the start are 82, 90 and 98 but it displays only 90 degrees. Why?
DGM
DGM 2021년 5월 28일
I don't see the problem at a glance. I'm not familiar with the thing you're trying to calculate. Perhaps it would help to try to develop a simplified version of the code to try testing a minimal set of inputs. That might make it easier to find where it's going wrong. Sorry I can't be of more direct help here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by