clear;clc
%%
fc = 3e8;% Carrier frequency
Nb = 1000;% Number of snapshots
c = 3e8;
wavelength = c/fc;% The wavelength of the received signal
d = 0.5*wavelength;
theta = [5 40];
M = length(theta);% Number of signals
N = 10;% Number of antennas
% Wavenumber
beta = 2*pi/wavelength;
% Signal amplitude
A = 1;
% SNR (dB)
snr = 5;
% Variance of noise
sigma=sqrt((A^2)/(2*10^(snr/10)));
% Source signal
D = randi(M,Nb,1);
S =A*(2*D - 1);
% The electrical phase shift from element to element along the array
phi=beta*d*cos(theta*pi/180);
% Matrix of steering vectors
for i=1:M
for k=1:N;
VecteurDirectionnel(k,i)= exp(j*(k-1)*phi(i));
end
end
% White Gaussien noise
B = (sigma^2)*(randn(N,Nb)+j*randn(N,Nb))/sqrt(2);
% Array output:signal plus noise
X = VecteurDirectionnel*S+B;
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
% Estimation of the spatial correlation matrix of the observed signal
Rxx = X*X'/Nb;
% Eigen decomposition
[Vi,Li] = eig(Rxx);
[L,I] = sort(diag(Li),'descend');
V = Vi(:,I);
Vs = V(:,1:M);
Vs1=Vs(1:N-1,:);
Vs2=Vs(2:N,:);
% Direction Of Arrival
% Least square
xsi=linsolve(Vs(1:N-1,:),Vs(2:N,:));
% DOA estimation
doa=acosd((angle(eig(xsi))/(2*pi*d)))

 채택된 답변

Matt J
Matt J 2024년 4월 16일
편집: Matt J 2024년 4월 16일

0 개 추천

As you can see, VecteurDirectionnel and S are the wrong sizes for matrix multiplication,
whos VecteurDirectionnel S
Name Size Bytes Class Attributes S 1000x1 8000 double VecteurDirectionnel 10x2 320 double complex
% Array output:signal plus noise
X = VecteurDirectionnel*S+B;
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.

댓글 수: 6

Sadiq Akbar
Sadiq Akbar 2024년 4월 16일
Thanks a lot for your kind response. Yes, but how will we correct it?
Stephen23
Stephen23 2024년 4월 16일
"but how will we correct it?"
We cannot guess what you expect the output of "multiplying" a 1000x1 matrix with a 10x2 matrix to be.
Please tell us the exact size you expect the result of that operation to be.
Matt J
Matt J 2024년 4월 16일
@Sadiq Akbar In addition to what Stephen said, you should know what sizes you expect VecteurDirectionnel and S themselves to be. You should be able to tell us what is wrong.
Sadiq Akbar
Sadiq Akbar 2024년 4월 19일
Thanks to both of you for your kind responses. Actualy the sizes of the matrices VecteurDirectionnel and S should be 10 x 2 and 2 x 1000 respectively. But I don't know how to make size of S as 2 x 1000?
Well S is Nb x 1 because D is Nb x 1, from this line,
D = randi(M,Nb,1);
Perhaps you meant to have,
D = randi([low, hi] , [M,Nb]);
but we have no way of knowing what you intended the low and hi limits to be.
Sadiq Akbar
Sadiq Akbar 2024년 4월 22일
Thanks a lot for your help. Yes, you are right. It works now.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Beamforming and Direction of Arrival Estimation에 대해 자세히 알아보기

태그

질문:

2024년 4월 16일

댓글:

2024년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by