Getting an error of "Not enough input arguments."

I'm defining a function which returns a vector used for design of fir filters using hamming window. I am not able to see where I'm going wrong and would appreciate if someone could help me out
Function:
function a = firfilt2(wp,ws)
n=ceil(8/(ws-wp));
if(rem(n,2)==0)
n=n+1;
end
y=hamming_alg(n);
a=fir1(n-1,wp,y);
end
function hm_wind = hamming_alg(n)
hm_wind=zeros(1,n);
for i=1:n
hm_wind(i) = 0.54 - 0.46*cos((2*pi*i)/(n-1));
end
end
Testcase:
rp=0.25;
rs=50;
wp=0.3;
ws=0.45;
filt=firfilt2(wp,ws);
freqz(filt,1);
Error Message :
>>firfilt2
Error using firfilt2 (line 2)
Not enough input arguments.
I've also tried another program which does the same thing and also determines the window automatically by using Stop Band Gain. That seemed to show the same error message. I've tried most of the tips online and also tried to debug the code line by line.

Answers (2)

Your sample line invokes your function firfilt2 with no arguments. Not sure why you did that...otherwise, looks like the sample test should run from the command line.

5 Comments

No. I get that error when I run the function. I'm physically not entering the sample line firfilt2 in the command line.
Well that makes no sense...line function as shown is not the first line in the function needing an input; hence the error should show up as line 2 for the missing inputs. One is left with the conclusion what you've posted (and think you're running) isn't really what you're looking at.
Try
which firfilt2
and ensure it's actually pointing to the copy you have shown here--or that the script that you're executing is actually the one you intend. Wherever that particular invocation is coming from there are fewer than two arguments.
ADDENDUM Or, alternatively, if you have an earlier version that were to have needed a third argument (like the length, maybe?) and you changed your mind, then the case above of having two arguments as the present version requires would give the same error. Either way, it's pretty clear something like that has to be the culprit here; I copied your code and as expected it runs just fine.
While doing the above, btw, I noted you don't need a loop in the internal function
function hm_wind = hamming_alg(n)
hm_wind=zeros(1,n);
for i=1:n
hm_wind(i) = 0.54 - 0.46*cos((2*pi*i)/(n-1));
end
end
could be written as simply
function hm_wind = hamming_alg(n)
hm_wind= 0.54-0.46*cos((2*pi*[1:n])/(n-1));
end
in which case it seems hardly worth making it a function. Anyway, use the "mat" part of Matlab; the vectorized operators where appropriate instead of looping.
I'm really sorry. Like you mentioned it's line 2 which is giving the error. In the original code there was a space which meant there was nothing written at line 2. I will try the suggestions and debug the code. Thanks a lot.
Line 2 was the first line on which you attempted to use one of the input arguments that you did not supply when you invoked the code.

Sign in to comment.

Jan
Jan on 6 Jun 2015
Edited: Jan on 6 Jun 2015
Use
dbstop if error
to find out, which line causes the troubles. Which line is "line 3"?
Be sure, that the file has been saved before calling and do not use the RUN-menu in the editor, because it does not define the inputs.

1 Comment

I'm really sorry. Like you mentioned it's line 2 which is giving the error. In the original code there was a space which meant there was nothing written at line 2. I will try the suggestions and debug the code and get back to you. Thanks a lot.

Sign in to comment.

Asked:

on 5 Jun 2015

Commented:

on 8 Jun 2015

Community Treasure Hunt

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

Start Hunting!