one error i can not solve plz solve it.

clc;
clear;
close all;
M = 16; % Number of antenna elements
L = 100; % Number of snapshots
f = 3e9; % Carrier frequency in Hz
c = 3e8; % Speed of light in m/s
lambda = c/f; % Wavelength in meters
d = lambda/2; % Element spacing in meters
k = d/lambda; % Wavenumber
thetas = [0 10]; % Angle of arrival in degrees for the first signal
thetai = [-30 30]; % Angle of arrival in degrees for the interfering signals
n = [0:M-1]';
snr = 30; % SNR in dB
inr = 10; % Interference-to-noise ratio in dB
% Uncomment one of the following lines to select the antenna array pattern
% chuang = hamming(M)';
% chuang = kaiser(M,pi)';
chuang = ones(M,1)';
vs = exp(-1j*2*pi*n*sin(thetas/180*pi)*d/lambda); % Steering vector for the desired signal
for i = 1:length(thetas)
vi = exp(-1j*2*pi*n*sin(thetai(i)/180*pi)*d/lambda); % Steering vector for the interfering signals
f_mod = 16000; % Modulation frequency in Hz
t = [0:L-1]/200;
xs = sqrt(10^(snr/10))*vs.'.*exp(1j*2*pi*f_mod*t); % Desired signal with additive noise
xi = sqrt(10^(inr/10)/2)*vi.*(randn(M,L)+1j*randn(M,L)); % Interference with additive noise
noise = (randn(M,L)+1j*randn(M,L))/sqrt(2); % Additive noise
X = xs.' + xi + noise; % Received signal with additive noise
R = X*X'/L; % Covariance matrix of the received signal
w = inv(R)*vs/(vs'*inv(R)*vs); % Optimal beamforming weight vector
w2(:,i) = w;
sita = 100*[-1:0.001:1]; % Angle of arrival for the grid search in degrees
v = exp(-1j*2*pi*k*n*sin(sita/180*pi)); % Steering vector for the grid search
B = abs(w'*v); % Beam pattern
B = 20*log10(B/max(B)); % Normalized beam pattern in dB
figure
plot(sita,B,'b');
title(['Array Pattern (M = ',num2str(M),')']);
xlabel('Angle of Arrival (degrees)');
ylabel('Normalized Power Pattern (dB)');
grid on
axis([-100 100 -70 10]);
end
% Combining the weights for the desired signal and the interfering signals
w1 = sum(w2,2);
sita = 100*[-1:0.001:1];
v = exp(-1j*2*pi*k*n*sin(sita/180*pi));
B = abs(w1'*v);
B = 20*log10(B/max(B));
figure
plot(sita,B,'b');
title(['Array Pattern (M = ',num2str(M),')']);
xlabel('Angle of Arrival (degrees)');
ylabel('Normalized Power Pattern (dB)');
grid on
axis([-100 100 -70 10]);

Answers (1)

Torsten
Torsten on 12 May 2023
Edited: Torsten on 12 May 2023
If you check the sizes of vs.' and 1j*2*pi*f_mod*t
size(vs.')
size(1j*2*pi*f_mod*t)
you will see that multiplication as
xs = sqrt(10^(snr/10))*vs.'.*exp(1j*2*pi*f_mod*t); % Desired signal with additive noise
is not possible.

Asked:

on 12 May 2023

Edited:

on 12 May 2023

Community Treasure Hunt

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

Start Hunting!