📄 lmsalgo.m
字号:
function[]=lmsalgo(M,d,angle1,inter)
T= 1e-3;
t=(1:100)*(T/100);
it=1:100;
s=sin(pi*t/T);
i=randn(1,100);
thetao=angle1*pi/180; % calculation of source direction %
thetai=inter*pi/180; % calculation of interference direction %
ao=[];ai=[];
ii=1:M;
ao=exp(1j*(ii-1)*2*pi*d*sin(thetao)).'; % calculation of source steering vector %
ai=exp(1j*(ii-1)*2*pi*d*sin(thetai)).'; % calculation of interference steering vector %
w=zeros(M,1);
wi=zeros(M,max(it));
mu=0.02; % defining the convergence factor %
for n=1:length(s) % calculating the error signal %
x=s(n)*ao+ i(n)*ai;
y=w'*x;
e=s(n)-y;
esave(n)=abs(e);
w=w+mu*conj(e)*x; % calculating the weights as per the error %
wi(:,n)=w;
end
w=w./w(1);
% displaying the weights for the optimal solution %
disp(' ');
disp([' The weights for the M = ',num2str(M)])
disp(' ')
for m= 1:length(w)
disp([' w',num2str(m),' = ',num2str(w(m),2)])
end
disp(' ')
% calculating the array factor which shows directional preference %
theta = -pi/2:.001:pi/2;
AF=0;
for ii=1:M
AF=AF+w(ii)'.*exp(1j*(ii-1)*2*pi*d*sin(theta));
end
AF=abs(AF)/max(abs(AF));
figure(3);
polar(theta,AF);
% displaying the necessary result in a graphical form %
figure(4);
plot(theta*180/pi,AF);
xlabel('Angle(deg)');
ylabel('Array Factor');
title('Beampattern vs Angle');
axis([-90 90 0 1]);
grid on;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -