the code of "myfunAskMathworks.m", yo and ye both are of the order 36x1 and these are correct. But in the other 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.
myfunAskMathworks.m
u=[10 20 30 40];b=u; M=6; % Tx constant N=6; % Rx constant d = 0.5; % constant vecH = @(MAT) MAT(:).'; steerVecT = @(ang) exp(1j*2*pi*d*(0:M-1).'*sin(vecH(ang))); steerVecR = @(ang) exp(1j*2*pi*d*(0:N-1).'*sin(vecH(ang))); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Calculation of yo and ye %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% yo = yMatTR(deg2rad(u), steerVecT, steerVecR); % 36x1 in which 36 is due to M*N ye = yMatTR(deg2rad(b), steerVecT, steerVecR); % 36x1 in which 36 is due to M*N %%%%%%%%%%%%%%%%%% % MSE %%%%%%%%%%%%%%%%%% e=norm(yo-ye).^2/(M*N); %%%%%%%%%%%%%%%%%%%%%%%%%%%% % function yMatTR %%%%%%%%%%%%%%%%%%%%%%%%5%%% function y = yMatTR(targetAngle, steerVecT, steerVecR) steerA = steerVecT(targetAngle); steerB = steerVecR(targetAngle); y=sum( steerA.*permute(steerB,[3,2,1]) ,2); y=y(:); end
codeWithArrays.m
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 AT = exp(-1j*rT*k);% Always (TX Antennas x No. of sources) AR = exp(-1j*rR*k);% Always (RX Antennas x No. of sources) az=az'; el=el'; yo = yMatTR(deg2rad(az), AT, AR); % 36x1 in which 36 is due to M*N ye = yMatTR(deg2rad(el), AT, AR); %%%%%%%%%%%%%%%%%% % MSE %%%%%%%%%%%%%%%%%% e=norm(yo-ye).^2/(M*N) %%%%%%%%%%%%%%%%%%%%%%%%%%%% % function yMatTR %%%%%%%%%%%%%%%%%%%%%%%%5%%% function y = yMatTR(targetAngle, steerVecT, steerVecR) steerA = steerVecT(targetAngle); steerB = steerVecR(targetAngle); y=sum( steerA.*permute(steerB,[3,2,1]) ,2); y=y(:); end
This is how I would modified the code to execute for any M r N dimensions:
clear clc u = [10 20 30 40]; b = u * (1+0.5*randn); % random deviation between u and b % 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 = 10; % 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 % rT is size Nx3, so to make multiplication work, % [cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)] must be 3x1 AT = @(alpha, beta) exp(-1j.*rT*pi*[cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)]); % rR is size Mx3, so to make multiplication work, % [cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)] must be 3x1 AR = @(alpha, beta) exp(-1j.*rR*pi*[cos(alpha).*cos(beta); sin(alpha).*cos(beta); sin(beta)]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Calculation of yo and ye %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% yo = yMatTR(u, AT, AR); ye = yMatTR(b, AT, AR); %%%%%%%%%%%%%%%%%% % MSE %%%%%%%%%%%%%%%%%% e=norm(yo-ye).^2/(M*N); %%%%%%%%%%%%%%%%%%%%%%%%%%%% % function yMatTR %%%%%%%%%%%%%%%%%%%%%%%%5%%% function y = yMatTR(targetAngle, steerVecT, steerVecR) az = deg2rad(targetAngle(1:2)); el = deg2rad(targetAngle(3:4)); steerA = steerVecT(az,el); steerB = steerVecR(az,el); y=sum( steerA.*permute(steerB,[3,2,1]) ,2); y=y(:); end
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.