MATLAB: How to plot array beampattern with Frost beamformer weights

beampatternfrost beamformerpatternPhased Array System Toolboxphased array toolbox

I am trying to plot beampattern of an array after using Frost Beamforming algorithm to adapt weights. Below is sample code for frost beamformer.
clear; close all; clc;
h = phased.URA('Size',[4 4],'ElementSpacing',[1 0.6]);
h.Element.FrequencyRange = [20 20000];
fs = 8e3;
t = 0:1/fs:0.3;
x = chirp(t,0,1,500);
c = 340;
collector = phased.WidebandCollector('Sensor',h,...
'PropagationSpeed',c,'SampleRate',fs,...
'ModulatedInput',false,'NumSubbands',8192);
incidentAngle = [-50;30];
x = step(collector,x.',incidentAngle);
noise = 0.2*randn(size(x));
rx = x + noise;
beamformer = phased.FrostBeamformer('SensorArray',h,...
'PropagationSpeed',c,'SampleRate',fs,...
'Direction',incidentAngle,'FilterLength',5,...
'WeightsOutputPort',true);
[y,yweights] = step(beamformer,rx);
plot(t,rx(:,6),'r:',t,y)
xlabel('Time')
ylabel('Amplitude')
legend('Original','Beamformed')
How do I use pattern and yweights to plot the beampattern?

Best Answer

You can consider translating the weights to frequency domain to obtain the appropriate frequency response. Then you can compute the pattern at the given frequency.
% plot pattern
% consider 16 bands and pick the band corresponding to 2 kHz
M = 16;
wfreq = fft(reshape(yweights,16,[]).',M);
freqvec = [0:7 -8:-1]*fs/M;
bandidx = 5; % corresponding to 2kHz
freqbin = 2e3;
hstv = phased.SteeringVector('SensorArray',h,'PropagationSpeed',c);
sv = step(hstv,freqbin,incidentAngle);
figure
pattern(h,freqbin,-180:180,0,'PropagationSpeed',c,'Weights',sv.*wfreq(bandidx,:).',...
'CoordinateSystem','polar','Type','powerdb');
HTH