
function[wa1,v]=aapowerspectraav1(a1,a2,a3,mu,M,N,avn,vr)
%aapowerspectraav1(a1,a2,a3,mu,M,N,avn,vrn);
wa=zeros(1,M);
dn=zeros(1,N);x=zeros(1,N);
for k=1:avn
   for n=4:N
       v(n)=vr*(rand-.5);
      dn(n)=-a1*dn(n-1)-a2*dn(n-2)-a3*dn(n-3)+v(n);
      x(n)=dn(n-1);
   end;
   [w]=aalms(x,dn,mu,M);
   wa=wa+w;
end;
wa1=wa/avn;
%this function gives averaged w's to be used for finding
%the approximate spectrum of the output of an AR filter
%up to the third order;M=number of LMS coefficients;
%N=length of desired signal and input signal to LMS filter;
%avn=number of times w's are averaged;the function is easily
%modified for AR filter with more coefficients;vr=controls the 
%variance of the white noise, multiplies the quantity (rand-.5);
%the function up to the first end produces the output from
%the AR filter with coefficients a1,a2 and a3; 
