%% 2D Conceptual + Electronically Steered Beamforming
clc; clear; close all;
%% PARAMETERS
Fs = 1000; % Sampling frequency [Hz]
T = 1/Fs; % Sampling period
t = 0:T:1-T; % 1-second time vector
f_sig = 50; % Signal frequency [Hz]
%% SIMULATE ANTENNA SIGNALS
p = sin(2*pi*f_sig*t); % Reference signal (antenna p)
vx = 0.8*sin(2*pi*f_sig*t + pi/6); % vx antenna
vy = 0.6*sin(2*pi*f_sig*t + pi/4); % vy antenna
%% NORMALIZE SIGNALS
pnor = p / max(abs(p));
vxnor = vx / max(abs(vx));
vynor = vy / max(abs(vy));
%% PASSIVE ROTATION (Conceptual Beamforming)
I1 = real(fft(pnor) .* conj(fft(vxnor)));
I2 = real(fft(pnor) .* conj(fft(vynor)));
theta = 360 * atan(sum(I2)/sum(I1)) / (2*pi); % degrees
vc = vxnor * cosd(theta) + vynor * sind(theta);
resultant_passive = pnor + 2*vc;
%% ELECTRONICALLY STEERED BEAM
theta_steer = 60; % Desired steering angle in degrees
lambda = 1; % Normalized wavelength
d = 0.5*lambda; % Antenna spacing
% Phase shifts for each antenna
phi_vx = -2*pi*d/lambda * cosd(theta_steer);
phi_vy = -2*pi*d/lambda * cosd(theta_steer);
% Apply phase shifts (complex representation)
vx_steered = vxnor .* cos(phi_vx) - vxnor .* sin(phi_vx)*1j;
vy_steered = vynor .* cos(phi_vy) - vynor .* sin(phi_vy)*1j;
% Coherent sum and take real part for visualization
resultant_steered = real(pnor + vx_steered + vy_steered);
%% PLOT VECTORS IN 2D
figure('Color','w'); hold on; grid on; axis equal;
xlabel('vx'); ylabel('vy'); title('2D Beamforming: Passive vs Electronic Steering');
sample_idx = 200; % Sample to illustrate
% Original antenna vectors
quiver(0,0,vxnor(sample_idx),0,0,'r','LineWidth',2,'MaxHeadSize',0.5); % vx
quiver(0,0,0,vynor(sample_idx),0,'b','LineWidth',2,'MaxHeadSize',0.5); % vy
quiver(0,0,pnor(sample_idx)*cosd(45), pnor(sample_idx)*sind(45),0,'k','LineWidth',2,'MaxHeadSize',0.5); % reference
% Passive rotated vector
quiver(0,0,vc(sample_idx)*cosd(theta), vc(sample_idx)*sind(theta),0,'m','LineWidth',2,'MaxHeadSize',0.5);
%% ELECTRONICALLY STEERED BEAM (corrected)
theta_steer = 120; % Desired steering angle in degrees
lambda = 1; % Normalized wavelength
d = 0.5*lambda; % Antenna spacing
% Complex phase shifts for each antenna element (assuming linear array along x)
phi_vx = -2*pi*d/lambda * cosd(theta_steer);
phi_vy = -2*pi*d/lambda * cosd(theta_steer);
% Antenna phasors at the sample index (using normalized amplitudes and zero phase for simplicity)
vx_phasor = vxnor(sample_idx) * exp(1j*phi_vx);
vy_phasor = vynor(sample_idx) * exp(1j*phi_vy);
p_phasor = pnor(sample_idx); % reference antenna assumed at phase 0
% Sum phasors coherently
resultant_phasor = p_phasor + vx_phasor + vy_phasor;
% Plot the electronically steered beam as a 2D vector (real vs imag parts)
quiver(0, 0, real(resultant_phasor), imag(resultant_phasor), 0, ...
'g', 'LineWidth', 2, 'MaxHeadSize', 0.5);
% Annotate
legend('vx','vy','Reference p','Passive Rotation vc','Electronic Steering','Location','best');
% Show theta arcs
theta_rad_passive = deg2rad(theta);
r_arc = 0.4;
arc_x = r_arc*cos(linspace(0,theta_rad_passive,50));
arc_y = r_arc*sin(linspace(0,theta_rad_passive,50));
plot(arc_x, arc_y, 'm--','LineWidth',1.5);
text(0.15,0.05,['\theta_{passive} = ',num2str(theta,'%.2f'),'°'],'FontSize',12,'Color','m');
theta_rad_steer = deg2rad(theta_steer);
arc_x2 = r_arc*cos(linspace(0,theta_rad_steer,50));
arc_y2 = r_arc*sin(linspace(0,theta_rad_steer,50));
plot(arc_x2, arc_y2, 'g--','LineWidth',1.5);
text(0.15,0.1,['\theta_{steer} = ',num2str(theta_steer,'%.2f'),'°'],'FontSize',12,'Color','g');
xlim([-1 1]); ylim([-1 1]);
grid on;
Simulate sinusoidal signals received by three antennas with phase offsets:
Compute the cross-spectrum terms between the reference and antenna signals in frequency domain:
Estimate the beam rotation angle \( \theta \) from the sum of the cross-spectrum components:
Rotate antenna components using the estimated angle and combine signals for conceptual beamforming:
This workflow uses frequency-domain cross-spectra to estimate relative phases and direction, then applies rotation to combine signals coherently — the essence of beamforming.