delay and sum beamforming

28 views (last 30 days)
Dhananjay Singh
Dhananjay Singh on 18 Mar 2019
Commented: Sazid Hasan on 1 Jun 2021
I am making a program to acheive delay and sum beamforming,
I looked for examples of this online and found one relatable. The code is given below. When i run the program i get this error
%% Examples on delay-and-sum response for different arrays and input signals
%% 1D-array case
% Create vectors of x- and y-coordinates of microphone positions
xPos = -0.8:0.2:0.8; % 1xP vector of x-positions [m]
yPos = zeros(1, numel(xPos)); % 1xP vector of y-positions [m]
zPos = zeros(1, numel(xPos));
elementWeights = ones(1, numel(xPos))/numel(xPos); % 1xP vector of weightings
% Define arriving angles and frequency of input signals
thetaArrivalAngles = [-30 10]; % degrees
phiArrivalAngles = [0 0]; % degrees
f = 800; % [Hz]
c = 340; % [m/s]
fs = 44.1e3; % [Hz]
% Define array scanning angles (1D, so phi = 0)
thetaScanAngles = -90:0.1:90; % degrees
phiScanAngles = 0; % degrees
% Create input signal
inputSignal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles);
% Create steering vector/matrix
e = steeringVector(xPos, yPos, zPos, f, c, thetaScanAngles, phiScanAngles);
% Create cross spectral matrix
R = crossSpectralMatrix(inputSignal);
% Calculate delay-and-sum steered response
S = steeredResponseDelayAndSum(R, e, elementWeights);
%Normalise spectrum
spectrumNormalized = abs(S)/max(abs(S));
%Convert to decibel
spectrumLog = 10*log10(spectrumNormalized);
%Plot array
fig1 = figure;
fig1.Color = 'w';
ax = axes('Parent', fig1);
scatter(ax, xPos, yPos, 20, 'filled')
axis(ax, 'square')
ax.XLim = [-1 1];
ax.YLim = [-1 1];
grid(ax, 'on')
title(ax, 'Microphone positions')
%Plot steered response with indicator lines
fig2 = figure;
fig2.Color = 'w';
ax = axes('Parent', fig2);
plot(ax, thetaScanAngles, spectrumLog)
grid(ax, 'on')
ax.XLim = [thetaScanAngles(1) thetaScanAngles(end)];
for j=1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,'LineWidth', 1, 'Color', 'r', 'LineStyle', '--');
end
xlabel(ax, '\theta')
ylabel(ax, 'dB')
  3 Comments
Dhananjay Singh
Dhananjay Singh on 18 Mar 2019
function signalTotal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles, amplitudes, nSamples, coherence)
%createSignal - create input signal to an array of microphones
%
%Creates the input signal to an array of microphones based on the position
%in space of the microphones and the arrival angle and amplitude of the individual sources
%signalTotal = createSignal(xPos, yPos, zPos, f, c, fs, thetaArrivalAngles, phiArrivalAngles, amplitudes, nSamples, coherence)
%IN
%xPos - 1xP vector of x-positions [m]
%yPos - 1xP vector of y-positions [m]
%zPos - 1xP vector of z-positions [m]
%f - Wave frequency [Hz]
%c - Speed of sound in [m/s]
%fs - Sampling frequency in [Hz]
%thetaArrivalAngles - 1xM vector of theta arrival angles for sources
%phiArrivalAngles - 1xM vector of phi arrival angles for sources
%amplitudes - 1xM vector of amplitudes of sources
%nSamples - Number of samples to be used in the calculations
%coherence - Boolean to make input signals coherent or not
%
%OUT
%signalTotal - PxN matrix of input signal to individual sensors
if ~exist('coherence', 'var')
coherence = false;
rng('default')
end
if ~exist('nSamples', 'var')
nSamples = 1e3;
end
if ~exist('amplitudes', 'var')
amplitudes = zeros(1,numel(xPos));
end
if ~isvector(xPos)
error('X-positions of array elements must be a 1xP vector where P is number of elements')
end
if ~isvector(yPos)
error('Y-positions of array elements must be a 1xP vector where P is number of elements')
end
if ~isvector(zPos)
error('Z-positions of array elements must be a 1xP vector where P is number of elements')
end
T = nSamples/fs;
t = 0:1/fs:T-1/fs;
signalTotal = 0;
for k = 1:numel(thetaArrivalAngles)
%Create signal hitting the array
doa = squeeze(steeringVector(xPos, yPos, zPos, f, c, thetaArrivalAngles(k), phiArrivalAngles(k)));
%Add random phase to make signals incoherent
if coherence
signal = 10^(amplitudes(k)/20)*doa*exp(1j*2*pi*f*t);
else
signal = 10^(amplitudes(k)/20)*doa*exp(1j*2*pi*(f*t+randn(1, nSamples)));
end
%Total signal equals sum of individual signals
signalTotal = signalTotal + signal;
end
Sazid Hasan
Sazid Hasan on 1 Jun 2021
Is that problem solved?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!