Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

car control using speech recognition

Status
Not open for further replies.

prajesh

Newbie level 1
Joined
Jan 21, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
rajkot
Activity points
1,334
hi, i am working on car control using speech recognition but i have problem with extract at 214 line.
please help me to solve this problem.
here is my code.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



function test_project
clc;
close all;
clear all;
a=0;
data1=[0 0 0 0];data2=[0 0 0 0];data3=[0 0 0 0];data4=[0 0 0 0];data=[0 0 0 0];val1=[0 0 0 0];
for i=1:100
for i=1:10
fs=22050;
y1=wavrecord(fs,fs,1);
wavwrite(y1,fs,16,'C:\MATLAB7\work\user.wav');
a=wavread('C:\MATLAB7\work\user.wav');
wavplay(a,fs);
n=input('Enter 0');
if(n==0)
break;
else
disp('Record your voice again');
end
end
filename = 'C:\MATLAB7\work\New Folder11L.wav' % Calculate the codebook vector.

cep = learn('C:\MATLAB7\work\New Folder11L.wav');
codebook = vqlbg(cep, 8);
result(1) = identify(filename, codebook);

cep = learn('O.wav');
codebook = vqlbg(cep, 8);
result(2) = identify(filename, codebook);

cep = learn('U.wav');
codebook = vqlbg(cep, 8);
result(3) = identify(filename, codebook);

cep = learn('V.wav');
codebook = vqlbg(cep, 8);
result(4) = identify(filename, codebook);

% Test a file.
if ( ( result(1) < result(2) ) & ( result(1) < result(3) ) & ( result(1) < result(4) ) )
'L'
end
if ( ( result(2) < result(1) ) & ( result(2) < result(3) ) & ( result(2) < result(4) ) )
'O'
end
if ( ( result(3) < result(2) ) & ( result(3) < result(1) ) & ( result(3) < result(4) ) )
'U'
end
if ( ( result(4) < result(2) ) & ( result(4) < result(1) ) & ( result(4) < result(3) ) )
'V'
end

% For Checking the Output and Data given to the parallel port
Select=input('Enter 0 for TRUE Output ');
if(Select==0)
if(ans=='L')
data=[~val1:),1) val1:),2) val1:),3) val1:),4)];
end
if(ans=='O')
data=[val1:),1) ~val1:),2) val1:),3) val1:),4)];
end
if(ans=='U')
data=[val1:),1) val1:),2) ~val1:),3) val1:),4)];
end
if(ans=='V')
data=[val1:),1) val1:),2) val1:),3) ~val1:),4)];
end
dio = digitalio('parallel','TPI1');
addline(dio,0:3,'out');
putvalue(dio.Line(1:4),data);
val1 = getvalue(dio)
end
Close=input('Enter 5 for Exit');
if(Close==5)
break;
end
end
% ---------- MARS MARS MARS MARS MARS ----------













%%%%% IDENTIFYING THE FILE %%%%%
function dist = identify(file, codebook)
[filedata, fs] = wavread('C:\MATLAB7\work\New Folder\user.wav');
truncated = extract(filedata);
cep = mfcc(truncated);
d = disteu(cep', codebook);
dist = sum(min(d,[],2)) / size(d,1);

% ---------- MARS MARS MARS MARS MARS ----------

%%%%% LINDO,BUZO,GOLD VECTOR QUANTIZATION %%%%%

function centroid = vqlbg(cepstrum, M)

% FEATURE MATCHING

% STEP 1 - INITIALIZATION
centroid = medel(cepstrum);
centroid = centroid';
cepstrum = cepstrum';
epsilon = 0.01;
%M = 8; % The size of the codebook
m=1;
while (m<M)
% STEP 2 --- DIVISION
temp_cent = centroid;
j = 1;
for i=1:m
centroid:),j) = temp_cent:), i) * (1 + epsilon);
j = j + 1;
centroid:),j) = temp_cent:), i) * (1 - epsilon);
j = j + 1;
end
m = 2*m;
test_var = 0;
D_prim = 99999999; % Init D_prim to a sufficient large value.

while (test_var == 0)
% STEP 3 --- CLUSTERING
dist = disteu(cepstrum, centroid);
[magic, ind] = min(dist, [], 2);
% STEP 4 --- UPDATE


D = sum(sum(dist));
if ( ( (D_prim - D) / D) < epsilon)
test_var = 1;
else
D_prim = D;
end
end
end

% ---------- MARS MARS MARS MARS MARS ----------





%%%%% FINDING EUCILIDIAN DISTANCE %%%%%
function d = disteu(x, y)
[M, N] = size(x);
[M2, P] = size(y);

if (M ~= M2)
error('Matrix dimensions do not match.')
end

d = zeros(N, P)
if (N < P)
copies = zeros(1,P);

for n= 1:N
d(n,:) = sum((x:), n+copies) - y) .^2, 1);
end
else
copies = zeros(1,N);

for p = 1:p
d:),p) = sum((x - y:), p+copies)) .^2, 1)';
end
end
d = d.^0.5;

% ---------- MARS MARS MARS MARS MARS ----------







%%%%% LEARNING AND MFCC %%%%%
function cep = learn(file)
[filedata, fs] = wavread('C:\MATLAB7\work\user.wav');
truncated = extract(filedata);
cep = mfcc(truncated);

% ---------- MARS MARS MARS MARS MARS ----------






%%%%% EXTRACTING FEATURES %%%%%
function sampledata = extract(xin, length)
length=16;
mean = 0;
for i = 1:1000
mean = mean + (abs(xin(i)) / 100);
end
threshold = mean * 2 ;
for first_index = 1:size(xin)
if (abs(xin(first_index)) > threshold)
break;
end
end
for end_index = 1:size(xin)
temp = size(xin) - end_index;
if (abs(xin(temp(1))) > threshold)
break;
end
end
sampledata = xin(first_index:(size(xin) - end_index));

% ---------- MARS MARS MARS MARS MARS ----------

%%%%% MEDEL %%%%%
function m = medel(v);
[nr_of_rows, nr_of_columns] = size(v);
for i=1:nr_of_columns
m(i) = sum(v(1:nr_of_rows, i)) / nr_of_rows;
end

% ---------- MARS MARS MARS MARS MARS ----------


%%%%% DETERMINING MEL-SPACED FREQUENCY BANK %%%%%
function m = melfb(p,n, fs)

p=20; % number of filters in filterbank
n=256; % length of fft
fs=22050;
f0 = 700 / fs;
fn2 = floor(n/2);
lr = log(1 + 0.5/f0) / (p+1);
% convert to fft bin numbers with 0 for DC term
bl = n * (f0 * (exp([0 1 p p+1] * lr) - 1));
b1 = floor(bl(1)) + 1;
b2 = ceil(bl(2));
b3 = floor(bl(3));
b4 = min(fn2, ceil(bl(4))) - 1;
pf = log(1 + (b1:b4)/n/f0) / lr;
fp = floor(pf);
pm = pf - fp;
r = [fp(b2:b4) 1+fp(1:b3)];
c = [b2:b4 1:b3] + 1;
v = 2 * [1-pm(b2:b4) pm(1:b3)];
m = sparse(r, c, v, p, 1+fn2);

% ---------- MARS MARS MARS MARS MARS ----------




















%%%%% MEL-CEPSTRUM %%%%%
function cepstrum = mfcc(x)

% FRAME BLOCKING
j=1;
i=1;
[s1, s2] = size(x);
%x(1: 256)
while ( (j+256) <= s1)
for( k=1 : 256)
x_new(i,k) = x(k+j-1);
end
i = i+1;
j = j + 256;
end

% WINDOWING

j=1;
i=1;
[s1, s2] = size(x);
w = hamming(256);

while ( (j+256) <= s1)
for( k=1 : 256)
x_new(i,k)=x_new(i,k) * w(k);
end
i = i + 1;
j = j + 256;
end

% FAST FOURIER TRANSFORM

j=1;
i=1;
while ( (j+256) <= s1)
x_new_freq(i,1:256) = fft(x_new(i,1:256));
i = i + 1;
j = j + 256;
end

% MEL FREQUENCY WRAPPING

nr_of_filters = 20;
m = melfb(nr_of_filters,256, 11000);
n2 =1+floor(256/2);
i=1;
j=1;
while ( (j+256) <= s1)
for (k=1:nr_of_filters)
z_prim = (m * (abs(x_new_freq(i,1:n2)).^2)'); %'

z(i,k) = z_prim(k);
end
j = j + 256;
i = i + 1;
end

i=1;
j=1;
while ( (j+256) <= s1)
cepstrum_prim = dct(z(i,1:nr_of_filters));
for (k=1:nr_of_filters)
cepstrum(i,k) = cepstrum_prim(k);
end
j = j + 256;
i = i + 1;
end
resolution = i-1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


if u have another code for matlab then also send it to me.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top