MATLAB Answers

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

6 views (last 30 days)
Pooja Prajapati
Pooja Prajapati on 26 Jan 2017
Commented: Walter Roberson on 28 Jan 2017
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

  0 Comments

Sign in to comment.

Accepted Answer

Niels
Niels on 27 Jan 2017
Edited: Niels on 27 Jan 2017
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 Comments

Pooja Prajapati
Pooja Prajapati on 27 Jan 2017
tysm niels it works.
I got the values in matrix form for all 5 variables,
Tysm again,
But now i have 1 more dought,
that i have to put that values in that files code too? or just in command window?
actually i tried after clicking on run button of that mfcc file & then after going on command window i first show that error of input argumnets but though i directly put that values in command window & it works. so nw need to put it in file code too?
is that error comes every time?
Also, one more dought that now how can i apply it on audio file for feature extraction using mfcc?
As i actually do this mfccc for feature extraction of audio file for my project.
so please kindly help me in this too.
also find the .mat file of the output code from following attachments,
Niels
Niels on 27 Jan 2017
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.

Sign in to comment.

More Answers (2)

Guillaume
Guillaume on 26 Jan 2017
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 Comments

Show 4 older comments
Pooja Prajapati
Pooja Prajapati on 27 Jan 2017
ok walter tysm for your help,
I tried it,
but don't know what is w1?
I have no idea about w1,
i changes the value for fs & frate for w1 i just put as you told 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
Guillaume
Guillaume on 27 Jan 2017
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 on 28 Jan 2017
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.

Sign in to comment.


Pooja Prajapati
Pooja Prajapati on 27 Jan 2017
Edited: Walter Roberson on 27 Jan 2017
@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 Comments

Show 1 older comment
Pooja Prajapati
Pooja Prajapati on 27 Jan 2017
ok niels u can get my full code file from attchments,
N ya also tried walter's code but i also produce error,
i vl send you the screenshot in nxt.
Niels
Niels on 27 Jan 2017
Which errormessage did you get when you run walters example? Probably another one.
Pooja Prajapati
Pooja Prajapati on 27 Jan 2017
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by