can anyone help to solve this matlab error of not enough input arguments?

2 次查看(过去 30 天)
function [ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(input,fs,frate)
global mfccDCTMatrix mfccFilterWeights
[r,c]=size(input); % error occur in this line
if(r > c)
input=input';
end

采纳的回答

Niels
Niels 2017-1-27
编辑:Niels 2017-1-27
so...
you changed the order of the input arguments again?... you have to decide yourself wether it shall be
1. case
function [ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(w1,fs,frate)
or 2. case
function [ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(fs,w1,frate)
to call your function type in your command window
1. case
[ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(w1,fs,frate)
ofc you have the set the variables w1, fs and frate to some values... thats what walter did: also in the command window
w1=rand(50, 864);
fs=9600, 57.2);
frate=57.2;
% then call your function like shown above or
2. case
[ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(fs,w1,frate)
in your picture you put a single number as input for w1, i thought you might expect w1 to be a matrix (since you check its size etc), walter generated a random matrix with size 50x864
  3 个评论
Niels
Niels 2017-1-27
编辑:Niels 2017-1-27
The values in my/ walters answer are just random numbers.
You shouldnt use these results getting from our example for anything. You need to Fill the variables with your own data. You might have some. Otherwise why would you try to use this function.
To answer your questions: i propose you do as guillaume said. Learn the basics. That will improve your understanding of how functions work. And i am sry but i cant help you any further because i have no clue of working with audio files.

请先登录,再进行评论。

更多回答(2 个)

Guillaume
Guillaume 2017-1-26
Clearly, you've called the function without giving it any input. I.e, you should call the function with:
mfcc(somevariable, someothervariable, somethingelse)
Note that calling the first input input is a very bad idea as it overrides the matlab function with the same name. Give that first input a different name.
Also, I would strongly reconsider having global variables. Whatever time saving it may give you now, you'll likely spend twice as much debugging weird issues later on.
  7 个评论
Guillaume
Guillaume 2017-1-27
编辑:Guillaume 2017-1-27
As Walter and I told you, you need to call the function with the required number of inputs. The same way that if you call
y = sin()
matlab returns the error not enough input arguments since you need at least one input for sin.
What that input should be, only you knows, the same way only you knows what angle you want the sin of.
If it's a function you wrote, I don't understand how you don't know what the inputs should be. They're whatever you thought was necessary. If it's not a function you wrote then refer to its documentation or ask its author. We can't guess that for you. The only thing that is clear from your code sample is that this badly named input should be a 2D matrix.
It looks to me that you're lacking some very basic understanding of how matlab works. I would recommend you go through the getting started tutorial and learn about functions
Walter Roberson
Walter Roberson 2017-1-28
w1 should be the data to be processed.
fs should be the sampling frequency the data was processed for.
frate should be the number of windows that the data will be broken up into. If you do not provide a value then 100 will be used by default.

请先登录,再进行评论。


Pooja Prajapati
Pooja Prajapati 2017-1-27
编辑:Walter Roberson 2017-1-27
@niels ya i knew that,
u r ri8 bt it's not running so i tried it with changing the order of inputarguments.
but u can see my full code,
nw please help in out of this error,
my code is,
function [ceps,freqresp,fb,fbrecon,freqrecon]=mfcc(w1,fs,frate)
global mfccDCTMatrix mfccFilterWeights
[r,c]=size(w1);
if(r > c)
w1=w1';
end
lowestFrequency=133.3333;
linearFilters=13;
linearSpacing=66.66666666;
logFilters=27;
logSpacing=1.0711703;
fftSize=256;
cepstralcoefficients=13;
windowSize=256;
if(nargin < 2)
fs=11025;
end
if(nargin < 3)
frate=100;
end
totalFilters=linearFilters+logFilters;
freqs=lowestFrequency+(0:linearFilters-1)*linearSpacing;
freqs(linearFilters+1:totalFilters+2)=freqs(linearFilters)*...
logSpacing .^ (1:logFilters+2);
lower=freqs(1:totalFilters);
center=freqs(2:totalFilters+1);
upper=freqs(3:totalFilters+2);
mfccFilterWeights=zeros(totalFilters,fftSize);
triangleHeight=2 ./ (upper-lower);
fftFreqs=(0:fftSize-1)/fftSize*fs;
for i=1:totalFilters
mfccFilterWeights(i,:)=(fftFreqs>lower(i) & ...
fftFreqs<= center(i)).* triangleHeight(i).*...
(fftFreqs-lower(i))/(center(i)-lower(i))+...
(fftFreqs>center(i) & fftFreqs<upper(i)).* ...
triangleHeight(i).*(upper(i)-fftFreqs)/(upper(i)-center(i));
end
hamWindow=0.54-0.46*cos(2*pi*(0:windowSize-1)/windowSize);
if 0
windowSize=fs/frate;
a=0.54;
b=-0.46;
wr=sqrt(windowStep/windowSize);
phi=pi/windowSize;
hamWindow=2*wr/sqrt(4*a*a+2*b*b)*...
(a+b*cos(2*pi*(0:windowSize-1)/windowSize+phi));
end
mfccDCTMatrix=1/sqrt(totalFilters/2)*...
cos((0:(cepstralcoefficients-1))'* ...
(2*(0:(totalFilters-1))+1)*pi/2/totalFilters);
mfccDCTMatrix(1,:)=mfccDCTMatrix(1,:)*sqrt(2)/2;
if 1
preEmphasized=filter([1-0.97],1,w1);
else
preEmphasized=w1;
end
windowStep=fs/frate;
cols=fix((length(w1)-windowSize)/windowStep);
if(nargout>4)
fr=(0:(fftSize/2-1))'/(fftSize/2)*fs/2;
j=1;
for i=1:(fftSize/2)
if fr(i) > center(j+1)
j=j+1;
end
if j > totalFilters-1
j=totalFilters-1;
end
fr(i)=min(totalFilters-0.0001, ...
max(i,j+(fr(i)-center(j))/(center(j+1)-center(j))));
end
fri=fix(fr);
frac=fr-fri;
freqrecon=zeros(fftSize/2,cols);
end
for i=0:cols-1
first=i*windowStep+1;
last=first+windowSize-1;
fftData=zeros(1,fftSize);
first=fix(first);
last=fix(last);
fftData(1:windowSize)=preEmphasized(first:last).*hamWindow;
fftMag=abs(fft(fftData));
earMag=log10(mfccFilterWeights*fftMag');
ceps(:,i+1)=mfccDCTMatrix*earMag;
if(nargout > 1)
freqresp(:,i+1)=fftMag(1:fftSize/2)';
end
if(nargout > 2)
fb(:,i+1)=earMag;
end
if(nargout > 3)
fbrecon(:,i+1)=mfccDCTMatrix(1:cepstralcoefficients,:)'* ...
ceps(:,i+1);
end
if(nargout > 4)
f10=10.^fbrecon(:,i+1);
freqrecon(:,i+1)=fs/fftSize* ...
(f10(fri).*(1-frac)+f10(fri+1).*frac);
end
end
if 1 && (nargout > 3)
fbrecon=mfccDCTMatrix(1:cepstralcoefficients,:)'*ceps;
end
end
  4 个评论
Niels
Niels 2017-1-27
编辑:Niels 2017-1-27
Which errormessage did you get when you run walters example? Probably another one.
Pooja Prajapati
Pooja Prajapati 2017-1-27
ok wait niels wait,
walter's code works nw,
But now what to do,
I have no idea about w1,
i changes the value for fs & frate for w1 i just put walter's random no 9600 for w1 & it works.
so can you please tell me about w1.
And now what command i have to give for run it,
fond the screenshot of it from attchmnets

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by