您好,欢迎访问三七文档
当前位置:首页 > 机械/制造/汽车 > 机械/模具设计 > 自适应的MATLAB的一种仿真
clearallcloseall%channelsystemordersysorder=5;%NumberofsystempointsN=2000;inp=randn(N,1);n=randn(N,1);[b,a]=butter(2,0.25);Gz=tf(b,a,-1);%ThisfunctionissubmittedtomakeinverseZ-transform(Matlabcentralfileexchange)%Thefirstsysorderweightvalue%h=ldiv(b,a,sysorder)';%ifyouuseldivthiswillgiveh:filterweightstobeh=[0.0976;0.2873;0.3360;0.2210;0.0964;];y=lsim(Gz,inp);%addsomenoisen=n*std(y)/(10*std(n));d=y+n;totallength=size(d,1);%Take60pointsfortrainingN=60;%beginofalgorithmw=zeros(sysorder,1);forn=sysorder:Nu=inp(n:-1:n-sysorder+1);y(n)=w'*u;e(n)=d(n)-y(n);%Startwithbigmuforspeedingtheconvergencethenslowdowntoreachthecorrectweightsifn20mu=0.32;elsemu=0.15;endw=w+mu*u*e(n);end%checkofresultsforn=N+1:totallengthu=inp(n:-1:n-sysorder+1);y(n)=w'*u;e(n)=d(n)-y(n);endholdonplot(d)plot(y,'r');title('Systemoutput');xlabel('Samples')ylabel('Trueandestimatedoutput')figuresemilogy((abs(e)));title('Errorcurve');xlabel('Samples')ylabel('Errorvalue')figureplot(h,'k+')holdonplot(w,'r*')legend('Actualweights','Estimatedweights')title('Comparisonoftheactualweightsandtheestimatedweights');axis([060.050.35])%RLS算法randn('seed',0);rand('seed',0);NoOfData=8000;%SetnoofdatapointsusedfortrainingOrder=32;%SettheadaptivefilterorderLambda=0.98;%SettheforgettingfactorDelta=0.001;%RinitializedtoDelta*Ix=randn(NoOfData,1);%Inputassumedtobewhiteh=rand(Order,1);%Systempickedrandomlyd=filter(h,1,x);%Generateoutput(desiredsignal)%InitializeRLSP=Delta*eye(Order,Order);w=zeros(Order,1);%RLSAdaptationforn=Order:NoOfData;u=x(n:-1:n-Order+1);pi_=u'*P;k=Lambda+pi_*u;K=pi_'/k;e(n)=d(n)-w'*u;w=w+K*e(n);PPrime=K*pi_;P=(P-PPrime)/Lambda;w_err(n)=norm(h-w);end;%Plotresultsfigure;plot(20*log10(abs(e)));title('LearningCurve');xlabel('IterationNumber');ylabel('OutputEstimationErrorindB');figure;semilogy(w_err);title('WeightEstimationError');xlabel('IterationNumber');ylabel('WeightErrorindB');
本文标题:自适应的MATLAB的一种仿真
链接地址:https://www.777doc.com/doc-2052382 .html