delay and sum beamforming

조회 수: 2 (최근 30일)
Dhananjay Singh
Dhananjay Singh 2019년 3월 18일
답변: prabhat kumar sharma 2025년 1월 16일
Hi, i am running a program for dealy and sum beamforming. When i run the program i get this error
"Error using line
Vectors must be the same length.
Error in examplesSteeredResponse (line 64)
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], ax.YLim,'LineWidth', 1, 'Color', 'r', 'LineStyle', '--');"
Here's some part of the code i am running:
%% 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')
  댓글 수: 1
Naman Bhaia
Naman Bhaia 2019년 3월 21일
Hello Dhananjay,
I think this question was posted twice by mistake. There are people from the community answering on the other question so please redirect there to follow that thread.

댓글을 달려면 로그인하십시오.

답변 (1개)

prabhat kumar sharma
prabhat kumar sharma 2025년 1월 16일
Hello Dhananjay,
The error you're encountering is due to a mismatch in the lengths of the vectors used in the line function within your plotting code. Specifically, the line function expects the X and Y data to be of the same length, but you're providing a single X value (thetaScanAngles(indx)) and a range for Y (ax.YLim), which causes the error.
To fix this, you should specify both X and Y as pairs of points that define the start and end of the line. Here's I'm providing a reference code snippet for modifying the line plotting section. You can adjust this code according to your specific needs.
% 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)];
% Add indicator lines for each arrival angle
for j = 1:numel(thetaArrivalAngles)
indx = find(thetaScanAngles >= thetaArrivalAngles(j), 1);
% Ensure indx is valid
if ~isempty(indx)
% Draw vertical line at arrival angle
line(ax, [thetaScanAngles(indx) thetaScanAngles(indx)], [min(spectrumLog), max(spectrumLog)], ...
'LineWidth', 1, 'Color', 'r', 'LineStyle', '--');
end
end
xlabel(ax, '\theta')
ylabel(ax, 'dB')
I hope it helps!

카테고리

Help CenterFile Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by