Error "undefined function or variable 'y1' ". Help me please. :\

1 次查看(过去 30 天)
if true
% code
end--------------------------------start of the code
clc;
clear all;
Fs=8000;
for k=1:30
clear y1 y2 y3;
display('record voice');
pause();
x=wavrecord(Fs,Fs);
t=0.04;
j=1;
for i=1:8000
if(abs(x(i))>t)
y1(j)=x(i);
j=j+1;
end
end
y2=y1/(max(abs(y1)));
y3=[y2,zeros(1,3120-length(y2))];
y=filter([1 -0.9],1,y3');%high pass filter to boost the high frequency components
%%frame blocking
blocklen=240;%30ms block
overlap=80;
block(1,:)=y(1:240);
for i=1:18
block(i+1,:)=y(i*160:(i*160+blocklen-1));
end
w=hamming(blocklen);
for i=1:19
a=xcorr((block(i,:).*w'),12);%finding auto correlation from lag -12 to 12
for j=1:12
auto(j,:)=fliplr(a(j+1:j+12));%forming autocorrelation matrix from lag 0 to 11
end
z=fliplr(a(1:12));%forming a column matrix of autocorrelations for lags 1 to 12
alpha=pinv(auto)*z';
lpc(:,i)=alpha;
end
wavplay(x,Fs);
X(k,:)=reshape(lpc,1,228);
Y(k,:)=input('enter the number ');
end
save('lpcdata.mat','X','Y');
---------------------------------------the command
record voice
??? Undefined function or variable 'y1'.
Error in ==> normalizedlpc at 17
y2=y1/(max(abs(y1)));

采纳的回答

Image Analyst
Image Analyst 2014-10-18
This
j=1;
for i=1:8000
if(abs(x(i))>t)
y1(j)=x(i);
j=j+1;
end
end
can be vectorized:
y1 = zeros(1, length(x); % Initialize to all zeros.
% Compute logical indexes of where x > t
aboveThreshold = x > t;
if sum(aboveThreshold) > 1
% At least one element of x is above the threshold.
% Extract only those above threshold and create a new y1
% which may be a different length than the initialized one.
y1 = x(aboveThreshold);
end
but you still might want to find out why no x is above your t threshold, because though my code fixed your code, it will just continue on with a y of all zeros, which is probably useless and not what you want.
  7 个评论
Poison
Poison 2014-10-28
Thank you for the explanation. Meant alot and 1 more question.
Why is my .mat(microsoft access table) files is only a shortcut after i run the program. Is there any way to make in permanently stay in my folder as .mat? And if there isn't, how do i save data into microsoft access table that is open-able afterward?
Thanks in advanced.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by