Andrew T
Andrew T

Reputation: 803

Receiving MATLAB Error Regarding Function Arguments

When running my MATLAB script below, I keep getting an error that states:

  1. Error using spa (Line 147)  
    The value of the window size must be an integer greater than 2.

  2. Error in "projectName"   G = spa(xFunction2, x)

I've tried putting in multiple types of arguments into "spa" (data, windowsize, frequency) but it still yields the same error(s). Help?

n = 1:1024; 

%Signal Function 
xFunction = sqrt(10)*exp(j*2*pi*0.10*n)+ sqrt(20)*exp(j*2*pi*0.20*n) + sqrt(625); 

%Complex Noise Function
zFunction = 0.707*randn(size(n)) + j*0.707*randn(size(n));

%Computing the value of x(n) + sqrt(625)*z
xFunction2 = xFunction + sqrt(625)*zFunction;  

G = spa(xFunction2,51);
figure(1); 
plot(w, 10*log10(G)); 

Upvotes: 0

Views: 60

Answers (1)

Seba Arriagada
Seba Arriagada

Reputation: 380

Acording the documentation of spa the first argument is iddata type. In addition, the time serie has to be a column vector. So, to make it works change G = spa(xFunction2,51); for G = spa(xFunction2(:),51);. To do it the correct way, convert your time serie to iddata:

Ts = 0.1;          % what ever is your sampling time.
myiddata = iddata(xFunction2(:),[],Ts);

G = spa(myiddata,51);

In addition, you should use spectrum(G) or bode(G)to plot the result.

Upvotes: 1

Related Questions