Why the 2nd code does not behave like the 1st code?
이전 댓글 표시
In the attached code of "myfunAskMathworks.m", yo and ye both are of the order 36x1 and these are correct. But in the other attached code "codeWithArrays.m", it gives error on line 35. Why is it so? In this also we should get the same order of yo and ye but it gives error.
채택된 답변
추가 답변 (1개)
It is because in the function "myfunAskMathworks.m" you have function handles defined. So, you are sending the function handle as an input parameter to the function yMatTR.
steerVecT = @(ang) exp(1j*2*pi*d*(0:M-1).'*sin(vecH(ang)));
In the line:
steerA = steerVecT(targetAngle)
you are actually calling the function handle for angles as an input to the function.
In the other file:
AT = exp(-1j*rT*k);
this is not a function, but an array (matrix) of complex numbers.
So in the line:
steerA = steerVecT(targetAngle);
you are trying to access elements of a matrix with indices that are not either integer or logical values.
Essentially, you are confusing function handles with matrices.
댓글 수: 12
Sadiq Akbar
2023년 2월 27일
Askic V
2023년 2월 28일
The main difference is that in your case you have a function of two variables (az and el). These are vectors of angles (azimuth and elevation).
In the example you provided there is only one variable (ang). So basically the task is how this to make it work for functions of two variables.
As a start, you need to define functions of two variables. For example, define two function handles:
AT = @(alpha, beta) exp(-1j.*rT*pi.*[cos(alpha).*cos(beta),sin(alpha).*cos(beta), sin(beta)].');
AR = @(alpha, beta) exp(-1j.*rR*pi.*[cos(alpha).*cos(beta), sin(alpha).*cos(beta), sin(beta)].')
I used here cos and sin instead of cosd and sind becaue later you use deg2rad function in your code.
If that is what you want, the next setp would be to pack two angles (or two arrays of angles) as an input parameter to the function yMatTR. The function would look something like this:
function y = yMatTR(targetAngle, steerVecT, steerVecR)
% az = targetAngle(1,:) - first row is az
% el = targetAngle(2,:) - second row is el
steerA = steerVecT(targetAngle(1,:), targetAngle(2,:));
steerB = steerVecR(targetAngle(1,:), targetAngle(2,:));
y=sum( steerA.*permute(steerB,[3,2,1]) ,2);
y=y(:);
end
So the function call would look like something like this:
yo = yMatTR([deg2rad(az);deg2rad(el)], AT, AR); % pack two angles in a single input param.
I think you now have all necessary inputs to make this work.
Sadiq Akbar
2023년 2월 28일
Askic V
2023년 3월 1일
Please examine this code, whether it is what you want:
clear
clc
close all; clear all; clc;
u=[10 20 30 40];b=u;
az = u(1:2)'; %Azimuths
el = u(3:4)'; % Elevations
M = length(az); % No. of sources
L = 1;
m = randn(M,L);
% Wavenumber vectors
%k = pi*[cosd(az).*cosd(el), sind(az).*cosd(el), sind(el)].';% Always 3 x No. of sources
% Tx antennas
N = 6;
% Array geometry [rx,ry,rz] (example: uniform circular array)
radius = 0.5/sind(180/N);
rx = radius*cosd(360*(0:N-1).'/N);
ry = radius*sind(360*(0:N-1).'/N);
rT = [rx, ry, zeros(N,1)];% Always No. of Antennas x 3
% Rx antennas
M=6;
% Array geometry [rx,ry,rz] (example: uniform circular array)
radius = 0.5/sind(180/M);
rx = radius*cosd(360*(0:M-1).'/M);
ry = radius*sind(360*(0:M-1).'/M);
rR = [rx, ry, zeros(M,1)];% Always No. of Antennas x 3
% Matrices AT and AR
% Always (TX Antennas x No. of sources)
AT = @(alpha, beta) exp(-1j.*rT*pi.*[cos(alpha).*cos(beta),sin(alpha).*cos(beta), sin(beta)].');
AR = @(alpha, beta) exp(-1j.*rR*pi.*[cos(alpha).*cos(beta), sin(alpha).*cos(beta), sin(beta)].');% Always (RX Antennas x No. of sources)
az=az';
el=el';
yo = yMatTR([deg2rad(az);deg2rad(el)], AT, AR); % 36x1 in which 36 is due to M*N
ye = yMatTR([deg2rad(az);deg2rad(el)], AT, AR);
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
e=norm(yo-ye).^2/(M*N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function yMatTR
%%%%%%%%%%%%%%%%%%%%%%%%5%%%
function y = yMatTR(targetAngle, steerVecT, steerVecR)
% az = targetAngle(1,:); el = targetAngle(2,:)
steerA = steerVecT(targetAngle(1,:), targetAngle(2,:));
steerB = steerVecR(targetAngle(1,:), targetAngle(2,:));
y=sum( steerA.*permute(steerB,[3,2,1]) ,2);
y=y(:);
end
Sadiq Akbar
2023년 3월 1일
Askic V
2023년 3월 1일
Yes, in the function "myfunAskMathworks.m" the vector b is used in a function call in the line:
ye = yMatTR([deg2rad(az);deg2rad(el)], AT, AR);
so I suggest to define vector b to be a little different than u, for example
b = u * (1+0.5*randn); % random number with mean 1 and deviation 0.5
an then extract az and el variables from b in the same way you extracted from vector u, and then call ye = yMatTR([deg2rad(b(1:2...
I'm sure you can figure it out on you own. A little bit effort is needed.
Sadiq Akbar
2023년 3월 2일
Askic V
2023년 3월 2일
The reason of the mismatch in the dimension originates from this line in you start file:
k = pi*[cosd(az).*cosd(el), sind(az).*cosd(el), sind(el)].';% Always 3 x No. of sources
sine you have two angles for az and two for el, this line will always produce a vector of 6 elements.
Remember, in your original template file there is a line:
steerVecT = @(ang) exp(1j*2*pi*d*(0:M-1).'*sin(vecH(ang)));
this is a fiunction handle, that was later called with complete vector u, which means for all angles. What you did was to extract az and el and use then separately. You need to rethink what you really trying to achive.
Also, in your code there are lines with questionable purpose.
For example, what is this line needed?
m = randn(M,L);
Sadiq Akbar
2023년 3월 2일
Askic V
2023년 3월 2일
@Sadiq Akbar here you need to know what function exactly you want to apply to the angles.
Here is the problem:
[cos(alpha).*cos(beta),sin(alpha).*cos(beta), sin(beta)]
In your example function you had only sin() applied to all angles. In in this particular case you apply three functions and make a new vector which dimension doesn't correspond to -1j.*rR*pi part.
You need to review these functions. How you get them? Are you sure they are correct one?
Why az and el contain two values each?
Sadiq Akbar
2023년 3월 2일
Sadiq Akbar
2023년 3월 3일
카테고리
도움말 센터 및 File Exchange에서 Transmitters and Receivers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!