Matrix dimensions must agree....?
2 views (last 30 days)
Show older comments
Hi, I need to do a gui of voice recognition.
clear 'color';
clc;
y1=wavrecord(88200,44100,1);
s1=analoginput('winsound');
canals= addchannel(s1,1);
s1.SampleRate=44100;
s1.TriggerType=('Immediate');
start(s1);
[g,u]=getdata(s1);
stop(s1);
wavwrite(g,44100,'color');
q=wavread('rojo');
q1=wavread('azul');
q2=wavread('verde');
q3=wavread('azulc');
q4=wavread('magenta');
q5=wavread('amarillo');
q6=wavread('blanco');
q7=wavread('negro');
q8=wavread('color');
maximoq=max(abs(q));
l=length(q);
sonidoq=zeros(1,l);
for iq=1:l
sonidoq(iq)=q(iq)/maximoq;
end
maximoq1=max(abs(q1));
l1=length(q1);
sonidoq1=zeros(1,l1);
for iq1=1:l1
sonidoq(iq1)=q1(iq1)/maximoq1;
end
maximoq2=max(abs(q2));
l2=length(q2);
sonidoq2=zeros(1,l2);
for iq2=1:l2
sonidoq2(iq2)=q2(iq2)/maximoq2;
end
maximoq3=max(abs(q3));
l3=length(q3);
sonidoq3=zeros(1,l3);
for iq3=1:l3
sonidoq(iq3)=q3(iq3)/maximoq3;
end
maximoq4=max(abs(q4));
l4=length(q4);
sonidoq4=zeros(1,l4);
for iq4=1:l4
sonidoq4(iq4)=q4(iq4)/maximoq4;
end
maximoq5=max(abs(q5));
l5=length(q5);
sonidoq5=zeros(1,l5);
for iq5=1:l5
sonidoq5(iq5)=q5(iq5)/maximoq5;
end
maximoq6=max(abs(q6));
l6=length(q6);
sonidoq6=zeros(1,l6);
for iq6=1:l6
sonidoq6(iq6)=q6(iq6)/maximoq6;
end
maximoq7=max(abs(q7));
l7=length(q7);
sonidoq7=zeros(1,l7);
for iq7=1:l7
sonidoq7(iq7)=q7(iq7)/maximoq7;
end
maximoq8=max(abs(q8));
l8=length(q8);
sonidoq8=zeros(1,l8);
for iq8=1:l8
sonidoq8(iq8)=q8(iq8)/maximoq8;
end
transq=abs(fft(sonidoq));
transq1=abs(fft(sonidoq1));
transq2=abs(fft(sonidoq2));
transq3=abs(fft(sonidoq3));
transq4=abs(fft(sonidoq4));
transq5=abs(fft(sonidoq5));
transq6=abs(fft(sonidoq6));
transq7=abs(fft(sonidoq7));
transq8=abs(fft(sonidoq8));
error(1)= mean(abs(transq-transq8));
error(2)= mean(abs(transq1-transq8));
error(3)= mean(abs(transq2-transq8));
error(4)= mean(abs(transq3-transq8));
error(5)= mean(abs(transq4-transq8));
error(6)= mean(abs(transq5-transq8));
error(7)= mean(abs(transq6-transq8));
error(8)= mean(abs(transq7-transq8));
minerror=min(error);
if(minerror==error(1))
axes(handles.axes1);
plot(tiempoa,aceleracion,'r');
axes(handles.axes2);
plot(tiempov,vel,'r');
axes(handles.axes3); | |monospaced||
plot(tiempod,dist,'r');
elseif(minerror==error(2))
axes(handles.axes1);
plot(tiempoa,aceleracion,'b');
axes(handles.axes2);
plot(tiempov,vel,'b');
axes(handles.axes3);
plot(tiempod,dist,'b');
elseif(minerror==error(3))
axes(handles.axes1);
plot(tiempoa,aceleracion,'g');
axes(handles.axes2);
plot(tiempov,vel,'g');
axes(handles.axes3);
plot(tiempod,dist,'g');
elseif(minerror==error(4))
axes(handles.axes1);
plot(tiempoa,aceleracion,'c');
axes(handles.axes2);
plot(tiempov,vel,'c');
axes(handles.axes3);
plot(tiempod,dist,'c');
elseif(minerror==error(5))
axes(handles.axes1);
plot(tiempoa,aceleracion,'m');
axes(handles.axes2);
plot(tiempov,vel,'m');
axes(handles.axes3);
plot(tiempod,dist,'m');
elseif(minerror==error(6))
axes(handles.axes1);
plot(tiempoa,aceleracion,'y');
axes(handles.axes2);
plot(tiempov,vel,'y');
axes(handles.axes3);
plot(tiempod,dist,'y');
elseif(minerror==error(7))
axes(handles.axes1);
plot(tiempoa,aceleracion,'w');
axes(handles.axes2);
plot(tiempov,vel,'w');
axes(handles.axes3);
plot(tiempod,dist,'w');
elseif(minerror==error(8))
axes(handles.axes1);
plot(tiempoa,aceleracion,'k');
axes(handles.axes2);
plot(tiempov,vel,'k');
axes(handles.axes3);
plot(tiempod,dist,'k');
end
The problem is:
Matrix dimensions must agree.
Error in formulas>pushbutton4_Callback (line 459)
error(1)= mean(abs(transq-transq8));
Many Thanks
2 Comments
Walter Roberson
on 6 Jan 2016
It looks to me as if the code is not intended for voice recognition, but is instead intended for speech recognition. Voice recognition is intended to recognize who is speaking. Speech recognition is intended to recognize what is spoken.
Stephen23
on 6 Jan 2016
Edited: Stephen23
on 6 Jan 2016
@Astrid Valle: You might like to consider changing your code to use cell arrays instead of numbered variables. For example this lets you read all of the wave files:
N = {'rojo','azul','verde','azulc','magenta','amarillo','blanco','negro','color'};
for k = numel(N):-1:1
Q{k} = wavread(N{k});
end
Writing code like this has many advantages, particularly because you only need to write/fix code on one line (not multiple lines), it allows code to be written that will automatically adjust to different number of files, it is more compact, easier to scan, etc.
Although beginners seem to love them using numbered variables, they are inevitably a bad idea, causing beginners to want to define/access them dynamically (which is very poor programming):
Accepted Answer
Walter Roberson
on 6 Jan 2016
Subtracting matrices is only possible if one of them is a scalar or the two have the same number of elements. You have been very careful to use different variables for the lengths, l1, l2, l3, and so on, so you are not assuming that your sounds all have the same number of samples, but you somehow expect you can do the subtractions anyhow. You have also not controlled the number of samples in what you input from the microphone.
You are going to need to get all of your samples (including from the microphone) to the exact same number of samples so that the matrices are the same length to be subtracted, or you going to need to find a way to correlate matrices of different sizes.
Note: you set a particular sampling frequency from the microphone, 44100, but you pay no attention to the sampling frequency of the sound samples, which could even be different for each file.
0 Comments
More Answers (0)
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!