How will i solve this problem? "Index exceeds matrix dimensions". i am not sure which line corresponds to the error can anyone help me?

1 view (last 30 days)
I am trying to execute this part of the program to calculate H
Under this condition,
if nfft21 ~= length(Y)
error('Error: input spectrum length is wrong');
end
f0Bins = (ceil(f0range(1)*nfft/fs+1) : floor(f0range(2)*nfft/fs+1));
forange is the pitch freq of the signal , dimension is (nfft/2+1) x 1 for my signal forange[100 300]
Y is the stft of a noisy signal
Q is the number of harmonic bands chosen 12
nfft i have chosen to be 512
nfft21= (nfft/(2+1))
ff = (0:nfft-1)*fs/nfft;
fband = floor((f0bin-1)/2);
H = zeros(nfft21,1);
A = zeros(Q,1);
aq2bq = zeros(Q,2*fband+1);
for q = 1:Q
aq2bq(q,:) = q*(f0bin-1)+1-fband : q*(f0bin-1)+1+fband;
numerator = sum( Y(aq2bq(q,:)).'.*conj(E(aq2bq(q,:))) );
denominator = sum( abs(E(aq2bq(q,:))).^2 );
A(q) = numerator/denominator;
H(aq2bq(q,:)) = A(q)*ones(2*fband+1,1);
end
i am not sure which line corresponds to the error can anyone help me? Thanks in advance

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Oct 2014
Santhiya - which line of code does the error correspond to? The error message is telling you that you are trying to access an element in a matrix using an index that exceeds the dimensions of the matrix. To solve this, type the following before executing your code
dbstop if error
Now, run your code and when the error occurs, the debugger will pause at the line with the error which you can then inspect the inputs.
As David has asked, what are are Y and E? Note how you access data within these two arrays using the data from aq2bq - so the data from this array is used as indices into the other two.
It seems reasonable to guess that this might be the cause of the problem: if Y is a 100x1 vector and you are trying to access element 234 (because f0bin has been chosen to produce a value such as this) then Y(234) will generate the error.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!