How to remove Index exceeds matrix dimensions error ?

1 回表示 (過去 30 日間)
parul
parul 2013 年 4 月 27 日
I am implimenting an algorithm for direction of arrival of signal estimation.For that i first store the angle information in a mat file n then loading it into the code.In this code s=a1,where a1 is the first signal and this variable contains the angle information i.e 30 degrees.but when i run my full code its giving me Index exceeds matrix dimensions error.Sir Please help me.
degree = 180; divisor_factor=32;
c = 346.287; K = 100; % Number of frequency snapshots Fs = 50000;% Sampling frequency T=1/Fs; f = 3000;% Signal frequency M = 8; dist = .03; xx = dist*[0:M-1];
theta_test = [1:1:degree-1]*pi/180; % Test vector of theta values (from 0 to 180 deg) length_t = length(theta_test); % Number of trial angles
load angledata s=a1; % a1-a5 correspond to data of 5 different incident angles % s is a 102400 by 8 matrix. The length of each of the 8 sequences may be longer than 102400 lfft=1024*1; % number of data points for FFT in a snapshot df = Fs/lfft/1; % frequency grid size F = 0:df:Fs/1-df; for ih=1:M for iv=1:K pos=(iv-1)*lfft+1; tmp=s(pos:pos+lfft-1,ih); %IN THIS ERROR IS SHOWGING X(:,ih,iv)=fft(tmp); end end

採用された回答

Iman Ansari
Iman Ansari 2013 年 4 月 27 日
Hi. Maybe your s isn't 102400 by 8 matrix. With s=rand(102400,8) didn't give any error:
degree = 180; divisor_factor=32;
c = 346.287; K = 100; % Number of frequency snapshots
Fs = 50000;% Sampling frequency
T=1/Fs; f = 3000;% Signal frequency
M = 8; dist = .03; xx = dist*[0:M-1];
theta_test = [1:1:degree-1]*pi/180; % Test vector of theta values (from 0 to 180 deg)
length_t = length(theta_test); % Number of trial angles
%%%%%%%load angledata
s=rand(102400,8); % a1-a5 correspond to data of 5 different incident angles
% s is a 102400 by 8 matrix. The length of each of the 8 sequences may be longer than 102400
lfft=1024*1; % number of data points for FFT in a snapshot
df = Fs/lfft/1; % frequency grid size
F = 0:df:Fs/1-df;
for ih=1:M
for iv=1:K
pos=(iv-1)*lfft+1;
tmp=s(pos:pos+lfft-1,ih); %IN THIS ERROR IS SHOWGING
X(:,ih,iv)=fft(tmp);
end
end
  2 件のコメント
parul
parul 2013 年 4 月 27 日
sir.it worked...bt for the same code i m having one more problem.when i running the code to find covariance matrix it is givein me error i.e Attempted to access theta_test(180); index out of bounds because numel(theta_test)=179.(eeror in finding phit)
% sample covariance matrix R=X0*X0';
omega = 2*pi*f0; % Angular frequency of the signal k=omega/c; % wave number phi=-k*dist*cos(theta_test); % Electrical angle for i=1:M a(i,:)=exp(j*(i-1)*phi); % Steering vector end
delta=1e-4; % epsilon--criterion to terminate the algorithm dphi=100;
for i=1:degree phit=-k*dist*cos(theta_test(i)); % electrical angle for ii=1:M v(ii,:)=exp(j*(ii-1)*phit); % array manifold matrix end P=v*inv(v'*v)*v'; % projection matrix wrt V phi10_tmp(i)=trace(P*R); end
Iman Ansari
Iman Ansari 2013 年 4 月 27 日
You can use 'for i=1:degree-1':
for i=1:degree-1
phit=-k*dist*cos(theta_test(i)); % electrical angle
for ii=1:M
v(ii,:)=exp(j*(ii-1)*phit); % array manifold matrix
end
P=v*inv(v'*v)*v'; % projection matrix wrt V
phi10_tmp(i)=trace(P*R);
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by