MATLAB: Too many inputs error with function?? *ASSIGNMENT DUE*

fourier transformfunctionhomework

Can anyone tell me why i get the error too many inputs for this function?
function [ W,E_W ] = Assessment_6( tau,beta,tol )
%Assessment_6
% computes essential bandwidth W for square pulse.
% INPUTS : tau = pulse width
% beta = fraction of signal energy desired in W
% tol = tolerance of relative energy error
% OUTPUTS : W = essential bandwidth [rad/s]
% E_W = Energy contained in bandwidth W
W = 0;
step = 2*pi/tau; %intial guess and step values.
X_squared = inline('(tau*Assessment_6 (omega*tau/2)).^2','omega','tau');
E = beta*tau; %Desired energy in W.
relerr = (E-0)/E; %Intial relative error is 100 percent.
while(abs(relerr) > tol),
if (relerr > 0), %W too small
W = W + step; %Increase W by step
else if (relerr < 0), %W too large
step = step/2;
W = W-step; %Decrease step size and then W.
end
E_W = 1/(2*pi)*quad(X_squared, -W,W, [], [], tau);
relerr = (E - E_W)/E;
end
end
end

Best Answer

  • It’s not obvious to me what you’re doing. I can’t tell where the ‘too many inputs’ error arises (you don’t tell us what line throws the error), but I have my suspicions.
    This is one problem:
    X_squared = inline('(tau*Assessment_6(omega*tau/2)).^2','omega','tau');
    First, do not call a function from within the same function! This creates recursion problems.
    Second, use anonymous functions instead of inline. Anonymous functions pick up previously-defined variables from your workspace, while inline functions do not. And inline functions are not going to be around for much longer, anyway.
    Convert it to this form (but remove the ‘Assessment_6’ call):
    X_squared = @(omega,tau) (tau*Assessment_6(omega*tau/2)).^2;
    Third, I have no idea what you’re integrating with respect to. If ‘tau’, then experiment with:
    E_W = 1/(2*pi)*quad(@(tau) X_squared(omega,tau), -W,W);
    Finally, you need to rewrite your function, perhaps using nested functions to eliminate the recursion problem.