Info

This question is closed. Reopen it to edit or answer.

index exceeding matrix dimension..line 102..

2 views (last 30 days)
arpana mishra
arpana mishra on 15 Feb 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
clc;
clear all;
close all;
THRESHOLD=0.7;
Fs = 10000;
fprintf('say a sentence immediately after hitting enter: ');
input('');
y= wavrecord(1 * 10000, 10000, 'double'); % Record and store the uttered speech
t=(0:(1*10000)-1)*1/(1*10000);
subplot(5,1,1);
plot(y);
r=fft(y);
d=abs(r);
subplot(5,1,2);
plot(d);
z=floor(Fs/100);
w=floor(Fs/5);%according to formula, 1600 sample needed for 8 khz
%----------
%calculation of mean and std
h=[];
for i=1:w
h=[h y(i)];
end
meanVal=mean(h);
sDev=std(h);
%----------
%identify voiced or not for each value
for i=1:length(y)
if(abs(y(i)-meanVal)/sDev > THRESHOLD)
voiced(i)=1;
else
voiced(i)=0;
end
end
% identify voiced or not for each frame
%discard insufficient samples of last frame
usefulSamples=length(y)-mod(length(y),z);
frameCount=usefulSamples/z;
voicedFrameCount=0;
for i=1:frameCount
cVoiced=0;
cUnVoiced=0;
for j=i*z-z+1:1:(i*z)
if(voiced(j)==1)
cVoiced=(cVoiced+1);
else
cUnVoiced=cUnVoiced+1;
end
end
%mark frame for voiced/unvoiced
if(cVoiced>cUnVoiced)
voicedFrameCount=voicedFrameCount+1;
voicedUnvoiced(i)=1;
else
voicedUnvoiced(i)=0;
end
end
k=[];
%-----
for i=1:frameCount
if(voicedUnvoiced(i)==1)
for j=i*z-z+1:1:(i*z)
k= [k y(j)];
end
end
end
%---display plot and play both sounds
subplot(5,1,3);
plot(k);
g=fft(k);
a=hamming(4000);% Hamming window to smooth the speech signal
b= [a ;zeros(6000,1)];
f = (1:10000);
mel(f) = 2595 * log(1 + f / 700); % Linear to Mel frequency scale conversion
tri = triang(100);
win1 = [tri ; zeros(9900,1)]; % Defining overlapping triangular windows for
win2 = [zeros(50,1) ; tri ; zeros(9850,1)]; % frequency domain analysis
win3 = [zeros(100,1) ; tri ; zeros(9800,1)];
win4 = [zeros(150,1) ; tri ; zeros(9750,1)];
win5 = [zeros(200,1) ; tri ; zeros(9700,1)];
win6 = [zeros(250,1) ; tri ; zeros(9650,1)];
win7 = [zeros(300,1) ; tri ; zeros(9600,1)];
win8 = [zeros(350,1) ; tri ; zeros(9550,1)];
win9 = [zeros(400,1) ; tri ; zeros(9500,1)];
win10 = [zeros(450,1) ; tri ; zeros(9450,1)];
win11 = [zeros(500,1) ; tri ; zeros(9400,1)];
win12 = [zeros(550,1) ; tri ; zeros(9350,1)];
win13 = [zeros(600,1) ; tri ; zeros(9300,1)];
win14 = [zeros(650,1) ; tri ; zeros(9250,1)];
win15 = [zeros(700,1) ; tri ; zeros(9200,1)];
win16 = [zeros(750,1) ; tri ; zeros(9150,1)];
win17 = [zeros(800,1) ; tri ; zeros(9100,1)];
win18 = [zeros(850,1) ; tri ; zeros(9050,1)];
win19 = [zeros(900,1) ; tri ; zeros(9000,1)];
win20 = [zeros(950,1) ; tri ; zeros(8950,1)];
nx = abs(g(floor(mel(f)))); % Mel warping
nx = nx / max(nx);
nx1 = nx * win1;
nx2 = nx * win2;
nx3 = nx * win3;
nx4 = nx * win4;
nx5 = nx * win5;
nx6 = nx * win6;
nx7 = nx * win7;
nx8 = nx * win8;
nx9 = nx * win9;
nx10 = nx * win10;
nx11 = nx * win11;
nx12 = nx *win12;
nx13 = nx * win13;
nx14 = nx * win14;
nx15 = nx * win15;
nx16 = nx * win16;
nx17 = nx * win17;
nx18 = nx * win18;
nx19 = nx * win19;
nx20 = nx * win20;
sx1 = sum(nx1 ^ 2); % Determine the energy of the signal within each window
sx2 = sum(nx2 ^ 2); % by summing square of the magnitude of the spectrum
sx3 = sum(nx3 ^ 2);
sx4 = sum(nx4 ^ 2);
sx5 = sum(nx5 ^ 2);
sx6 = sum(nx6 ^ 2);
sx7 =sum(nx7 ^ 2);
sx8 = sum(nx8 ^ 2);
sx9 = sum(nx9 ^ 2);
sx10 = sum(nx10 ^ 2);
sx11 = sum(nx11 ^ 2);
sx12 = sum(nx12 ^ 2);
sx13 = sum(nx13 ^ 2);
sx14 = sum(nx14 ^ 2);
sx15 = sum(nx15 ^ 2);
sx16 = sum(nx16 ^ 2);
sx17 = sum(nx17 ^ 2);
sx18 = sum(nx18 ^ 2);
sx19 = sum(nx19 ^ 2);
sx20 = sum(nx20 ^ 2);
sx = [sx1, sx2, sx3, sx4, sx5, sx6, sx7, sx8, sx9, sx10, sx11, sx12, sx13, sx14,
sx15, sx16, sx17, sx18, sx19, sx20];
bx = log(sx);
dx = dct(bx);
subplot(5,1,4);
plot(dx);
  2 Comments
Jan
Jan on 15 Feb 2012
How can we recognize the line 102?
Using sx1, sx2, ... is a bad programming practice. Better use sx{1}, sx{2}, ...

Answers (1)

Andreas Goser
Andreas Goser on 15 Feb 2012
  1. Go to line 101 and set a breakpoint
  2. Run the code
  3. It will stop at line 101. Look at all variables needed in line 102 and see whether you can see where you try to access data outside the used matrix size
  4. If you still need help, condense the data and the line to a reasonable size and the community will help you.

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!